1.狮子
import turtle as t
def hair(): # 画头发
t.penup()
t.goto(-50, 150)
t.pendown()
t.fillcolor('#a2774d')
t.begin_fill()
for j in range(10): # 重复执行10次
t.setheading(60 - (j * 36)) # 每次调整初始角度
t.circle(-50, 120) # 画120度的弧
t.end_fill()
def face(): # 画脸
t.penup()
t.goto(0, 100)
t.pendown()
t.fillcolor('#f2ae20')
t.begin_fill()
t.setheading(180)
t.circle(85)
t.end_fill()
# 下巴
t.circle(85, 120)
t.fillcolor('white')
t.begin_fill()
t.circle(85, 120)
t.setheading(135)
t.circle(100, 95)
t.end_fill()
def ears(dir): # 画眼睛,dir用来设置方向,左右眼对称
t.penup()
t.goto((0 - dir) * 30, 90)
t.setheading(90)
t.pendown()
t.fillcolor('#f2ae20')
t.begin_fill()
t.circle(dir * 30)
t.end_fill()
t.penup()
t.goto((0 - dir) * 40, 85)
t.setheading(90)
t.pendown()
t.fillcolor('white')
t.begin_fill()
t.circle(dir * 17)
t.end_fill()
def nose(): # 画鼻子
t.penup()
t.goto(20, 0)
t.setheading(90)
t.pendown()
t.fillcolor('#a2774d')
t.begin_fill()
t.circle(20)
t.end_fill()
def eye(dir): # 画耳朵,dir用来设置方向,左右耳对称
t.penup()
t.goto((0 - dir) * 30, 20)
t.setheading(0)
t.pendown()
t.fillcolor('black')
t.begin_fill()
t.circle(10)
t.end_fill()
def mouth(): # 画嘴巴
t.penup()
t.goto(0, 0)
t.setheading(-90)
t.pendown()
t.forward(50)
t.setheading(0)
t.circle(80, 30)
t.penup()
t.goto(0, -50)
t.setheading(180)
t.pendown()
t.circle(-80, 30)
hair()
ears(1)
ears(-1)
face()
eye(1)
eye(-1)
mouth()
nose()
t.done()
2.比心
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>原生JS制作爱心表白代码 - 站长素材</title>
<link rel="stylesheet" href="css/love.css">
</head>
<body>
<div class="container" onselectstart="return false;" unselectable="on" style="-moz-user-select:none;">
<div class="body_left">
<img src="images/biubiubiu.gif" alt="" ondragstart='return false;'>
</div>
<div class="body_center love">
<div class="block">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
</div>
</div>
</div>
<div class="footer">
<div class="border">
<div class="border-top"></div>
<div class="border-bottom"></div>
</div>
<div class="copyright">
<div id="author">520快乐</div>
</div>
</div>
<script type="text/javascript" src="js/love.js"></script>
</body>
</html>
3.烟火
from turtle import *
colors = ["red", "yellow", "blue", "lime"]
bgcolor("black")
x = 6
t = [Turtle(), Turtle()]
for index, i in enumerate(t):
i.speed(0)
i.color("white")
i.shape("circle")
i.shapesize(0.3)
i.width(3)
i.pu()
i.seth(90)
i.fd(350)
i.seth(-180)
i.pd()
t[0].pu()
delay(0)
speed(0)
ht()
for i in colors:
color(i)
for i in range(360):
t[0].fd(x)
t[0].lt(1)
pu()
goto(t[0].pos())
pd()
t[1].fd(2 * x)
t[1].lt(2)
goto(t[1].pos())
done()
2023
早睡早起,减肥健身
标签:goto,51CTO,第一篇,博文,setheading,pendown,circle,dir,fill From: https://blog.51cto.com/u_16288000/7723828