# This function initializes a RubyLabs Canvas, colors it color, and
# then calls the recursive function sierpinski to do all the work
def start_sierpinski(size, color)
   size = size.round()
   Canvas.init(size+2, size+2, "SierpinskisTriangle")
   Canvas::Rectangle.new(1, 1, size+1, size+1,
                        :width => 0, :fill => color)
   sierpinski(0, 0, size)
end

# draw a Sierpinski triangle with top left at (x,y) and 
# with height and width of size
def sierpinski(x, y, size)
   # stop when the size gets smaller than 2 (since we can't subdivide a pixel)
   return if size < 2

   half = size / 2.0
   draw_topleft_square(x,y,half)

   # recursively repeat the sierpinski triangle 
   # for each of the other three quadrants
   sierpinski( , , )  # Fill in the missing parameters of this call!
   sierpinski( , , )  # Fill in the missing parameters of this call!
   sierpinski( , , )  # Fill in the missing parameters of this call!
end

def draw_topleft_square(x,y,half)
   # draw a white square in the upper left quadrant
   Canvas::Rectangle.new(1 + x,
                         1 + y,
                         1 + x + half,
                         1 + y + half,
                         :width => 0, :fill => "white")
end
