Skip to content

Instantly share code, notes, and snippets.

@HotelCalifornia
Created November 10, 2015 15:50
Show Gist options
  • Save HotelCalifornia/d34fe5102244325f1fbc to your computer and use it in GitHub Desktop.
Save HotelCalifornia/d34fe5102244325f1fbc to your computer and use it in GitHub Desktop.
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