天天看點

python turtle_使用Python的turtle畫炫酷圖形

例子一:

import 
           

效果圖如下:

python turtle_使用Python的turtle畫炫酷圖形
例子二:

可以做成互動的,利用eval函數獲得使用者想繪制的邊數

代碼:

#Python學習交流群:973783996
import turtle
t = turtle.Pen()
turtle.bgcolor("black")
sides=evali(input("輸入要繪制的邊的數目,請輸入2-6的數字!"))
colors=["red","yellow","green","blue","orange","purple"]
for x in xrange(100):
    t.pencolor(colors[x%sides])
    t.forward(x*3/sides+x)
    t.left(360/sides+1)
    t.width(x*sides/200)

print("####結束####")
           

效果:兩條邊

python turtle_使用Python的turtle畫炫酷圖形

例子三:

繪制橡皮筋球體

import turtle
#Python學習交流群:973783996
t = turtle.Pen()
turtle.bgcolor("black")
#sides=evali(input("輸入要繪制的邊的數目,請輸入2-6的數字!"))
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)
print("####結束####")
           

效果圖如下:

python turtle_使用Python的turtle畫炫酷圖形