Created
November 10, 2015 15:50
-
-
Save HotelCalifornia/d34fe5102244325f1fbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from turtle import * | |
import random as r | |
RADIUS = 50 | |
# visual of the circle | |
c = Turtle() | |
c.penup() | |
c.setpos(c.pos()[0], c.pos()[1]-RADIUS) | |
c.pendown() | |
c.color('blue') | |
c.circle(RADIUS) | |
# particle | |
t = Turtle() | |
t.color('red') | |
# main loop | |
count = 0 | |
while True: | |
t.forward(5) | |
if r.randint(0, 1) == 0: | |
t.left(r.randint(0, 100)) | |
else: | |
t.right(r.randint(0, 100)) | |
if abs(t.pos()[0]) >= RADIUS or abs(t.pos()[1]) >= RADIUS: | |
break | |
count += 1 | |
done() | |
# print out the number of moves the particle made | |
print str(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment