小伙伴关心的问题:python画国旗代码(Python画国旗小五角星),本文通过数据整理汇集了python画国旗代码(Python画国旗小五角星)相关信息,下面一起看看。

python画国旗代码(Python画国旗小五角星)

突发奇想,想要用python画一个中国国旗,但是要怎么画呢?谷歌!

hzeyuan/100-Python​github.com/hzeyuan/100-Python

1.中国国旗的标准画法

国旗知识--五星红旗标准制法 - 中华人民共和国国旗网​www.chinaflag.org.cn/GuoQiZhishi/201474133055181.html(一) 旗面为红色,长方形,其长与高为三与二之比,旗面左上方缀黄色五角星五颗。一星较大,其外接圆直径为旗高十分之三,居左;四星较小,其外接圆直径为旗高十分之一,环拱于大星之右。旗杆套为白色。

(二) 五星之位置与画法如下:

甲 、为便于确定五星之位置,先将旗面对分为四个相等的长方形,将左上方之长方形上下划为十等分,左右划为十五等分。

乙 、大五角星的中心点,在该长方形上五下五、左五右十之处。

其画法为:以此点为圆心,以三等分为半径作一圆。在此圆周上,定出五个等距离的点,其一点须位于圆之正上方。然后将此五点中各相隔的两点相联,使各成一直线。此五直线所构成之外轮廓线,即为所需之大五角星。五角星之一个角尖正向上方。

丙 、四颗小五角星的中心点,第一点在该长方形上二下八、左十右五之处,第二点在上四下六、左十二右三之处,第三点在上七下三、左十二右三之处,第四点在上九下一、左十右五之处。其画法为:以以上四点为圆心,各以一等分为半径,分别作四个圆。在每个圆上各定出五个等距离的点,其中均须各有一点位于大五角星中心点与以上四个圆心的各联结线上。然后用构成大五角星的同样方法,构成小五角星。此四颗小五角星均各有一个角尖正对大五角星的中心点.

太长啦,俺们看不懂....直接看图就好啦。

这样就直观多啦。

2.接下来就是画的过程啦

2.1 画一个正方形

def drawrectangle(x=0, y=0, height=100, width=100): turtle.color("red") # turtle.penup() turtle.goto(x, y) turtle.seth(0) turtle.pensize(2) turtle.pendown() turtle.begin_fill() turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.end_fill()

2.2 画五角星

从上至下画4颗小五角星, 中心:(100, 20), (120, 40), (120, 70), (100, 90)def draw5star(x, y, size=100, angle=0):

turtle.color("yellow")

turtle.penup()

turtle.goto(x, y)

turtle.seth(90) # 默方向为北方

turtle.left(angle)

turtle.forward(size)

turtle.right(180 - 36 / 2)

turtle.pendown()

distance = 2 * size * cos(pi / 10)

turtle.begin_fill()

for i in range(5):

turtle.forward(distance)

turtle.right(144)

turtle.end_fill()

2.3 画辅助线

# 画辅助线 def drawsubline(x=0, y=0, mag=1): # 国旗尺寸 width = 300 * mag height = 200 * mag # 画中心十字 turtle.pencolor(black) turtle.penup() turtle.goto(x + width / 2, y) turtle.seth(180) turtle.pensize(2) turtle.pendown() turtle.forward(width) turtle.penup() turtle.goto(x, y - height / 2) turtle.setheading(90) turtle.pendown() turtle.forward(height) # 画小方格的横线 for i in range(1, 10): # 横线 turtle.penup() turtle.goto(x, y + height / 2 - i * 10 * mag) turtle.setheading(180) turtle.pendown() turtle.forward(width / 2) # 画小方格的竖线 for i in range(1, 15): turtle.penup() turtle.goto(x - width / 2 + i * 10 * mag, y) turtle.setheading(90) turtle.pendown() turtle.forward(height / 2) # 计算国旗矩形左上角坐标 r_x = x - width / 2 r_y = y + height / 2 # 画大五角星外接圆,圆绘制起始点为圆最右侧切点 turtle.penup() turtle.goto(r_x + 80 * mag, r_y - 50 * mag) turtle.pendown() turtle.circle(30 * mag) # 画4个小五角星外接圆,从上至下 (110, 20), (130, 40), (130, 70), (110, 90) turtle.penup() turtle.goto(r_x + 110 * mag, r_y - 20 * mag) turtle.pendown() turtle.circle(10 * mag) turtle.penup() turtle.goto(r_x + 130 * mag, r_y - 40 * mag) turtle.pendown() turtle.circle(10 * mag) turtle.penup() turtle.goto(r_x + 130 * mag, r_y - 70 * mag) turtle.pendown() turtle.circle(10 * mag) turtle.penup() turtle.goto(r_x + 110 * mag, r_y - 90 * mag) turtle.pendown() turtle.circle(10 * mag) # 画4个小星到大星中心的连线 turtle.penup() turtle.goto(r_x + 100 * mag, r_y - 20 * mag) turtle.pendown() turtle.goto(r_x + 50 * mag, r_y - 50 * mag) turtle.penup() turtle.goto(r_x + 120 * mag, r_y - 40 * mag) turtle.pendown() turtle.goto(r_x + 50 * mag, r_y - 50 * mag) turtle.penup() turtle.goto(r_x + 120 * mag, r_y - 70 * mag) turtle.pendown() turtle.goto(r_x + 50 * mag, r_y - 50 * mag) turtle.penup() turtle.goto(r_x + 100 * mag, r_y - 90 * mag) turtle.pendown() turtle.goto(r_x + 50 * mag, r_y - 50 * mag)

3.效果图

参考:

每日一程-11.利用Python turtle库绘制国旗​www.cnblogs.com/leo1875/p/10398926.html

更多python画国旗代码(Python画国旗小五角星)相关信息请关注本站,本文仅仅做为展示!