python画国旗,急急急急急急

 

按照题意要求,代码这样写:

from turtle import *
setup(600, 400, 0, 0)#填空
hideturtle()#填空
tracer(0)#填空
bgcolor("red")#填空
#填空
def star(n):
    for i in range(5):
        forward(n)
        right(144)
#以下除调用star函数外全部为填空。

#主星
color('yellow')
fillcolor("yellow")
begin_fill()
up()
goto(-280, 100)
down()
star(90)
end_fill()
#第1颗副星
begin_fill()
up()
goto(-100, 180)
setheading(305)
down()
star(30)
end_fill()
#第2颗副星
begin_fill()
up()
goto(-50, 110)
setheading(30)
down()
star(30)
end_fill()
#第3颗副星
begin_fill()
up()
goto(-40, 50)
setheading(5)
down()
star(30)
end_fill()
#第4颗副星
begin_fill()
up()
goto(-100, 10)
setheading(300)
down()
star(30)
end_fill()
done()

如对你有帮助,请点击我回答右上角的【采纳】按钮,采纳一下。

'''
	绘制五星红旗(Five-Starred Red Flag)
	@Author: Notus(hehe_xiao@qq.com)
	@Create: 2019-02-18
	@Update: 2019-02-19
	@Version: 1.0
	
	国旗数据分析:(参照下方参考图片)
	1. 最小单元格 A 的大小设为(长*宽,下同):10*10
	2. 左上角1/4矩形B被分成:15*10个A, 尺寸为 150 * 100
	3. 国旗矩形C大小为:300 * 200(为3:2的比例)
	4. 若向下为正,向右为正。大五角星相对国旗左上角(0,0)坐标为(x, y): (50, 50)
	5. 4个小五角星从上至下分别为:(100, 20), (120, 40), (120, 70), (100, 90)
	6. 五角星每个角36度
	

	国旗数据参考图片(国旗黑线图):https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike150%2C5%2C5%2C150%2C50/sign=dc24ea3a11d5ad6ebef46cb8e0a252be/78310a55b319ebc4b97aa7678826cffc1f1716c9.jpg
	
'''

import turtle
from math import *

# 绘制五角星, 默认为正五角星(一个顶点朝正北方)
# 五角星每个顶角的角度为 180/5 = 36度 或 pi/5
# (x, y): 五角星中心点坐标
# size: 中心到顶点的长度, 即外接圆的半径
# angle 旋转角度, 正五角星正北顶点 turtle.left 方式旋转到被绘制五角星的角度
def draw5star(x=0, y=0, size=100, angle=0, fillcolor='yellow', pencolor='yellow'):
	turtle.speed(0)
	turtle.shape('blank')
	turtle.color(pencolor, fillcolor)
	turtle.penup()

	# 定位到中心点正北方顶点(angle为0时的正北方)
	turtle.goto(x, y)
	turtle.setheading(90)
	turtle.left(angle)
	turtle.forward(size)
	turtle.right(180-36/2)
	
	turtle.pendown()

	# 一条直线上的两个顶点的距离
	distance = 2 * size * cos(pi/10)
	
	# 开始绘制,对于 angle 为 0 的, 从正北方顶点开始
	turtle.begin_fill()
	for i in range(5):
		turtle.forward(distance)
		turtle.right(144)
	turtle.end_fill()

	
# 画矩形
# (x,y) 矩形左上角坐标
def drawrectangle(x=0, y=0, height=100, width=100, fillcolor='red', pencolor='black'):
	turtle.speed(0)
	turtle.shape('blank')
	turtle.color(pencolor, fillcolor)
	turtle.penup()
	turtle.goto(x, y)
	turtle.setheading(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()


# 画辅助线,方便判断
# (x,y) 国旗中心点坐标
# mag 国旗放大倍数
def drawsubline(x=0, y=0, mag=1):
	# 国旗尺寸
	width = 300 * mag
	height = 200 * mag
	
	# 画中心十字
	turtle.speed(0)
	turtle.shape('blank')
	turtle.pencolor('black')
	turtle.penup()
	turtle.goto(x+width/2, y)
	turtle.setheading(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)
		

#绘制五星红旗
#(x, y) 红旗中心点坐标, 默认为(0,0),即标准模式turtle绘图的中心起点。
# mag: 放大倍数, maganification
def drawflag(x=0, y=0, mag=1):
	# 国旗尺寸
	width = 300 * mag
	height = 200 * mag

	# 计算国旗矩形左上角坐标
	r_x = x - width/2	
	r_y = y + height/2	
	# 画国旗矩形	
	drawrectangle(x=r_x, y=r_y, height=height, width=width)

	# 画最大的五角星
	draw5star(x=r_x+50*mag, y=r_y-50*mag, size=30*mag)
	# draw5star(x=r_x+50*mag, y=r_y-50*mag, size=30*mag)
	
	# 从上至下画4颗小五角星, 中心:(100, 20), (120, 40), (120, 70), (100, 90)
	l_size = 10 * mag
	draw5star(x=r_x+100*mag, y=r_y-20*mag, size=l_size, angle=180-atan(5/3)/pi*180)
	draw5star(x=r_x+120*mag, y=r_y-40*mag, size=l_size, angle=180-atan(7/1)/pi*180)
	draw5star(x=r_x+120*mag, y=r_y-70*mag, size=l_size, angle=90-atan(2/7)/pi*180)
	draw5star(x=r_x+100*mag, y=r_y-90*mag, size=l_size, angle=90-atan(4/5)/pi*180)
	
	
if __name__ == '__main__':

	drawflag(mag=2.5)
	# drawsubline(mag=2.5)
	input()

 

import turtle


turtle.setup(600,400,0,0)
turtle.bgcolor("red")
turtle.fillcolor("yellow")
turtle.color('yellow')
turtle.speed(10)
#主星
turtle.begin_fill()
turtle.up()
turtle.goto(-280,100)
turtle.down()
for i in range (5):
    turtle.forward(150)
    turtle.right(144)
turtle.end_fill()

#第1颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-100,180)
turtle.setheading(305)
turtle.down()
for i in range (5):
    turtle.forward(50)
    turtle.left(144)

turtle.end_fill()


#第2颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-50,110)
turtle.setheading(30)
turtle.down()
for i in range (5):
    turtle.forward(50)
    turtle.right(144)

turtle.end_fill()

#第3颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-40,50)
turtle.setheading(5)
turtle.down()
for i in range (5):
    turtle.forward(50)
    turtle.right(144)

turtle.end_fill()

#第4颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-100,10)
turtle.setheading(300)
turtle.down()
for i in range (5):
    turtle.forward(50)
    turtle.left(144)

turtle.end_fill()

turtle.done()

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632