1.三角形
import turtle turtle.pendown() turtle.fd(100) turtle.seth(-120) turtle.fd(100) turtle.seth(120) turtle.fd(100) turtle.seth(60) turtle.fd(100) turtle.seth(-60) turtle.fd(200) turtle.seth(-180) turtle.fd(200) turtle.seth(60) turtle.fd(100) turtle.seth(0)
2.没有角的正方形
import turtle turtle.penup() turtle.fd(30) turtle.pendown() turtle.fd(60) turtle.penup() turtle.fd(30) turtle.seth(90) turtle.fd(30) turtle.pendown() turtle.fd(60) turtle.penup() turtle.fd(30) turtle.seth(-180) turtle.fd(30) turtle.pendown() turtle.fd(60) turtle.penup() turtle.fd(30) turtle.seth(-90) turtle.fd(30) turtle.pendown() turtle.fd(60)
3.六角形
import turtle turtle.seth(90) turtle.pendown() turtle.fd(180) turtle.seth(-30) turtle.fd(180) turtle.seth(-150) turtle.fd(180) turtle.seth(90) turtle.fd(120) turtle.seth(30) turtle.fd(120) turtle.seth(-90) turtle.fd(180) turtle.seth(150) turtle.fd(180) turtle.seth(30) turtle.fd(60)
4.正方形螺旋线
a=6
import turtle
turtle.pendown()
turtle.seth(90)
turtle.fd(3)
turtle.seth(-180)
turtle.fd(3)
turtle.seth(-90)
turtle.fd(6)
turtle.seth(0)
for i in range(24):
turtle.fd(a)
turtle.seth(90)
a=a+3
turtle.fd(a)
turtle.seth(-180)
a=a+3
turtle.fd(a)
turtle.seth(-90)
a=a+3
turtle.fd(a)
turtle.seth(0)
a=a+3
5.蟒蛇
import turtle def drawSnake(rad,angle,len,neckrad): colors = ["red","orange","yellow","green","cyan","blue"] for i in range(len): turtle.color(colors[i]) turtle.circle(rad,angle) turtle.circle(-rad,angle) turtle.color("purple") turtle.circle(rad,angle/2) turtle.fd(rad) turtle.circle(neckrad+1,180) turtle.fd(rad*2/3) def main(): turtle.setup(1300,800,0,0) turtle.penup() turtle.goto(-350,0) turtle.pendown() pythonsize = 30 turtle.pensize(pythonsize) turtle.seth(-40) drawSnake(40,80,6,pythonsize/2) main()