玫瑰
import turtle as t
from random import randint
t.speed(0)
def pot():
t.bgcolor('black')
x = 1
while x < 400:
r = randint(0,255)
g = randint(0, 255)
b = randint(0, 255)
t.colormode(255)
t.pencolor(r,g,b)
t.fd(50 + x)
t.rt(90.911)
x = x + 1
pot()
t.done()
病毒
import turtle as t
def jump(x, y):
t.penup()
t.goto(x, y)
t.pendown()
jump(0,-200)
t.bgcolor('black')
t.speed(0)
n = 0
t.colormode(255)
while n < 200:
t.left(n)
t.fd(n * 3)
t.color(n,225 - n,n % 30 * 8)
n += 1
t.done()
海绵宝宝
from turtle import *
#大致外观
setup(600,600)
pensize(3)
speed(20)
color('black','yellow')
penup()
goto(-120,120)
pendown()
begin_fill()
seth(-45) #Turtle中的turtle.seth(angle)函数表示小乌龟启动时运动的方向
for i in range(0,4):
for i in range(0,5):
circle(15,90)
circle(-15,90)
right(90)
end_fill()
#眼睛
pensize(1)
color('black','white')
penup()
goto(-70,30)
pendown()
begin_fill()
circle(30)
end_fill()
#1眼睛
color('white','blue')
penup()
goto(-40,43)
pendown()
begin_fill()
circle(10)
end_fill()
#2眼睛
color('white','black')
penup()
goto(-35,46)
pendown()
begin_fill()
circle(5)
end_fill()
#左眉毛1
pensize(3)
color('black')
penup()
goto(-68,82)
pendown()
fd(6)
#左眉毛2
pensize(3)
color('black')
penup()
goto(-50,88)
pendown()
right(45)
fd(6)
#左眉毛3
pensize(3)
color('black')
penup()
goto(-30,82)
pendown()
right(30)
fd(6)
#右眼睛
pensize(1)
color('black','white')
penup()
goto(3,67)
pendown()
begin_fill()
circle(30)
end_fill()
#右1眼睛
color('white','blue')
penup()
goto(3,56)
pendown()
begin_fill()
circle(10)
end_fill()
#右2眼睛
color('white','black')
penup()
goto(7,54)
pendown()
begin_fill()
circle(5)
end_fill()
#右眉毛1
pensize(3)
color('black')
penup()
goto(10,82)
pendown()
left(50)
fd(6)
#右眉毛2
pensize(3)
color('black')
penup()
goto(30,88)
pendown()
right(20)
fd(6)
#右眉毛3
pensize(3)
color('black')
penup()
goto(50,82)
pendown()
right(15)
fd(6)
#嘴巴
pensize(1)
color('black','IndianRed3')
penup()
goto(-86,-20)
pendown()
left(65)
begin_fill()
right(33)
circle(70,150)
# circle(120,80)
fd(10)
left(130)
circle(-184,45)
end_fill()
#舌头
color('black', 'orange red')
penup()
goto(-66,-50)
pendown()
right(130)
circle(-140,46)
#鼻子
penup()
goto(-15,10)
pendown()
fd(40)
circle(5,180)
fd(40)
#裤子
color('black','white')
penup()
goto(-123,-85)
pendown()
begin_fill()
left(100)
fd(20)
left(93)
fd(225)
left(95)
fd(20)
left(85)
fd(225)
end_fill()
#二层裤子
color('black','orange4')
penup()
goto(-123,-106)
pendown()
begin_fill()
left(90)
fd(30)
left(90)
fd(225)
left(90)
fd(30)
left(90)
fd(225)
end_fill()
#裤缝
color('black')
pensize(8)
for i in range(0,4):
penup()
goto(-83+(i*60),-120)
pendown()
fd(30)
#裤腿1
color('black','orange3')
pensize(1)
penup()
goto(-63,-137)
pendown()
begin_fill()
left(90)
fd(10)
left(30)
circle(15,120)
left(30)
fd(10)
left(90)
fd(30)
end_fill()
#裤腿2
color('black','orange3')
pensize(1)
penup()
goto(23,-137)
pendown()
begin_fill()
left(90)
fd(10)
left(30)
circle(15,120)
left(30)
fd(10)
left(90)
fd(30)
end_fill()
#腿1
color('black')
penup()
goto(-53,-155)
pendown()
left(90)
fd(65)
fd(30)
left(90)
fd(20)
penup()
goto(-43,-155)
pendown()
right(90)
fd(60)
circle(20,90)
fillcolor('black')
begin_fill()
fd(5)
circle(-7,180)
fd(35)
right(90)
fd(24)
end_fill()
#腿2
color('black')
penup()
goto(33,-152)
pendown()
right(180)
fd(55)
fd(30)
left(90)
fd(20)
penup()
goto(43,-152)
pendown()
right(90)
fd(65)
circle(20,90)
fillcolor('black')
begin_fill()
circle(-7,180)
fd(32)
right(90)
fd(22)
end_fill()
#左手
color('black','yellow')
penup()
goto(-120,-10)
pendown()
begin_fill()
left(45)
fd(100)
circle(-15,80)
fd(5)
circle(5,180)
fd(20)
#第2个手指
right(150)
fd(35)
circle(5,180)
fd(40)
#第3个手指
right(150)
fd(30)
circle(5,180)
fd(30)
#第4个手指
right(140)
fd(30)
circle(5,180)
fd(45)
circle(15,90)
right(40)
right(70)
fd(110)
end_fill()
#右手
color('black','yellow')
penup()
goto(90,-10)
pendown()
begin_fill()
left(90)
fd(100)
circle(-15,80)
fd(5)
circle(5,180)
fd(20)
#第2个手指
right(150)
fd(35)
circle(5,180)
fd(40)
# #第3个手指
right(150)
fd(30)
circle(5,180)
fd(30)
# #第4个手指
right(140)
fd(30)
circle(5,180)
fd(45)
circle(15,90)
right(40)
right(70)
fd(98)
end_fill()
penup()
goto(-120,160)
pendown()
done()
时钟
import turtle
from datetime import *
# 抬起画笔,向前运动一段距离放下
def Skip(step):
turtle.penup()
turtle.forward(step)
turtle.pendown()
def mkHand(name, length):
# 注册Turtle形状,建立表针Turtle
turtle.reset()
Skip(-length * 0.1)
# 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。
turtle.begin_poly()
turtle.forward(length * 1.1)
# 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。
turtle.end_poly()
# 返回最后记录的多边形。
handForm = turtle.get_poly()
turtle.register_shape(name, handForm)
def Init():
global secHand, minHand, hurHand, printer
# 重置Turtle指向北
turtle.mode("logo")
# 建立三个表针Turtle并初始化
mkHand("secHand", 135)
mkHand("minHand", 125)
mkHand("hurHand", 90)
secHand = turtle.Turtle()
secHand.shape("secHand")
minHand = turtle.Turtle()
minHand.shape("minHand")
hurHand = turtle.Turtle()
hurHand.shape("hurHand")
for hand in secHand, minHand, hurHand:
hand.shapesize(1, 1, 3)
hand.speed(0)
# 建立输出文字Turtle
printer = turtle.Turtle()
# 隐藏画笔的turtle形状
printer.hideturtle()
printer.penup()
def SetupClock(radius):
# 建立表的外框
turtle.reset()
turtle.pensize(7)
for i in range(60):
Skip(radius)
if i % 5 == 0:
turtle.forward(20)
Skip(-radius - 20)
Skip(radius + 20)
if i == 0:
turtle.write(int(12), align="center", font=("Courier", 14, "bold"))
elif i == 30:
Skip(25)
turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))
Skip(-25)
elif (i == 25 or i == 35):
Skip(20)
turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))
Skip(-20)
else:
turtle.write(int(i / 5), align="center", font=("Courier", 14, "bold"))
Skip(-radius - 20)
else:
turtle.dot(5)
Skip(-radius)
turtle.right(6)
def Week(t):
week = ["星期一", "星期二", "星期三",
"星期四", "星期五", "星期六", "星期日"]
return week[t.weekday()]
def Date(t):
y = t.year
m = t.month
d = t.day
return "%s %d%d" % (y, m, d)
def Tick():
# 绘制表针的动态显示
t = datetime.today()
second = t.second + t.microsecond * 0.000001
minute = t.minute + second / 60.0
hour = t.hour + minute / 60.0
secHand.setheading(6 * second)
minHand.setheading(6 * minute)
hurHand.setheading(30 * hour)
turtle.tracer(False)
printer.forward(65)
printer.write(Week(t), align="center",
font=("Courier", 14, "bold"))
printer.back(130)
printer.write(Date(t), align="center",
font=("Courier", 14, "bold"))
printer.home()
turtle.tracer(True)
# 100ms后继续调用tick
turtle.ontimer(Tick, 100)
def main():
# 打开/关闭龟动画,并为更新图纸设置延迟。
turtle.tracer(False)
Init()
SetupClock(160)
turtle.tracer(True)
Tick()
turtle.mainloop()
if __name__ == "__main__":
main()