# Draw a sin wave 

import ecs10graphics07 as gr
import math

width = 600
height = 200

# Define graphics window
gr.begin_graphics(width,height,gr.Color.pink,"The Wave")

# Pick up purple crayon
gr.set_Color(gr.Color.purple)

pointList = []   # list of points to draw
angle = 0        # floating point variable that hold angle values

while angle < 2*math.pi:

    # Define a point for that value
    # x corresponds to angle, scaled so 2*pi is the width of window
    x = width * angle/(2*math.pi)

    # y corresponds to height, scaled so that 1 = height of window
    y = (height-20)/2 * math.sin(angle) + height/2
    
    point = [x,y]
    pointList = pointList + [point]   # Concatenate a point to the list

    # Increase the angle by a little bit each time
    angle = angle+2*math.pi/50

# Loop to draw all the points in the list
for point in pointList:

    # Draw the circle using the graphics library
    gr.circle(point[0],point[1],4,filled=True)


# Pause to allow graphics window to process commands, window
# move, window kill, all that stuff. 
# After every pause, alive will be True if the graphics window
# is still there, False after it gets killed. 
alive = True
while alive:
    alive = gr.sleep(.05)

gr.end_graphics()
