Task 4 Art – Love Code

# Lesson I've learned from this task: 
# Continued from Task4_Art, I tried to simplify it by calling each shape for certain coordinates that I defined.
# Matt has kindly explained to me the new function and concept of coordinates and arrays for the loops positioning.
# Mina also helped me to simplify the codes and logics from Matt. 
# I also challenged myslef again by adding a new shape (love heart) into my letter M.
# The picture output is perfect but unfortunately when I tried to print it out on Harry the Plotter, for some reason it didn't come out nice at all.
# The size/scale and position were not as what I expected. So I didn't submit this design, but I will try to fix and print it for hand in submission.


import axi
import turtle
A4_PORT = (0, 0, 8.25, 11.75) # A4 Portrait bounds
A4_LAND = (0, 0, 11.75, 8.25) # A4 Landscape bounds
BOUNDS = A4_PORT

def draw_circle(turtle, x, y):
    turtle.pu() # pen up
    turtle.goto(x,y) # go to point (x, y)
    turtle.pd() # pen down
    angle = 51 # I add 1 to make the circle rotate slightly bigger to diferent angle for each loop
    for i in range(70):
        turtle.circle(i)
        turtle.right(angle)
        
def draw_pentagon(turtle, x, y):
    turtle.pu() # pen up
    turtle.goto(x,y) # go to point (x, y)
    turtle.pd() # pen down
    angle = 71 # I add 1 to make the pentagon rotate slightly bigger to diferent angle for each loop
    for i in range(150):
        turtle.forward(i)
        turtle.right(angle) 
        
def draw_love(turtle, x, y):
    turtle.pu() # pen up
    turtle.goto(x+150, y) # go to point (x+150, y)
    turtle.pd() # pen down
    turtle.goto(x, y+150) # go to point (x, y+150)
    turtle.left(90) # rotate 90° to the left 
    r = 75 # radius for the curve on the love heart shape
    turtle.circle(r, 210, 100) # draw a circular shape with radius r and covering 210° constituted of 100 lines
    turtle.left(180) # rotate 180° to the left 
    r = 75 # radius for the curve on the love heart shape
    turtle.circle(r, 210, 100) # draw a circular shape with radius r and covering 210° constituted of 100 lines
    turtle.goto(x+150, y) # go to point (x+150, y)
    turtle.pu() # pen up
    turtle.home() # bring back the turtle to home position
       
           
def save_img(turtle, name = 'out'):
    drawing = turtle.drawing.rotate_and_scale_to_fit(BOUNDS[2], BOUNDS[3], step=90, padding=0.5) # scale letter to fit A4-sized paper
    im = drawing.render(bounds=BOUNDS) # render drawing
    im.write_to_png(name + '.png') # save a image of your drawing in a file called name.png
    
def draw_img(turtle):
    drawing = turtle.drawing.rotate_and_scale_to_fit(BOUNDS[2], BOUNDS[3], step=90, padding=0.5) # scale letter to fit A4-sized paper
    axi.draw(drawing)

def main():
    turtle = axi.Turtle()   
    # circle coordinates
    coord_c = [(300, -400), (0, -400), (-300, -400), (-150, -150),  (-150, 150), (-300, 400),  (0, 400), (300, 400)]
    # pentagon coordinates
    coord_p = [(600, -400), (-600, -400), (-600, 400), (600, 400)]
    # love coordinates 
    coord_l = [(150, 0)]
    
    # call circle function
    for a in range(len(coord_c)): # len is length of the coord_c which has 8 set of (x,y) coordinates
        arrays_1 = coord_c[a] # arrays for the circle coordinates consist of 2 options only: 0 for x and 1 for y
        # print(arrays)
        x = arrays_1[0] # if arrays is 0 then it's the x coordinate
        y = arrays_1[1] # if arrays is 1 then it's the y coordinate
        draw_circle(turtle, x, y)

    """ This is another way of using 2 for loops function (but too long and a bit confusing :)
    for b in range(len(arrays)):
        # print(arrays[b])
        if b==0:
            x= arrays[b]
            y= arrays[b+1]
        else:
            x = arrays[b-1]
            y = arrays[b]    
    """            
        
    # call pentagon function
    for b in range(len(coord_p)): # len is length of the coord_p which has 4 set of (x,y) coordinates
        arrays_2 = coord_p[b] # arrays for the pentagon coordinates consist of 2 options only: 0 for x and 1 for y
        x = arrays_2[0] # if arrays is 0 then it's the x coordinate
        y = arrays_2[1] # if arrays is 1 then it's the y coordinate
        draw_pentagon(turtle, x, y)

    """# call love function (This is unfortunately not working)
    for c in range(len(coord_l)):
        arrays_3 = coord_l[c]
        x = arrays_3[0]
        y = arrays_3[1]
        # print (y)  
    """  
    draw_love(turtle, 150, 0) 
    
       
    output_img = 'Task4_Love'
    save_img(turtle, output_img)
    # draw_img(turtle) # Uncomment to draw your image

     
if __name__ == '__main__':
    main()