怎么用Python画加纳国旗# python6.6
import turtle
def test():
# 加纳共和国国旗呈长方形python画国旗的函数,长与宽之比为3∶2 。
# 自上而下由红、黄、绿三个平行相等python画国旗的函数的横长方形组成python画国旗的函数,黄色部分中间是一颗黑色五角星 。
flag_h = 300
flag_w = 450
star_h = flag_h/3
turtle.pensize(2)
turtle.speed(5)
turtle.hideturtle()
def draw_rectangle(color):
turtle.pencolor(color)
turtle.fillcolor(color)
turtle.pendown()
turtle.begin_fill()
turtle.forward(flag_w)
turtle.right(90)
turtle.forward(star_h)
turtle.right(90)
turtle.forward(flag_w)
turtle.right(90)
turtle.forward(star_h)
turtle.end_fill()
turtle.penup()
turtle.back(star_h)
turtle.right(90)
turtle.penup()
turtle.goto(-flag_w / 2, flag_h / 2)
draw_rectangle("red")
draw_rectangle("yellow")
draw_rectangle("green")
# 五角星
turtle.penup()
turtle.goto(0, star_h/2)
turtle.pencolor("black")
turtle.fillcolor("black")
turtle.right(90-18)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(star_h)
turtle.right(180-36)
turtle.end_fill()
turtle.done()
if __name__ == "__main__":
test()
急求!这是一个用python画国旗的程序,请求大神解释一下每一步是干嘛的import turtle//导入模块
import time
import os
defdraw_square(org_x, org_y, x, y)://定义红旗绘制函数
turtle.setpos(org_x, org_y)//定义画笔初始位置
turtle.color('red', 'red')//颜色
turtle.begin_fill()//开始绘制
turtle.fd(x)//绘制偏转方向和角度
turtle.lt(90)
turtle.fd(y)
turtle.lt(90)
turtle.fd(x)
turtle.lt(90)
turtle.fd(y)
turtle.end_fill()//绘制结束
def draw_star(center_x, center_y, radius)://定义星星绘制函数
print(center_x, center_y)//显示位置
turtle.pencolor('black')//画笔轨迹颜色
turtle.setpos(center_x, center_y)//中心点位置
pt1 = turtle.pos()//偏转角度计算
turtle.circle(-radius, 360 / 5)
pt2 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt3 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt4 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt5 = turtle.pos()
turtle.color('yellow', 'yellow')//星星颜色
turtle.begin_fill()//开是绘制
turtle.goto(pt3)
turtle.goto(pt1)
turtle.goto(pt4)
turtle.goto(pt2)
turtle.goto(pt5)
turtle.end_fill()//绘制结束
print(turtle.pos())
turtle.pu()//隐藏画笔轨迹
draw_square(-320, -260, 660, 440)//绘制红旗
star_part_x = -320//自定义星星大小等属性
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5//计算星星中心点位置
turtle.setpos(center_x, center_y)
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3)//绘制星星
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2)//同上
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
推荐阅读
- 斗鱼嘉熙直播录播,斗鱼嘉熙直播录播视频
- 如何客观的评价新媒体设计,如何客观的评价新媒体设计作品
- 管理者如何做好酒店营销,如何做好酒店的营销工作
- vb.net添加用户控件 vb程序设计中怎样添加控件
- 缺少.net文件是什么意思的简单介绍
- ppt怎么设置百叶窗,ppt如何设置百叶窗切换效果
- 像素动作冒险游戏,像素动作冒险游戏大全
- 查看版本号命令linux linux查版本号命令
- 新居网如何营销店铺,新居网如何营销店铺服务