Clone a turtle


y = t.clone()


examples/turtle/star.py
import turtle

# based on the example in the documentation

t = turtle.getturtle()
t.color('red', 'yellow')
t.begin_fill()
while True:
    t.forward(100)
    t.left(190)
    if abs(t.pos()) < 1:
        break
t.end_fill()

turtle.exitonclick()

examples/turtle/many_shapes.py
import turtle

t = turtle.getturtle()

while True:
    res = turtle.numinput("Angles?", "How many angles?", default=3, minval=3, maxval = 180)
    if res is None:
        break
    t.clear()
    print(res)
    t.circle(100, steps=int(res))

examples/turtle/numinput_select_shape.py
import turtle

t = turtle.getturtle()

res = turtle.numinput("Angles?", "How many angles?", default=3, minval=3, maxval = 180)
print(res)
t.circle(100, steps=int(res))

turtle.exitonclick()

examples/turtle/textinput_select_shape.py
import turtle

t = turtle.getturtle()

res = turtle.textinput("Shape?", "Which shape shall I draw? rectangle or triangle ?")
print(res)
if res == 'triangle':
    t.circle(100, steps=3)
elif res == 'rectangle':
    t.circle(100, steps=4)
else:
    pass
    

turtle.exitonclick()

examples/turtle/draw.py
import turtle

def screen_details():
    scr = turtle.getscreen()
    print(dir(scr))
    print(scr.screensize())
    print(scr.window_width())
    print(scr.window_height())

def draw_top_box():
    trt = turtle.getturtle()
    scr = turtle.getscreen()
    speed = trt.speed()
    print(speed)
    trt.speed(0)
    trt.penup()
    trt.setpos(20-scr.window_width()/2, scr.window_height()/2-20)
    trt.pendown()
    trt.setheading(0)
    trt.forward(scr.window_width()-40)
    trt.setheading(270)
    trt.forward(200)
    trt.setheading(180)
    trt.forward(scr.window_width()-40)
    trt.write("GitHub", font=("Arial", 30, 'normal'))
    trt.setheading(90)
    trt.forward(200)

    trt.speed(speed)

#turtle.bye()
def click(x, y):
    print('click at', x, y)
def button():
    print("button")

def main():
    trt = turtle.getturtle()
    scr = turtle.getscreen()
    scr.onclick(click)
    #scr.onkey(button,  'a')
    #scr.listen() # is needed to make the onkey settings work
    screen_details()
    draw_top_box()
    turtle.mainloop()

    #turtle.exitonclick()

main()