"""
要求:
红色的矩形(长:438,宽:292),起始坐标(-200,200),画布大小600*600
每个五角星的边长、坐标和旋转角度分别为:
主五角星边长50,坐标:(-170, 145)
四个小五角星边长为20,起始坐标分别为:(-100, 180),(-85, 150),(-85, 120),
(-100, 100)
四个小星星旋转初始角度分别为:305°、30°、3°、300°
顺时针旋转,旋转角度144°
"""
"""
author:ml_YSY
time:2019/11/19
"""
import turtle as tu
import time
def HQDemo():
# 创建600*600的画布,设置距离本机窗边距离
tu.setup(600, 600, 50, 50)
# 设置画笔颜色与显示情况、移动速度
tu.begin_fill()
tu.up()
tu.fillcolor("red") # 填充颜色
tu.color("red")
tu.hideturtle() # 隐藏画笔
tu.speed(1) # 移动速度为1
tu.goto(-200,200) # 将画笔移动到坐标为-200, 200的位置
tu.down()
# 绘制矩形边框
tu.fd(438)
tu.right(90)
tu.fd(292)
tu.right(90)
tu.fd(438)
tu.right(90)
tu.fd(292)
tu.end_fill()
time.sleep(1) # 绘制完成后睡眠一秒
# 绘制大星
tu.begin_fill() # 准备开始填充图形
tu.up() # 画笔开始绘制
tu.fillcolor("yellow") # 填充颜色
tu.color("yellow")
tu.seth(0) # 旋转初始角度0°
tu.goto(-170, 145) # 将画笔移动到坐标为-170, 145的位置
tu.down() # 画笔绘制结束
for i in range(5): # 循环5次
tu.forward(50) # 向当前画笔方向移动50像素长
tu.right(144) # 顺时针移动 144°
tu.end_fill() # 填充完成
time.sleep(1)
# 绘制四小星
# [第一颗、小星]
tu.begin_fill() # 准备开始填充图形
tu.up() # 画笔开始绘制
tu.fillcolor("yellow") # 填充颜色
tu.color("yellow")
tu.seth(305) # 旋转初始角度305°
tu.goto(-100, 180) # 将画笔移动到坐标为-100, 180的位置
tu.down() # 画笔绘制结束
for i in range(5): # 循环5次
tu.forward(20) # 向当前画笔方向移动20像素长
tu.right(144) # 顺时针移动 144°
tu.end_fill() # 填充完成
time.sleep(1)
# [第二颗、小星]
tu.begin_fill() # 准备开始填充图形
tu.up() # 画笔开始绘制
tu.fillcolor("yellow") # 填充颜色
tu.color("yellow")
tu.seth(30) # 旋转初始角度30°
tu.goto(-85, 150) # 将画笔移动到坐标为-85, 150的位置
tu.down() # 画笔绘制结束
for i in range(5): # 循环5次
tu.forward(20) # 向当前画笔方向移动20像素长
tu.right(144) # 顺时针移动 144°
tu.end_fill() # 填充完成
time.sleep(1)
# [第三颗、小星]
tu.begin_fill() # 准备开始填充图形
tu.up() # 画笔开始绘制
tu.fillcolor("yellow") # 填充颜色
tu.color("yellow")
tu.seth(3) # 旋转初始角度3°
tu.goto(-85, 120) # 将画笔移动到坐标为-85, 120的位置
tu.down() # 画笔绘制结束
for i in range(5): # 循环5次
tu.forward(20) # 向当前画笔方向移动20像素长
tu.right(144) # 顺时针移动 144°
tu.end_fill() # 填充完成
time.sleep(1)
# [第四颗、小星]
tu.begin_fill() # 准备开始填充图形
tu.up() # 画笔开始绘制
tu.fillcolor("yellow") # 填充颜色
tu.color("yellow")
tu.seth(300) # 旋转初始角度300°
tu.goto(-100, 100) # 将画笔移动到坐标为-100, 100的位置
tu.down() # 画笔绘制结束
for i in range(5): # 循环5次
tu.forward(20) # 向当前画笔方向移动20像素长
tu.right(144) # 顺时针移动 144°
tu.end_fill() # 填充完成
time.sleep(1)
tu.done() # 程序运行完后不退出
if __name__ == "__main__":
HQDemo()