猫史档案馆


【Python作品分享】StarrySky_new【作品秀】

用户:RainDawn_SATARainDawn_SATA查看:0 回复:0 评论:0 创建时间:2021-09-20T13:33:51


【作品展示】

center_image

 

【作品介绍】

for new color

 

【作品源代码】

import turtle
import random as r

turtle.bgcolor("darkslateblue")
turtle.tracer(0)

myscreen = turtle.Screen()
myscreen.setworldcoordinates(0, 0, 400, 400)

mypen = turtle.Pen()

# 绘制五角星
def star(x, y, angle, length, color):
    setpen(x, y, color)
    mypen.setheading(angle)
    mypen.begin_fill()
    for i in range(5):
        mypen.fd(length)
        mypen.rt(144)
    mypen.end_fill()

# 绘制五角星
def starmac(x, y, angle, length, color):
    setpen(x, y, color)
    mypen.setheading(angle)
    mypen.begin_fill()
    for i in range(5):
        mypen.fd(length/4)
        mypen.lt(72)
        mypen.fd(length/4)
        mypen.rt(144)
    mypen.end_fill()

def setpen(x, y, color):
    mypen.pu()
    mypen.setheading(0)
    mypen.goto(x, y)
    mypen.color(color, color)
    mypen.pd()
    mypen.setheading(0)

def main():
    times = turtle.numinput("How many stars do you wnt to draw?", "How many stars do you wnt to draw?",35, 0)
    for i in range(int(times)):
        colors = ["white", "lightyellow","lightgoldenrodyellow","yellow"]
        color = r.choice(colors)
        starmac(r.randint(0,450),r.randint(0,450),r.randint(0,120),
             r.randint(10,50),color)
        
main()
turtle.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页