Trying to scale/change orientation a Turtle image in Python

37 Views Asked by At

I have made an image of a bee using Turtle in Python. In an ideal world, I would like to know how to scale the size of the bee, while simulatenously keeping all of the dimensions in proportion. I would also like to know how I can easily change the orientation of this image.

I'm rather new to coding, so I'm still very much in a learning stage. I know there's probably a very obvious answer that I'm just not making the connection with. Any help would be hugely appreciated.

def visualise_data(rename_me_in_task_1b):
def draw_body(x, y, step):
# Body outline
    penup()
    pencolor('black')
    fillcolor('gold')
    goto(x, y)
    pendown()
    begin_fill()
    setheading(90)
    circle((step * 5), 180)
    forward(step * 10)
    circle((step * 5), 180)
    forward(step * 10)
    end_fill()
# Draw Stripe 1
    fillcolor('black')
    begin_fill()
    setheading(180)
    forward(step * 10)
    setheading(270)
    forward(step * 4)
    setheading(0)
    forward(step * 10)
    setheading(90)
    forward(step * 4)
    end_fill()
# Goto Stripe 2
    penup()
    setheading(180)
    forward(step * 10)
    setheading(270)
    forward(step * 6)
# Draw Stripe 2
    setheading(0)
    pendown()
    begin_fill()
    forward(step * 10)
    setheading(270)
    forward(step * 4)
    setheading(180)
    forward(step * 10)
    setheading(90)
    forward(step * 4)
    end_fill()
    penup()
# Draw stinger
    goto((x - 50), (y - (step * 15)))
    setheading(270)
    pendown()
    width(5)
    forward(step)
    penup()
    width(3)
# Draw right wing
    goto(x, (y * 0.66))
    setheading(25)
    fillcolor('gainsboro')
    pendown()
    begin_fill()
    forward(step * 5)
    circle((-step * 3.5), 180)
    goto(x, (-y * 0.66))
    goto(x, (y * 0.66))
    end_fill()
    penup()
# Draw left wing
    goto(-x, (y * 0.66))
    setheading(155)
    pendown()
    begin_fill()
    forward(step * 5)
    circle((step * 3.5), 180)
    goto(-x, (-y * 0.66))
    end_fill()

def draw_head(x, y, step):
# Head outline
    width(3)
    pencolor('black')
    fillcolor('gold')
    penup()
    goto((x - 50), (y * 1.5))
    pendown()
    begin_fill()
    setheading(0)
    circle((step * 6), 360)
    end_fill()
    penup()
# Eyes
    goto((x * 0.5), (y * (step * 0.275)))
    pendown()
    fillcolor('white')
    begin_fill()
    circle(step, 360)
    penup()
    goto((-x * 0.5), (y * (step * 0.275)))
    pendown()
    circle(step, 360)
    end_fill()
    penup()
# Pupils
    goto((-x * 0.5), (y * (step * 0.29)))
    pendown()
    fillcolor('black')
    begin_fill()
    circle((step * 0.3), 360)
    penup()
    forward(step * 5)
    pendown()
    circle((step * 0.3), 360)
    end_fill()
    penup()
# Mouth
    setheading(270)
    forward(step * 3)
    pendown()
    setheading(270)
    circle((-step * 2.5), 180)
    penup()
# Antennae
    goto((-x * 0.3), (y * (step * 0.36)))
    setheading(100)
    pendown()
    forward(step * 4)
    setheading(220)
    forward(step * 2)
    penup()
    goto((x * 0.3), (y * (step * 0.36)))
    setheading(80)
    pendown()
    forward(step * 4)
    setheading(320)
    forward(step * 2)
    penup()
    speed(0)
    width(3)

title('The Australian Honey Bees-nest/Business')


def draw_main_body(x, y, step):
    draw_body(x, y, step)
    draw_head(x, y, step)


write("Australia's Honey production is abundant!", move=True, align='left',
font=("Arial", 8, "bold"))


    draw_main_body(50, 50, 10)
    hideturtle()
    done()
    mainloop()
1

There are 1 best solutions below

1
cdlane On

Along with @ggorlen's usual excellent advice (+1), you have to also avoid commands like setheading() in favor of left() and/or right(). You also need to think about applying your scaling to things like pen width. You may also need to "undraw" (with pen up) some things to get your turtle back to a known location to continue drawing other items.

As an example, below is a rework of your draw_head() function that scales and rotates:

from turtle import Screen, Turtle

def draw_head(scale):

    # Head outline
    turtle.fillcolor('gold')
    turtle.width(scale * 0.3)
    turtle.penup()
    turtle.right(90)
    turtle.forward(scale * 6)
    turtle.left(90)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(scale * 6, 360)
    turtle.end_fill()
    turtle.penup()

    # Eyes
    turtle.fillcolor('white')
    turtle.right(90)
    turtle.backward(scale * 7)
    turtle.left(90)

    # Left Eye
    turtle.forward(scale * 2.5)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(scale, 360)
    turtle.end_fill()
    turtle.penup()

    # Right Eye
    turtle.backward(scale * 5)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(scale, 360)
    turtle.end_fill()
    turtle.penup()

    # Pupils
    turtle.fillcolor('black')
    turtle.forward(scale * 2.5)
    turtle.left(90)
    turtle.forward(scale * 0.66)
    turtle.right(90)

    # Left Pupil
    turtle.forward(scale * 2.5)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(scale * 0.3, 360)
    turtle.end_fill()
    turtle.penup()

    # Right Pupil
    turtle.backward(scale * 5)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(scale * 0.3, 360)
    turtle.end_fill()
    turtle.penup()

    # Mouth
    turtle.right(90)
    turtle.forward(scale * 3)
    turtle.pendown()
    turtle.circle(scale * 2.5, 180)
    turtle.penup()

    # Antennae
    turtle.forward(scale * 5.5)

    # Left Antenna
    turtle.right(10)
    turtle.pendown()
    turtle.forward(scale * 4)
    turtle.right(120)
    turtle.forward(scale * 2)
    turtle.penup()

    turtle.backward(scale * 2)
    turtle.left(120)
    turtle.backward(scale * 4)
    turtle.left(100)
    turtle.forward(scale * 5)
    turtle.right(90)

    # Right Antenna
    turtle.left(10)
    turtle.pendown()
    turtle.forward(scale * 4)
    turtle.left(120)
    turtle.forward(scale * 2)
    turtle.penup()

def draw_main_body(x, y, scale):
    turtle.goto(x, y)
    draw_head(scale)

screen = Screen()
screen.title('The Australian Honey Bees-nest/Business')

turtle = Turtle()
turtle.speed('fastest')

draw_main_body(0, 0, 15)

turtle.setheading(45)
draw_main_body(-200, -200, 10)

turtle.setheading(180)
draw_main_body(200, -200, 5)

turtle.hideturtle()
screen.exitonclick()

enter image description here