鱼C论坛

 找回密码
 立即注册
查看: 4813|回复: 2

[作品展示] python绘画共青团团旗

[复制链接]
发表于 2023-5-6 17:46:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. 运行代码:
  2. import turtle as t
  3. import math as m
  4. a=20 #长
  5. w=48 #宽
  6. h=32 #高
  7. def move_to(x,y): #移动画笔函数
  8.     t.pu()
  9.     t.goto(x,y)
  10.     t.pd()

  11. def draw_rectangle():#画矩形函数
  12.     move_to(-w/2*a,h/2*a)
  13.     t.color("red")
  14.     t.begin_fill()
  15.     for i in range(2):
  16.         t.fd(w*a)
  17.         t.right(90)
  18.         t.fd(h*a)
  19.         t.right(90)
  20.     t.end_fill()

  21. def draw_grid():
  22.     t.color("black")

  23.     for i in range(h//2+1):
  24.         move_to(-w/2*a,h/2*a-i*a)
  25.         t.fd(w/2*a)

  26.     t.seth(-90)
  27.     for i in range(w//2+1):
  28.         move_to(-w/2*a+i*a,h/2*a)
  29.         t.fd(h/2*a)

  30. def draw_fivestar():
  31.     t.color("yellow")
  32.     t.begin_fill()
  33.     t.seth(-72)
  34.     for i in range(5):
  35.         t.fd (2*4*a*m.cos(18*m.pi/180))
  36.         t.right (144)
  37.     t.end_fill()

  38. def draw_circle(c,r):
  39.     t.color("yellow")
  40.     t.begin_fill()
  41.     t.color(c)
  42.     t.seth(0)
  43.     t.circle(-r)
  44.     t.end_fill()

  45. def set_point(x,y,r):
  46.     move_to(x,y)
  47.     t.seth (90)
  48.     t.pu()
  49.     t.fd(r)
  50.     t.pd()

  51. def write_sth(x,y,sth,length=100,c="red",ps=16):
  52.     move_to(x,y)
  53.     t.color(c)
  54.     t.pensize(ps)
  55.     t.write ("{0:^3}".format(sth),font=("黑体",ps,"normal"))

  56. t.setup(w*a+100,h*a+100)#设置窗口大小
  57. draw_rectangle()#画矩形
  58. #draw_grid() #画方格矩阵(最后,此行代码要注释掉!)

  59. set_point(-w/4*a,h/4*a,5.33*a) #设置大圆起笔位置
  60. draw_circle("yellow",5.33*a)  #画大圆

  61. set_point(-w/4*a,h/4*a,4*a)
  62. draw_circle("red",4*a)

  63. set_point(-w/4*a,h/4*a,4*a)
  64. draw_fivestar()

  65. write_sth(-w*a/4,-h*a/2-40,"团旗飘飘,青春闪耀",ps=24)

  66. t.ht()
  67. t.done()
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-5-6 17:51:03 | 显示全部楼层

把“运行代码”移出代码块
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-6 17:47:31 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-29 02:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表