机器猫:
# -*- coding: utf-8 -*-
from turtle import *
import turtle
speed(0)
penup()
seth(180)
fd(200)
seth(0)
penup() #外圈头
circle(150, 40)
pendown()
fillcolor('dodgerblue')
begin_fill()
circle(150, 280)
end_fill() #外圈头
fillcolor("red")
begin_fill() #外圈头
seth(0) #项圈
fd(200)
circle(-5,90)
fd(10)
circle(-5,90)
fd(210)
circle(-5,90)
fd(10)
circle(-5,90)
end_fill() #项圈
fd(183) #右脸
left(45)
fillcolor("white")
begin_fill()
circle(120,100)
seth(90) #眼睛
a = 2.5
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a -= 0.05
lt(3)
fd(a)
else:
a += 0.05
lt(3)
fd(a)
penup()
seth(180)
fd(60)
pendown()
seth(90)
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a -= 0.05
lt(3)
fd(a)
else:
a += 0.05
lt(3)
fd(a) #眼睛
seth(180)
penup()
fd(60)
pendown()
seth(215)
circle(120,100)
end_fill() #脸部颜色和眼睛部分
seth(0) # 左眼珠部分
penup()
fd(40)
seth(90)
fd(170)
seth(0)
fd(5)
pendown()
fillcolor("black")
begin_fill()
circle(15,360)
end_fill()
seth(90)
penup()
fd(5)
pendown()
seth(0)
fillcolor("white")
begin_fill()
circle(4,360)
end_fill() #左眼珠部分
penup() #右眼珠
seth(0)
fd(58)
seth(270)
fd(15)
seth(0)
pensize(5)
circle(18,90)
pendown()
circle(18,180)
penup()
circle(18,90)
pendown()
pensize(1)#右眼珠
penup() #鼻子
seth(270)
fd(7)
seth(180)
fd(27)
pendown()
fillcolor("red")
begin_fill()
circle(20)
end_fill()#鼻子
seth(270)#嘴
penup()
fd(40)
pendown()
pencolor("black")
pensize(2)
fd(90)
seth(0)
circle(120,50)
penup()
circle(120,260)
pendown()
circle(120,50)#嘴
penup() #胡须
seth(90)
fd(60)
seth(0)
fd(20)
pendown()
fd(60)
penup()
fd(-60)
seth(90)
fd(20)
pendown()
seth(15)
fd(60)
penup()
fd(-60)
seth(270)
fd(40)
pendown()
seth(-15)
fd(50)
penup()
fd(-50)
seth(180)
fd(40)
pendown()
seth(-165)
fd(50)
penup()
fd(-50)
seth(90)
fd(40)
seth(165)
pendown()
fd(60)
fd(-60)
penup()
seth(280)
fd(20)
seth(180)
pendown()
fd(60) #胡须
penup() #下半身
home()
penup()
seth(180)
fd(200)
seth(0)
seth(90)
fd(36)
seth(0)
fd(98)
pendown()
fillcolor("dodgerblue")
begin_fill()
seth(50)
fd(70)
seth(40)
fd(20)
right(90)
fd(35)
right(75)
fd(105)
seth(90)
fd(10)
seth(-90)
fd(90)
seth(-95)
fd(80)
seth(180)
fd(80) # 右腿
penup() #左腿和过渡
fd(30)
seth(-90)
fd(30)
seth(0)
circle(30,90)
pendown()
circle(30,180)
penup()
circle(30,90)
seth(90)
fd(30)
seth(180)
fd(30)
pendown()
fd(80) #腿
seth(92)
fd(80)
seth(90)
fd(75)
fd(-30)
seth(-135)
fd(30)
right(90)
fd(40)
right(93)
fd(78)
seth(0)
fd(205)
end_fill()
fillcolor("red")# 项圈的补充
begin_fill()
circle(5,90)
fd(10)
circle(5,90)
fd(10)
end_fill()
penup()
seth(50)
fd(70)
seth(40)
fd(16)
right(90)
fd(20)
pendown()
fillcolor("white")# 手掌
begin_fill()
circle(30)
end_fill()
penup()
seth(-90)
fd(253)
seth(180)
fd(160)
seth(-90)
fd(30)
seth(0)
pendown()
fillcolor("white")
begin_fill()
penup()
circle(31,90)
pendown()
circle(31,180)
penup()
circle(31,90)
end_fill()
seth(90)
fd(30)
seth(0)
fd(24)
pendown()
seth(180)
circle(15,180)# 脚
fd(90)
circle(15,180)
fd(90)
penup()
seth(180)
fd(60)
penup()
seth(0)
pendown()
circle(-15,180)
fd(80)
circle(-15,180)
fd(80)
penup()
seth(180)
fd(140)
seth(90)
fd(90)
seth(-45)
pendown()
fillcolor("white")
begin_fill()
circle(30)
end_fill()
penup()
seth(-90)
fd(50)
seth(0)
fd(173)
seth(0)
fillcolor("white")# 胸
begin_fill()
pendown()
circle(90,128)
seth(180)
fd(145)
seth(-128)
circle(90,129)
end_fill()
seth(90)
penup()
fd(35)
seth(0)
pendown()
circle(70,90)# 口袋
seth(180)
fd(140)
seth(-90)
circle(70,90)
penup()
seth(90)
fd(90)
pendown()
seth(0)
fillcolor("#ffd200")#铃铛
begin_fill()
circle(20)
end_fill()
seth(90)
pensize(2)
fd(13)
fillcolor("black")
begin_fill()
seth(0)
circle(2)
end_fill()
seth(-90)
fd(13)
seth(0)
penup()
circle(20,110)
pendown()
seth(170)
fd(20)
seth(190)
fd(20)
penup()
seth(-90)
fd(3.5)
pendown()
seth(10)
fd(20)
seth(-10)
fd(22)
turtle.done()
# hideturtle()
皮卡丘:
import turtle
# 画鼻子
def drawNose():
turtle.penup()
turtle.seth(90)
turtle.fd(100)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('black')
turtle.seth(45)
turtle.fd(25)
turtle.seth(135)
turtle.circle(25, 95)
turtle.seth(315)
turtle.fd(25)
turtle.end_fill()
# 画眼睛
def drawEyes(seth, fd, r):
turtle.penup()
turtle.seth(seth)
turtle.fd(fd)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('black')
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.circle(50, r)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('white')
turtle.circle(20)
turtle.end_fill()
# 画脸
def drawFace(seth, fd):
turtle.penup()
turtle.seth(seth)
turtle.fd(fd)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('red')
turtle.circle(70)
turtle.end_fill()
# 画嘴巴
def drawLip():
turtle.penup()
turtle.seth(135)
turtle.fd(250)
turtle.pendown()
turtle.seth(-300)
turtle.circle(30, -65)
turtle.begin_fill()
turtle.fillcolor('Firebrick')
turtle.seth(165)
turtle.fd(140)
turtle.seth(195)
turtle.fd(140)
turtle.seth(-360)
turtle.circle(30, -65)
turtle.penup()
turtle.seth(-60)
turtle.circle(30, 65)
turtle.pendown()
turtle.seth(-70)
turtle.fd(240)
turtle.circle(55, 140)
turtle.seth(70)
turtle.fd(240)
turtle.end_fill()
turtle.seth(-110)
turtle.fd(80)
turtle.begin_fill()
turtle.fillcolor('Firebrick')
turtle.seth(120)
turtle.circle(120, 123)
turtle.seth(-70)
turtle.fd(165)
turtle.circle(55, 140)
turtle.seth(72)
turtle.fd(165)
turtle.end_fill()
# 主函数
def main():
turtle.pensize(4)
turtle.hideturtle()
turtle.setup(1000, 600)
turtle.speed(10)
turtle.screensize(bg='yellow')
drawNose()
drawEyes(160, 250, 60)
drawEyes(-9.5, 530, 230)
drawFace(195, 600)
drawFace(-11, 720)
drawLip()
turtle.done()
if __name__ == '__main__':
main()
樱花树:
from turtle import *
from random import *
from math import *
class Tree:
def __init__(self):
setup(1000, 500)
bgcolor(1, 1, 1) # 背景色
# ht() # 隐藏turtle
speed(10) # 速度 1-10渐进,0 最快
# tracer(1, 100) # 设置绘图屏幕刷新频率,参数1设置在正常刷新频次的第参数1次刷新,参数2设置每次刷新的时延
tracer(0, 0)
pu() # 抬笔
backward(100)
# 保证笔触箭头方向始终不向下,此处使其左转90度,而不是右转
left(90) # 左转90度
backward(300) # 后退300
def tree(self, n, l):
pd() # 下笔
# 阴影效果
t = cos(radians(heading()+45))/8+0.25
pencolor(t, t, t)
pensize(n/1.2)
forward(l) # 画树枝
if n > 0:
b = random()*15+10 # 右分支偏转角度
c = random()*15+10 # 左分支偏转角度
d = l*(random()*0.25+0.7) # 下一个分支的长度
# 右转一定角度,画右分支
right(b)
self.tree(n-1, d)
# 左转一定角度,画左分支
left(b+c)
self.tree(n-1, d)
# 转回来
right(c)
else:
# 画叶子
right(90)
n = cos(radians(heading()-45))/4+0.5
pencolor(n,n*0.8,n*0.8)
fillcolor(n,n*0.8,n*0.8)
begin_fill()
circle(3)
left(90)
end_fill()
# 添加0.3倍的飘落叶子
if random() > 0.7:
pu()
# 飘落
t = heading()
an = -40 + random()*40
setheading(an)
dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2)
forward(dis)
setheading(t)
# 画叶子
pd()
right(90)
n = cos(radians(heading()-45))/4+0.5
pencolor(n*0.5+0.5,0.4+n*0.4,0.4+n*0.4)
fillcolor(n, n * 0.8, n * 0.8)
begin_fill()
circle(2)
left(90)
end_fill()
pu()
# 返回
t = heading()
setheading(an)
backward(dis)
setheading(t)
# pass
pu()
backward(l) # 退回
def main():
tree = Tree()
tree.tree(12, 100) # 递归7层
done()
if __name__ == '__main__':
main()
来源:CSDN
作者:浮华乱世丶谁许谁一生繁华
链接:https://blog.csdn.net/Kris_Kris/article/details/104108689