Simple Python Turtle Graphic and Code: Simple Pampanga Lantern 1

Опубликовано: 02 Октябрь 2024
на канале: Basic Python Turtle Art
61
2

A stylized representation of the star of Bethlehem that guided the three magi to the birthplace of Jesus. Pampanga lanterns are elaborately designed with geometric shapes and variedly illuminated with electric lights to create a spectacular display of a sparkling star. They are made in Pampanga, Philippines during the Christmas season.

Feel free to copy the basic Python Turtle code that is given below. Don't hesitate to ask questions about the code if you have any. Enjoy! Please comment, like, or subscribe :)

Incidentally, for manually colorable graphics and variations, please visit my author url at https://www.amazon.com/author/basicpy...

import turtle
t = turtle.Turtle() #Definitions and Initializations
screen = turtle.Screen()
t.pensize(4)
number_of_points = 5 #Number of triangular corners for star; Preferably 5
new_point = () #Holder of tuples for point coordinates or ordered pair
list_of_points = [] #Holder of 2 ordered pairs from which side length of triangular corner is derived
radius_star = 130 #Distance from graphic center to tip of a star's triangle corner
radius_heart = 165 #Distance from graphic center to heart center
def set_of_points(): #Procedure in identifying and generating a list of 2 ordered pairs corresponding
for i in range(2): #to vertices of star's triangular corner
new_point = t.position()
list_of_points.append(new_point)
t.circle(radius_star, 360 / number_of_points)
def triangular_corners(): #Procedure in drawing the star's triangular corners, which together make a
for i in range(number_of_points): #complete star with indicated number_of_points
t.forward(triangle_side_length)
t.left(120)
t.forward(triangle_side_length)
t.right(120 - 360 / number_of_points)
def hearts(): #Procedure in drawing two overlapping hearts - the smaller over the bigger
for k in range(5):
heart_size = 98 #Size of bigger heart
for color in ("yellow", "red"): #Loop to draw bigger and smaller hearts, with indicated colors respectively
t.left(90 + k * 360 / 5)
t.forward(radius_heart)
t.right(90)
t.forward(heart_size / 2 ** 0.5)
t.left(135)
t.pendown()
t.fillcolor(color)
t.begin_fill()
for i in range(2): #Loop to draw heart portion composed of two perpendicular lines
t.forward(heart_size)
t.left(90)
for j in range(2): #Loop to draw heart portion composed of two arcs
t.right(90)
t.circle(heart_size / 2, 180)
t.end_fill()
heart_size = 0.7 * heart_size #Size of smaller heart
t.penup()
t.home()
t.left(90) #Python_graphic drawing procedure
t.penup()
t.forward(radius_star) #Trail-less movement of turtle to a vertex of star's triangular corner
t.left(90) #Preparation to generate a list of 2 ordered pairs corresponding to vertices
set_of_points() #of star's triangular corner; Function call to def set_of_points() above
t.goto(list_of_points[0])
triangle_side_length = t.distance(list_of_points[1]) #Operation to derive side length of of star's triangular corner
for color in ["green", "red", "light green"]: #Loop to draw three overlapping, differently-sized, and colored stars
t.home()
t.left(90)
t.forward(radius_star)
t.left(30 + 180 / number_of_points)
t.pendown()
t.fillcolor(color)
t.begin_fill()
triangular_corners() #Function call to draw the triangular corners of a complete star
t.end_fill()
t.penup()
radius_star = 0.5 * radius_star #Change of star size to a smaller one involving downsize of radius_star and
triangle_side_length = 0.5 * triangle_side_length #triangle_side_length
t.penup() #Preparation to draw the hearts
t.home()
hearts() #Function call to draw the overlapping hearts
t.hideturtle()
screen.exitonclick()