2016-07-26 2 views
0

여유 시간에 만든 코드는 매우 간단하지만 무작위이므로 포인터는 항상 화면을 벗어날 가능성이 있습니다. 나는 아이가 스크래치를 드로잉/스프라이트에서 사용하기 전에 스크래치를 사용하는 것을 지켜 봤다. 나는 파이썬과 같은 코드를 찾고있다. 20 당신의 선택까지이다영원히 그리는 프로그램을 만들 때 어떻게 그림을 화면에 표시합니까?

from turtle import* 
from random import* 

while True: 
    forward(randint(1, 360)) 
    right(randint(1, 360)) 
+4

[벽에 반사 거북이 얻기]의 사용 가능한 복제 (http://stackoverflow.com/questions/19482196/getting-turtle-to -bounce-off-the-walls) 또는 [Python3.2 거북이 화면에서 벗어나는 방법] (http://stackoverflow.com/questions/22891134/python3-2-how-to-keep-turtle-from 화면 이동 및 해제) 또는 [TurtleGraphics Python : 거북이가 벽에서 튀어 오르는가?] (http://stackoverflow.com/questions/1457332/turtlegraphics-python-bouncing- 벽 거북이) – TessellatingHeckler

답변

0
from turtle import * 
from random import* 

while True: 
    forward(randint(1, 360)) 
    right(randint(1, 360)) 
    if xcor() < 0: 
     setx(20) 
    if ycor() < 0: 
     sety(20) 
    if xcor() > window_width(): 
     setx(window_width()-20) 
    if ycor() > window_height(): 
     sety(window_height()-20) 

는 작동합니다.

편집 : 중복 게시물 중 하나의 솔루션은 아마 더 나은

관련 문제