Friday, January 13, 2023

T_Shape

 Been playing with turtle shape to stamp a leaf form. Works well enough;

one needs to register the new shape with the screen. Only problem, that shape will always

be right side up ie will not bend to show a new heading...

                                                            


from turtle import*
import turtle
import time

screen = Screen()
turtle = Turtle()
screen.register_shape('T_Leaf.gif')
turtle.shape('T_Leaf.gif')
turtle.pensize(3)

def draw():
turtle.pu()
turtle.forward(100)
turtle.stamp()
turtle.left(30)
turtle.forward(100)
turtle.stamp()
time.sleep(.5)
turtle.left(90)
turtle.forward(140)

draw()
done()

                                                               *     *     *


                                                                         



from turtle import*
import turtle
import time

screen = Screen()
turtle = Turtle()
#Shapes should be registered on the screen
screen.register_shape('T_Leaf.gif')
screen.register_shape('R_Lean.gif')
screen.register_shape('L_Lean.gif')

# Brown tree
turtle.pensize(10)
turtle.color('brown')
turtle.pu()
turtle.goto(0, -140)
turtle.pd()
turtle.setheading(90)
turtle.forward(100)
turtle.right(40)
turtle.forward(40)
turtle.backward(40)
turtle.goto(0,0)

# One needs to add sleep time to get all images
def draw():
turtle.pu()
turtle.goto(20, 0)
turtle.shape('R_Lean.gif')
turtle.setheading(40)
turtle.forward(20)
turtle.stamp()
turtle.shape('T_Leaf.gif')
turtle.left(120)
turtle.forward(40)
turtle.stamp()
time.sleep(.5)
turtle.shape('L_Lean.gif')
turtle.left(95)
turtle.forward(100)

# Calling draw and keeping the window open
draw()
done()


No comments: