Monday, January 9, 2023

Learner_Code

 I'm at it again: taking inspiration from eisting code in trying to

develop new things. I've been looking for a cute tree done with turtle

but all I can find is all-too-clever fractal figures. So I.ve been tryibg

to develop a simple tree shape with nice leaves.Something of a 

challenge, it turns out. Real leavea look the way they do because they

have three dimensions. A two-dimensional leaf is a methematical puzzle.


Long story short, I am trying to adapt  Christmas tree codde go do the job.

                                                            


https://pythondex.com/draw-christmas-tree-in-python

from turtle import *
speed(0)
# Tree Trunk
penup()
goto(-10, -200)
pendown()
color("brown")
begin_fill()
for i in range(2):
forward(20)
right(90)
forward(20)
right(90)
end_fill()

# Set the start position and the inital tree width
y = -200
width = 16
height = 25
#Green section 1
while width <=240 :
width = width + 32 # Make the tree get smaller as it goes up in height
x = 0 - width / 2 # Set the starting x-value of each level of the tree
color("green")
penup()
goto(x, y)
pendown()
begin_fill()
for i in range(2):
forward(width)
left(90)
forward(height)
left(90)
end_fill()

y = y + height # Keep drawing the levels of the tree higher than the previous

# Green section 2
while width > 20:
width = width - 32 # Make the tree get smaller as it goes up in height
x = 0 - width / 2 # Set the starting x-value of each level of the tree
color("green")
penup()
goto(x, y)
pendown()
begin_fill()
for i in range(2):
forward(width)
left(90)
forward(height)
left(90)
end_fill()

y = y + height # Keep drawing the levels of the tree higher than the previous

hideturtle()
done()

                                                               

No comments: