绘图之前先要安装turtle模块:
python 2:
pip install turtle
python 3:
pip3 install turtle
绘图思路:
首先绘制出外正方形和内线,然后使用dot绘制出九个跑位的点,记录每个点的x和y轴,写入死循环和if判断条件判断是否为中圆点并闪烁。
效果图展示:
效果图代码:
import turtle
import time
import random
turtle.title("woshinsy python homework")
turtle.bgcolor("#367847")
def bcir():
turtle.dot(65,"yellow")
def cir():
turtle.dot(45, "white")
def tp(x,y):
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
def square():
turtle.color("white")
for i in range(4):
turtle.pensize(10)
turtle.forward(500)
turtle.left(90)
turtle.speed(9)
turtle.hideturtle()
tp(-250,-250)
square()
tp(-250,125)
turtle.forward(500)
tp(0,120)
turtle.left(-90)
turtle.forward(370)
tp(0,0)
bcir()
tp(-250,250)
cir()
tp(0,250)
cir()
tp(250,250)
cir()
tp(-250,0)
cir()
tp(250,0)
cir()
tp(-250,-250)
cir()
tp(0,-250)
cir()
tp(250,-250)
cir()
def gogo():
arr = [[0,0],[-250,250],[0,250],[250,250],[-250,0],[250,0],[-250,-250],[0,-250],[250,-250]]
while True:
ran = random.randint(0,8)
if ran ==0:
tp(0,0)
turtle.dot(65, "red")
time.sleep(2)
turtle.undo()
else:
tp(arr[ran][0],arr[ran][1])
turtle.dot(45,"red")
time.sleep(2)
turtle.undo()
gogo()
turtle.exitonclick()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)