My turtle

Simple Christmas Tree

 

Task: Build Christmas Tree


Code:

from turtle import *
from math import sqrt
bgcolor("light blue")
def tree (c,s):
    def triangle (c):
        color('green')
        b=sqrt(2*c*c)
        begin_fill()
        setheading(315)
        forward(c)
        setheading(180)
        forward(b)
        setheading(45)
        forward(c)
        end_fill()

    for i in range (s):
        c=c*3/2 #enlarge the next triangle by a factor of 3/2
        triangle(c)
        setheading(270)
        forward(c/3) #descend for c/3

tree(15,5) #c — leg of the triangle, S — number of cycles
hideturtle()
done()

2026-07-09 07:56:44

Comments

No comments yet. Be the first to leave one!

Leave a Comment