刀刀致命 发表于 2023-5-6 17:46:54

python绘画共青团团旗


运行代码:
import turtle as t
import math as m
a=20 #长
w=48 #宽
h=32 #高
def move_to(x,y): #移动画笔函数
    t.pu()
    t.goto(x,y)
    t.pd()

def draw_rectangle():#画矩形函数
    move_to(-w/2*a,h/2*a)
    t.color("red")
    t.begin_fill()
    for i in range(2):
      t.fd(w*a)
      t.right(90)
      t.fd(h*a)
      t.right(90)
    t.end_fill()

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

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

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

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

def draw_circle(c,r):
    t.color("yellow")
    t.begin_fill()
    t.color(c)
    t.seth(0)
    t.circle(-r)
    t.end_fill()

def set_point(x,y,r):
    move_to(x,y)
    t.seth (90)
    t.pu()
    t.fd(r)
    t.pd()

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

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

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

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

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

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

t.ht()
t.done()

Threebody1 发表于 2023-5-6 17:51:03

刀刀致命 发表于 2023-5-6 17:47


把“运行代码”移出代码块

刀刀致命 发表于 2023-5-6 17:47:31

{:10_256:}
页: [1]
查看完整版本: python绘画共青团团旗