说明:海龟绘图网上的案例非常多,网上百度一搜就可以找到各种各样的不同绘图参考代码,简单的有,难的有绘制梵高画、九大行星图等等,有需求的最好问度娘,简单又方便。
分享Python 基础教程:
https://www.runoob.com/python/python-tutorial.html
01
四色彩色螺旋线
from turtle import *
from time import *
import turtle
t = Turtle()
t.pensize(2)
turtle.bgcolor("black")
colors = ["red", "yellow", 'purple', 'blue']
t._tracer(False)for x in range(200):
t.forward(2*x)
t.color(colors[x % 4])
t.left(91)
t._tracer(True)done()
02
六色彩色螺旋线
from turtle import *
from time import *
import turtle
t = turtle.Pen()
turtle.bgcolor("black")
sides=6
colors = ["red", "yellow", "blue", "orange", "green", "purple"]for x in range(100):
t.pencolor(colors[x%sides])
t.forward(x * 3/sides + x)
t.left(360/sides + 1)
t.width(x*sides/200)
t._tracer(True)done()
03
彩色炫酷图
import turtle
t = turtle.Pen()
turtle.bgcolor("black")
sides=6
colors=["red","yellow","green","blue","orange","purple"]for x in range(360):
t.pencolor(colors[x%sides])
t.forward(x*3/sides+x)
t.left(360/sides+1)
t.width(x*sides/180)
t.left(91)
END