Task 2 – CDDC Code

# Lesson I've learned from this task: 
# I play around with the coordinate to find the right shape, rotation angle and position for each letter.
# I'm struggling to make the curve version for the letter C and D into the CDDC position originally due to the angle rotation for each letter C and D, one version is curved line and the second version is straight line. 
# I find the straight line version is easier to draw CDDC format because the straight line doesn't need to rotate the angle (maybe I just don't know how to rotate it correctly).
# But then after speaking to Mina, he advised to always bring back the turtle position to home and now it works perfectly for the curved CDDC.
# I reduce the x coordinate by 0.25 to give a space in between letter to make it looks nicer and to fit within the paper bounds.
 
import axi
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 straight_C(turtle, x, y):
    # function to draw the letter 'C' starting at a specific starting point (x,y)
    turtle.pu() #pen up
    turtle.goto(x+2.75, y+1) # go to point (x+2.75, y+1)
    turtle.pd() # pen down
    turtle.goto(x+2, y) # go to point (x+2, y)
    turtle.goto(x+1, y) # go to point (x+1, y)
    turtle.goto(x, y+1) # go to point (x, y+1)
    turtle.goto(x, y+4) # go to point (x, y+4)
    turtle.goto(x+1, y+5) # go to point (x+1, y+5)
    turtle.goto(x+2, y+5) # go to point (x+2, y+5)
    turtle.goto(x+2.75, y+4) # go to point (x+2.75, y+4)
    turtle.pu() #pen up
    turtle.home() # bring back the turtle to home position

def straight_D(turtle, x, y):
    # function to draw the letter 'D' starting at a specific starting point (x,y)
    turtle.goto(x, y) # go to point (x, y)
    turtle.pd() #pen down
    turtle.goto(x, y+5) # go to point (x, y+5)
    turtle.goto(x+2, y+5) # go to point (x+2, y+5)
    turtle.goto(x+2.75, y+4) # go to point (x+2.75, y+4)
    turtle.goto(x+2.75, y+1) # go to point (x+2.75, y+1)
    turtle.goto(x+2, y) # go to point (x+2, y)
    turtle.goto(x, y) # go to point (x, y)
    turtle.pu() #pen up  
    turtle.home() # bring back the turtle to home position 

def curve_C(turtle, x, y): #round curve C instruction
    turtle.pu() #pen up
    turtle.goto(x+2.75, y+1) # go to point (x+2.75, y+1)
    turtle.pd() # pen down
    turtle.right(90) # rotate 90° to the right 
    r = 1 # radius for the curve quarter circle of C
    turtle.circle(r, -90, 10) # draw a circular shape with radius r and covering -90° (quarter circle) constituted of 10 lines
    turtle.goto(x+1, y) # go to point (x+1, y)
    r = 1 # radius for the curve quarter circle of C
    turtle.circle(r, -90, 10) # draw a circular shape with radius r and covering -90° (quarter circle) constituted of 10 lines
    turtle.goto(x, y+4) # go to point (x, y+4)
    r = 1 # radius for the curve quarter circle of C
    turtle.circle(r, -90, 10) # draw a circular shape with radius r and covering -90° (quarter circle) constituted of 10 lines
    turtle.goto(x+1.75, y+5) # go to point (x+1.75, y+5)
    r = 1 # radius for the curve quarter circle of C
    turtle.circle(r, -90, 10) # draw a circular shape with radius r and covering -90° (quarter circle) constituted of 10 lines
    turtle.pu()  #pen up
    turtle.home() # bring back the turtle to home position

def curve_D(turtle, x, y): #round curve D instruction
    turtle.pu() #pen up
    turtle.goto(x, y)
    turtle.pd()
    turtle.goto(x, y+5) # go to point (x, y+5)
    turtle.goto(x+1.75, y+5) # go to point (x+1.75, y+5)
    turtle.right(180) # rotate 180° to the right 
    r = 1 # radius for the curve quarter circle of D
    turtle.circle(r, -90, 10) # draw a circular shape with radius r and covering -90° (quarter circle) constituted of 10 lines
    turtle.goto(x+2.75, y+1) # go to point (x+2.75, y+1)
    r = 1 # radius for the curve quarter circle of D
    turtle.circle(r, -90, 10) # draw a circular shape with radius r and covering -90° (quarter circle) constituted of 10 lines
    turtle.goto(x, y) # go to point (x, 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()
    # straight_C(turtle, 0,0)
    # straight_D(turtle, 3,0)
    # straight_D(turtle, 6,0)
    # straight_C(turtle, 9,0)
    # remove the # to print out the straight version for letters "CDDC"
    curve_C(turtle, 0,0)
    curve_D(turtle, 3,0)
    curve_D(turtle, 6,0)
    curve_C(turtle, 9,0)
    # remove the # to print out the curve version for letters "CDDC"
    
    output_img = 'Task2_CDDC_curve'
    save_img(turtle, output_img)
    # draw_img(turtle) # Uncomment to draw your image
    
if __name__ == '__main__':
    main()