【发布时间】:2020-07-11 02:26:43
【问题描述】:
我正在尝试在 repli 中找到海龟屏幕的大小,以便我可以知道海龟在哪里越界。
这是我的代码:
import turtle as t
from random import randint as r
import sys
window = t.Screen()
pet = t.Turtle()
def rand_color():
red = r(0, 255)
green = r(0, 255)
blue = r(0, 255)
pet.color(red, green, blue)
def random_turtle(num_moves):
global count
while count < num_moves:
rand_color()
pet.forward(r(10, 100))
check()
pet.right(r(0, 360))
check()
count += 1
def check():
global count
x = t.xcor()
y = t.ycor()
if x > 350 or x < -350:
t.right(180)
if count > 100:
sys.stop()
else:
random_turtle(100 - count)
elif y > 330 or y < -320:
t.right(180)
if count > 100:
sys.stop()
else:
random_turtle(100 - count)
else:
random_turtle(100 - count)
如果有比找到海龟屏幕的大小并将 x 除以 2 更简单的方法,请在 cmets 中告诉我!
【问题讨论】:
-
嗨!你的问题到底是什么?请包含您的代码并指出您的问题以及您遇到的问题。
标签: python python-3.x turtle-graphics