鱼C论坛

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

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

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

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

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

x
运行代码:
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()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

把“运行代码”移出代码块
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-6 17:47:31 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-23 09:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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