#*********************************************************************************
#
# Name: Peyton Capristo
# Pledge: Peyton Capristo...
#
# This program will perform a monte carlo simulation on a photon traveling 
# through the sun
#
# Inputs: mfp = mean free path of a photon in meters
#         radius_to_rz = distance away from center of the sun to the sun's 
#                        radiation zone in meters
#
# Outpus: counter = the number of steps the photon took
#         myS = Turtle screen to display the random walk
#
#*********************************************************************************


# Make an assumption that the typical mean free path of a photon is 2mm. 
# center of sun to radiation zone is 0.714 solar radii =(approx) 4.967x10^8 m 


# import libraries
import turtle 
import random as random
import math as math

# Initialize some variables 
mfp = 0.002 * 1000000000
radius_to_rz = 4.697*10**8
position_tracker = 0
x = 0
y = 0
counter = 0

# Sets up the turtle screen
myS = turtle.Screen()
myS.tracer(0)
myS.title("Random Walk") # Titles the screen
border = radius_to_rz * 1.1 #Sets up a variable for the boundary of the page
myS.setworldcoordinates(-border, -border, border, border) # Sets up the boundaries on the page itself


# Set up boundary circle
turtle.hideturtle()
turtle.speed(0)
turtle.penup()
turtle.goto(0, -4.697*10**8)
turtle.pendown()
turtle.circle(radius_to_rz)
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()

# Do the random walk
while position_tracker < radius_to_rz:
    angle = random.random()*2*math.pi   # generates a random angle 
    x = x + math.cos(angle) * mfp  # multiply by a large number so the program runs shorter than 30,000-100,000 years.
    y = y + math.sin(angle) * mfp  # multiply by a large number so the program runs shorter than 30,000-100,000 years.
    turtle.goto(x,y)   #for drawing run this, if looking for stats comment out
    position_tracker = math.sqrt(x**2 + y**2)
    
    counter += 1

# Prints the number of times the photon moved one step
print(counter)

# Updates and displays the turtle screen
myS.update()
myS.mainloop()
