# Lesson I've learned from this task:
# I applied the for loops functions to create the repetition for forward and right/left functions which will change over certain range that I defined.
# By changing the angle each time for the ange of loops, this apparently will create different shape, e.g: 90' angle will create a square and 70' angle will create a pentagon shape.
# I also tried the circle function and modified the angle to create a beautiful circle of flower.
# I could stop here, but then I like to challenge myself to create a letter M using combination of these for loops shapes.
# So I draw and position each shape in certain coordinates to create a letter M.
# The position for each loop is listed manually because I didn't know what function to simplify it (yet).
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_LAND
def draw_square(turtle, x, y):
turtle.pu() # pen up
turtle.goto(x,y) # go to point (0,0)
turtle.pd() # pen down
angle = 91 # I add 1 to make the square (90') rotate slightly bigger to diferent angle for each loop
for i in range(100):
turtle.forward(i)
turtle.left(angle)
def draw_circle(turtle, x, y):
turtle.pu() # pen up
turtle.goto(x,y) # go to point (0,0)
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 (0,0)
turtle.pd() # pen down
angle = 71 # I add 1 to make the pentagon (70') rotate slightly bigger to diferent angle for each loop
for i in range(150):
turtle.forward(i)
turtle.right(angle)
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()
draw_circle(turtle, 150, 300)
draw_circle(turtle, 0, 300)
draw_circle(turtle, -150, 300)
draw_circle(turtle, -150, 120)
draw_circle(turtle, 0, 0)
draw_circle(turtle, -150, -120)
draw_circle(turtle, -150, -300)
draw_circle(turtle, 0, -300)
draw_circle(turtle, 150, -300)
draw_pentagon(turtle, 350, 300)
draw_pentagon(turtle, 350, -300)
draw_pentagon(turtle, -350, -300)
draw_pentagon(turtle, -350, 300)
# draw_square(turtle, 350, 600)
# draw_square(turtle, 350, -600)
output_img = 'Task4_Art'
save_img(turtle, output_img)
# draw_img(turtle) # Uncomment to draw your image
if __name__ == '__main__':
main()