今天我在课堂上学习了如何运用Python来画出蟒蛇,蟒蛇这种生物大家都应该很熟悉吧,甚至很多人都害怕这种生物,那让我们来看看如何运用Python来画出蟒蛇这种让人害怕的生物吧。
代码如下:
#PythonDraw.py
import turtle as tl
tl.setup(950,350,300.300) #画布的大小
tl.up() #拿起笔
tl.fd(-400) #向前移动-400
tl.down() #放下笔
tl.pensize(27)
tl.pencolor("yellow")
tl.seth(-45)
for i in range(3): #运行3次循环
tl.circle(45,90) #转向角度
tl.circle(-45,90)
tl.pencolor("green")
for i in range(2):
tl.circle(45,90)
tl.circle(-45,90)
tl.pencolor("red")
tl.circle(45,90/2)
tl.fd(60)
tl.circle(16,120)
tl.pensize(50)
tl.fd(40)
tl.done() #结束
运行结果如下:
这个蟒蛇是不是看起来就没有让人那么害怕呢?你们也可以试试画出更加好看的蟒蛇。