Home > Blockchain >  How can I rotate a shape from the bottom in turtle
How can I rotate a shape from the bottom in turtle

Time:04-19

I am trying to make a turtle analog clock, and to make the second, minute, an hour hands I am making a shape with turtle, and using .tilt() to tilt it 6 degrees every second. The thing is, when I run .tilt() it rotates the ship from the middle, whereas I want to have it rotate from the bottom point (like an analog clock). Is there a way to do that, or do I need to find another way to make this program?

Here is my code:

from turtle import *
import time

turtle = Turtle()
turtle.shape("square")
turtle.shapesize(6, .1)

tilt_amnt = 0

for x in range (60):
    turtle.tilt(tilt_amnt)
    tilt_amnt = tilt_amnt   6
    time.sleep(1)

CodePudding user response:

I don't think there is a way to tilt the turtle in such a way where it turns from the bottom but you can rewrite the code to essentially do the same thing but using forward instead. Check this out.

from turtle import *
import time

turtle = Turtle()
turtle.pensize(2)
turtle.hideturtle()
turtle.speed(0)

tilt_amnt = 0

for x in range (60):
    turtle.right(tilt_amnt)
    turtle.forward(100)
    turtle.backward(100)
    tilt_amnt = tilt_amnt   6
    time.sleep(1)
    turtle.clear()
  • Related