#!/usr/bin/python3
import turtle
import matplotlib.pyplot as plt
from math import sin, cos, asin, pi

zoom=1
n=1.33
steps=50

angles=[]

turtle.Screen().setup(500,500)
turtle.setworldcoordinates(-1-zoom,-1-zoom,1.5,1.5)
turtle.speed(0)
turtle.radians()
turtle.hideturtle()

turtle.penup()
turtle.goto(0,-1)
turtle.pendown()
turtle.circle(1,steps=100)
turtle.penup()


for x in range(1,steps):
    x=x/steps
    theta=asin(x)
    phi=asin(x/n)

    turtle.goto(-1-zoom,x)
    turtle.setheading(pi/2)
    turtle.pendown()
    turtle.forward(zoom+1-cos(theta))
    
    turtle.right(theta-phi)
    turtle.forward(2*cos(phi))

    turtle.right(pi-2*phi)
    turtle.forward(2*cos(phi))

    turtle.right(theta-phi)
    turtle.forward(zoom)
    turtle.penup()

    print(x,180*(4*phi-2*theta)/pi)
    angles.append(180*(4*phi-2*theta)/pi)


plt.hist(angles)
plt.show()
    
input('Press ENTER to close window')
