Python Zelle Graphics - Recursive functions in drawing?
Question: ![the goal](http://web.cs.swarthmore.edu/~grace/cs21/f14/labs/09/diamonds.jpg)

![enter image description here](http://i.stack.imgur.com/ZMMaD.png)

    
    
    import graphics
    def main():
        window = graphics.GraphWin("x", 600, 400)
        cntr = graphics.Point(300,200)
        size = 200
        wrapdiamond(size, window,cntr)
        window.getMouse()
    def wrapdiamond(size, window,cntr):
        count = 0
        if count == 4:
            return
        if count < 4:
            diamond(size,window,"black", cntr)
            x= cntr.getX()+-0.5*size
            y = cntr.getY()+-0.5*size
            cntr= graphics.Point(x,y)
            size = size*0.33
            count +=1
            diamond(size,window,"black", cntr)
    
    def diamond(size,window,color,cntr):
        p1 = cntr.clone()
        p1.move(0,-0.5*size)
        x1 = p1.getY()
        newcntr = graphics.Point(300,x1)
        p2 = cntr.clone()
        p2.move(-0.5*size,0)
        p3 = cntr.clone()
        p3.move(0,0.5*size)
        p4 = cntr.clone()
        p4.move(0.5*size,0)
        diamond= graphics.Polygon(p1, p2, p3, p4)
        diamond.setFill("black")
        diamond.draw(window)
    

So the top picture is my goal. I need to do this recursively (calling the same
function), shifting the center point, size, and color. I feel like my current
method is very likely to have me hardcoding much of this. How would I
implement this recursively?


Answer: If you're stuck with recursion, this could get you started again

    
    
    def rdraw(x,y,level=1,max_level=5):
        draw_diamond(level)
        d = distance(level)
        if (level+1)<=max_level:
            rdraw(x+d,y+d,level+1)
            rdraw(x+y,y-d,level+1)
            rdraw(x-y,y+d,level+1)
            rdraw(x-y,y-d,level+1)
    
    rdraw(0,0)
    

