代码:
import turtle as t
import random
t.pensize(1)
t.delay(0)
t.hideturtle()
t.screensize(800,600,‘black’)
t.penup()
t.color(‘white’)
t.goto(-200,0)
t.write(“每个人,都有属于自己的星空!\n”,move=True,align=“left”,font=(“楷体”, 30, “bold”))
t.goto(30,-10)
t.write("–<<小王子>>",move=True,align=“left”,font=(“楷体”,20, “bold”))
#小王子的身体
t.up()
t.goto(-20,-220)
t.pd()
t.seth(90)
t.fillcolor(‘green’)
t.begin_fill()
t.pencolor(‘green’)
t.fd(60)
t.left(90)
t.fd(45)
t.left(90)
t.fd(60)
t.left(90)
t.fd(45)
t.up()
t.goto(-43,-185)
t.circle(22)
t.end_fill()
#小王子的头
t.up()
t.goto(-43,-150)
t.pd()
t.fillcolor(‘orange’)
t.begin_fill()
t.pencolor(‘orange’)
t.circle(15)
t.end_fill()
#月亮
t.up()
t.goto(0,-800)
t.pd()
t.fillcolor(‘yellow’)
t.begin_fill()
t.pencolor(‘yellow’)
t.circle(312)
t.end_fill()
#小王子的围巾
t.up()
t.goto(-62,-151)
t.pd()
t.pensize(10)
t.pencolor(‘red’)
t.fd(10)
t.seth(-40)
for i in range(3):
t.circle(15, 80)
t.circle(-15, 80)
t.circle(15, 80/2)
t.fd(20)
t.pensize(1)
def stars1(x,y,angle,lenth):
t.pencolor(“yellow”)
t.fillcolor(‘yellow’)
t.speed(0)
t.penup()
t.goto(x,y)
t.begin_fill()
t.pendown()
t.left(angle)
for i in range(5):
t.fd(lenth)
t.right(144)
t.end_fill()
t.left(-angle)
def stars2(x,y):
t.pencolor(“yellow”)
t.fillcolor(‘yellow’)
t.speed(0)
t.penup()
t.goto(x,y)
t.begin_fill()
t.pendown()
t.left(angle)
for i in range(4):
t.circle(2)
t.end_fill()
def stars(x,y,angle,lenth):
t.pencolor(“white”)
t.fillcolor(‘white’)
t.speed(0)
t.penup()
t.goto(x,y)
t.begin_fill()
t.pendown()
t.left(angle)
for i in range(5):
t.fd(lenth)
t.right(144)
t.end_fill()
t.left(-angle)
def stars3(x,y):
t.pencolor(“white”)
t.fillcolor(‘white’)
t.speed(0)
t.penup()
t.goto(x,y)
t.begin_fill()
t.pendown()
t.left(angle)
for i in range(4):
t.circle(1)
t.end_fill()
for i in range(150):
x=random.randint(-400,400)
y=random.randint(-300,300)
lenth=random.randint(1,8)
angle=random.randint(0,180)
stars(x,y,angle,lenth)
x=random.randint(-400,400)
y=random.randint(-300,300)
lenth=random.randint(1,8)
angle=random.randint(0,180)
stars1(x,y,angle,lenth)
x=random.randint(-400,400)
y=random.randint(-300,300)
stars2(x,y)
x=random.randint(-400,400)
y=random.randint(-300,300)
stars3(x,y)
t.done()