# The Snowflake module!!

# Local graphics module. Must be in same folder as this
# program (or both on Desktop)
import ecs10graphics as gr
# Math module that comes with Python
import math

class Snowflake(object):
    
    def __init__(self):
        self.center = [250,250]


    # beginning with __ means the method is top secret.
    def __pointOnCircle(self,f, r):
        # f is fraction of the way around
        # r is radius
        # produces a point f way around circle c,r

        # Use the global variable "center".
        c = self.center
        a = (2*math.pi)*f + math.pi/2.0
        x = c[0] + math.cos(a)*r
        y = c[1] + math.sin(a)*r
        return [x,y]

    def __circleSegment(self,f1, f2, r1, r2):
        # f1 is first fraction, r1 first radius
        # f2 is second fraction, r2 second radius
        # draws a segment from point f1, r1 to point f2, r2
        p1 = self.__pointOnCircle(f1, r1)
        p2 = self.__pointOnCircle(f2, r2)
        gr.line(p1[0], p1[1], p2[0], p2[1], lineWidth=5)
    
    # A method that can be seen from outside.
    # What used to be the main program. 
    def draw(self):
        # Start graphics window
        gr.begin_graphics(500, 500, title="Snow Flakes",
                          background = gr.Color.dark_blue)


        gr.set_Color(gr.Color.white)

        for i in range(6):
            frac = i/6.0

            # A line
            self.__circleSegment(frac+.05, frac+.05, 30, 60)
            # It's mirror image
            self.__circleSegment(frac-.05, frac-.05, 30, 60)
            
            # A line
            self.__circleSegment(frac+.05, frac, 60, 62)
            # Its mirror image
            self.__circleSegment(frac-.05, frac, 60, 62)
            
            # A line
            self.__circleSegment(frac+.05, frac+(1.0/12), 30, 30)
            # Its mirror image
            self.__circleSegment(frac-.05, frac-(1.0/12), 30, 30)



        # Display loop. 
        # Display the window, and wait for it to be closed
        alive = True
        while alive:
            alive = gr.sleep(.05)

        gr.end_graphics()






