1.前言
一定要看到最后啊!真的很好看。一定要自己去试一试。
2.分叉树
有小花,很真实。
import turtle as t
import random as r
t.seth(90)
t.speed(0)
t.pu()
tx = 0
t.goto(tx,-300)
t.pd()
def fc(cd,cen,cx):
t.colormode(255)
t.pencolor(102,51,0)
if cen >= 0:
t.speed(0)
t.pensize(cx)
t.fd(cd)
t.left(15)
c = r.randint(10,100)
fc(c,cen-1,cx-4)
t.pencolor('pink')
t.fd(10)
t.circle(2)
t.bk(10)
t.right(30)
c = r.randint(10, 100)
fc(c, cen - 1, cx-4)
t.left(15)
t.bk(cd)
t.hideturtle()
fc(60,4,20)
t.pu()
t.fd(100)
t.pd()
fc(60,4,18)
t.pu()
t.fd(100)
t.pd()
fc(60,4,17)
t.pu()
tx += 200
t.goto(tx,-300)
t.pd()
t.mainloop()
3.小风扇
小风扇,没什么特别的。
import turtle as t
t.pu()
t.goto(0,-200)
t.pd()
t.speed(0)
t.pencolor('light green')
t.pensize(50)
t.seth(90)
t.fd(100)
t.pensize(10)
t.fillcolor('tan')
t.seth(0)
t.begin_fill()
t.circle(100)
t.end_fill()
t.seth(90)
t.pensize(3)
t.fd(100)
t.dot(50)
a = 270
for i in range(20):
a += 360/20
t.seth(a)
t.fd(100)
t.fd(-100)
t.fd(100)
t.hideturtle()
t.mainloop()
4.小雪花
from turtle import* a = 0 pencolor('blue') pensize(2) for i in range(8): seth(a) fd(100) left(45) fd(20) fd(-20) right(90) fd(20) fd(-20) seth(a) fd(-100) a+=45 mainloop()
5.小金鱼
from turtle import *
def fish(bg_color,shen_color,lin_color): #背景颜色,身体的颜色,鳞片的颜色
def pen(x,y):
pu()
goto(x, y)
pd()
def yuan(x,y,dx,c): #大小-->dx。color-->c
pen(x,y)
color(c)
begin_fill()
circle(dx)
end_fill()
def ban_yuan(x,y,dx,c): #大小-->dx。color-->c
pen(x, y)
pencolor(c)
circle(dx,200)
speed(0)
bgcolor(bg_color)
yuan(-30,-10,30,shen_color)
yuan(30,160,30,shen_color)
yuan(0,0,100,shen_color)
yuan(-80,100,30,'white')
yuan(-90,110,20,'black')
x = -30
y = 10
for i in range(6):
ban_yuan(x,y,15,lin_color)
seth(0)
y+=30
x = 0
y = 0
for i in range(5):
ban_yuan(x,y,20,lin_color)
seth(0)
y+=40
x = 30
y = 10
for i in range(6):
ban_yuan(x,y,15,lin_color)
seth(0)
y+=30
x = 60
y = 20
for i in range(5):
ban_yuan(x,y,15,lin_color)
seth(0)
y+=30
seth(180)
pen(190,0)
color(shen_color)
begin_fill()
circle(-100,200)
seth(185)
circle(100,155)
end_fill()
fish('blue','orange red','red')
mainloop()
6.四季画册里的冬季雪景
可以看看我的文章四季画册,画了一个四季画册。
def d():
import turtle as t
import random as r
t.speed(0)
t.bgcolor('blue')
t.pencolor('orange')
t.pensize(5)
t.fillcolor('red')
t.begin_fill()
t.circle(200)
t.end_fill()
t.pu()
t.goto(-400,-350)
t.pd()
t.fillcolor('white')
t.begin_fill()
for i in range(2):
t.fd(800)
t.left(90)
t.fd(400)
t.left(90)
t.end_fill()
#画房子
x = -300
y = -225
t.pu()
t.goto(x,y)
t.pd()
t.fillcolor('brown')
t.begin_fill()
for i in range(4):
t.fd(200)
t.left(90)
t.end_fill()
t.fillcolor('brown')
t.begin_fill()
t.fd(20)
t.seth(90)
t.fd(100)
t.right(90)
t.fd(50)
t.right(90)
t.fd(100)
t.pu()
t.goto(x+200,y+200)
t.pd()
t.seth(135)
t.fd(140)
t.seth(225)
t.fd(140)
t.pu()
t.goto(x+175,y+100)
t.pd()
t.seth(180)
t.end_fill()
t.fillcolor('light blue')
t.begin_fill()
for i in range(4):
t.fd(50)
t.left(90)
t.end_fill()
t.pu()
t.goto(x+200,y+200)
t.pd()
t.seth(180)
t.fd(200)
#画小雪花
for i in range(50):
t.pu()
t.goto(r.randint(-300,300), r.randint(-100,300))
t.pd()
t.pencolor('white')
t.dot(10)
def fc(cd,cen,cx):
t.colormode(255)
t.pencolor(102,51,0)
if cen >= 0:
t.speed(0)
t.pensize(cx)
t.fd(cd)
t.left(15)
c = r.randint(10,100)
fc(c,cen-1,cx-4)
t.right(30)
c = r.randint(10, 100)
fc(c, cen - 1, cx-4)
t.left(15)
t.bk(cd)
t.pu()
t.goto(100,-100)
t.pd()
t.seth(90)
fc(60,4,20)
#画非常大的雪花
a = 0
t.pencolor('white')
t.pensize(10)
for j in range(r.randint(2, 6)):
t.pu()
t.goto(r.randint(-300,300), r.randint(100,300))
t.pd()
for i in range(8):
t.seth(a)
t.fd(30)
t.left(45)
t.fd(10)
t.fd(-10)
t.right(90)
t.fd(10)
t.fd(-10)
t.seth(a)
t.fd(-30)
a+=45
d()