Pookkalam by Reyes Joe

Code

"""Code-a-Pookalam Contest - by Tinkerhub & Manglish Keyboard in collab with mon.school"""

""" pookalam """

# user-defined Functios

def diamond(x, y, h, w, fill, stroke='none', stroke_width=1):
    p1 = point(x=x-(w/2), y=y) # left point
    p2 = point(x=x, y=y-(h/2)) # bottom point
    p3 = point(x=x+(w/2), y=y) # right point
    p4 = point(x=x, y=y+(h/2))
    shape = polygon([p1, p2, p3, p4], fill=fill, stroke=stroke, stroke_width=stroke_width)
    return shape

def triangle(p1, p2, p3, fill, stroke='none', stroke_width=1):
    p1 = point(x=p1[0], y=p1[1])
    p2 = point(x=p2[0], y=p2[1])
    p3 = point(x=p3[0], y=p3[1])
    return polygon([p1, p2, p3], fill=fill, stroke=stroke, stroke_width=stroke_width)

def angleshadow(p1, p2, h, fill, stroke='none'):
    p_1 = point(x=p1[0], y=p1[1])
    p_2 = point(x=p2[0], y=p2[1])
    p1_y = point(x=p1[0], y=p1[1] + h)
    p2_y = point(x=p2[0], y=p2[1] + h)

    return polygon([p_1, p1_y, p2_y, p_2], fill=fill, stroke='none')

def square(l, fill, x=0, y=0, stroke_width=1, stroke='black'):
    return rectangle(x=x, y=y, h=l, w=l, fill=fill, stroke_width=stroke_width, stroke=stroke)

def petallise(p, r, fill, stroke):
    pos = 0
    num = 1
    petals = []
    for n in range(r):
        for x in range(num):
            # clr = color(r=255, g=0, b=0)
            shape = triangle((-26, p - 32), (0, p), (26, p-32), fill=fill, stroke=stroke, stroke_width=2) | rotate(pos) | repeat(4, rotate(90))
            petals.append(shape)
            pos -= 6.25
        p -= 6.75
        pos = 3.10 * num
        num += 1
    return combine(petals)

# implementation

circle_1 = circle(r=5, fill='white', stroke='none')  # the small circle in the middle
middle_petal_lines = line(x1=0, y1=0, x2=0, y2=15, stroke='white') | repeat(8, rotate(45))  # the white rays from the middle

diamond_petals_1 = diamond(x=0, y=20, h=40, w=20, fill='purple', stroke='white') | repeat(8, rotate(45))
diamond_petals_2 = diamond(x=0, y=20, h=45, w=30, fill='white', stroke='red', stroke_width=2) | rotate(22.5) | repeat(8, rotate(45))
diamond_petals_3 = diamond(x=0, y=25, h=45, w=35, fill='orange', stroke='darkred', stroke_width=2) | repeat(8, rotate(45))

petals_1 = ellipse(w=50, h=100, fill='#ff75ca', stroke='green', stroke_width=3) | repeat(8, rotate(45))

petals_2 = ellipse(w=50, h=125, fill='purple', stroke='orange', stroke_width=0) | repeat(16, rotate(22.5))
petal_lines_1 = line(x1=0, y1=59, x2=0, y2=40, stroke='white', stroke_width=3) | rotate(11.25) | repeat(16, rotate(22.5))
petal_lines_2 = line(x1=0, y1=67.5, x2=0, y2=40, stroke='yellow', stroke_width=2) | repeat(16, rotate(22.5))

circle_2 = circle(r=65, fill='orange', stroke='red', stroke_width=5)

triangular_petal = triangle((-10, 63), (0, 75), (10, 63), fill='white', stroke_width=5) | rotate(10)
triangular_petals = triangular_petal | repeat(72, rotate(5))

dark_shadow_1 = angleshadow((-16, 63), (0, 72), 20, fill='purple') | rotate(10)
dark_shadows_1 = dark_shadow_1 | repeat(36, rotate(10))

dark_shadow_2 = angleshadow((16, 60), (0, 72), 20, fill='orange') | rotate(10)
dark_shadows_2 = dark_shadow_2 | repeat(36, rotate(10))

shadow_lines = line(x1=0, y1=75, x2=-15.5, y2=82.5, stroke='purple', stroke_width=2) | repeat(36, rotate(10))
circle_3 = circle(r=95, fill='yellow', stroke='red', stroke_width=4)


layers = []
pos = 10
middle_p = 144
colors = ('#fdff99', 'yellow', 'orange', 'red', '#550000')

for i in colors:  # setting up the outer layers of petals
    
    shape = triangle((-50, middle_p - 50), (0, middle_p), (50, middle_p-50), fill=i, stroke='none') | rotate(pos) | repeat(36, rotate(10))
    layers.append(shape)
    pos = 10 if pos == 5 else 5
    middle_p -= 10  # the distance of each layer

outer_layers = combine(layers)
circle_4 = circle(r=149, fill='black', stroke='none')

# rendering the shapes
show(circle_4, outer_layers, circle_3, dark_shadows_1, dark_shadows_2, shadow_lines, triangular_petals, circle_2, petals_2, petal_lines_2, petal_lines_1, petals_1, diamond_petals_3, diamond_petals_2, diamond_petals_1, circle_1, middle_petal_lines)

"""
by,
Reyes Joe Roshan (16)
Kasargod, Kerala
"""