Pookkalam by Sreeraj Rajeendran

Code

import math

yellow = "#ffef00"
violet = "#9932CC"
white_green = "#d7edc1"
dark_brown = "#654321"
orange="#ffa500"
dark_green = "#013220"
green = "#2fa34a"
red = "#e30800"
maroon = "#670000"
blue = "#1c67bd"

def clear():
    return rectangle(w=300, h=300, fill="gray")

def layer1():
    c = circle(r=150, fill=white_green, stroke="none")
    return c
    
def layer2():
    return circle(r=145, fill=dark_green, stroke="none")

def layer3():
    c = circle(r=140, fill=yellow, stroke="none")
    shape = rectangle(w=197, h=197, fill=violet, stroke="none") | repeat(9, rotate(10))
    shape = combine([c, shape])
    return shape

def layer4():
    return circle(r=120, fill="none", stroke=green, stroke_width=20)

def layer5():
    return circle(r=110, fill="none", stroke=red, stroke_width=12)
    
def layer6():
    return circle(r=102, fill="none", stroke=orange, stroke_width=5)

def layer7():
    # r1 = rectangle(w=140, h=140, fill="#703d55", stroke="none") | repeat(9, rotate(10))
    # r2 = rectangle(w=125, h=125, fill="#a64672", stroke="none") | rotate(5) | repeat(9, rotate(10))
    # r3 = rectangle(w=110, h=110, fill="#e3bacd", stroke="none") | repeat(9, rotate(10))
    # r4 = rectangle(w=95, h=95, fill="#eddfe6", stroke="none") | rotate(5) | repeat(9, rotate(10))
    
    # c = circle(r=102, fill="#591333", stroke="none")
    c = circle(r=102, fill=dark_green, stroke="none")
    # shape = combine([c, r1, r2, r3, r4])
    shape = c
    return shape

def triangle(p1, p2, p3, color, stroke, stroke_width):
    p = polygon([p1, p2, p3], fill=color, stroke=stroke, stroke_width=stroke_width)
    return p

def layer8():
    p1 = point(x=-50, y=0)
    p2 = point(x=50, y=0)
    p3 = point(x=0, y=90)
    color = yellow
    t1 = triangle(p1, p2, p3, color=color, stroke="none", stroke_width=0)
    t1 = t1 | repeat(4, rotate(90))
    
    color = maroon
    t2 = triangle(p1, p2, p3, color=color, stroke="none", stroke_width=0)
    t2 = t2 | scale(0.47)
    t2 = t2 | translate(y=30)
    t2 = t2 | repeat(4, rotate(90))
    
    shape = combine([t1, t2])
    shape = shape | scale(1.4)
    return shape

def layer9():
    c0 = circle(x=-30, y=30, r=35, fill="#f56cae", stroke="none") 
    c1 = circle(x=-30, y=30, r=30, fill=yellow, stroke="none")
    c2 = circle(x=-30, y=30, r=25, fill=orange, stroke="none")
    c3 = circle(x=-30, y=30, r=7, fill=violet, stroke="none")

    c = combine([c0, c1, c2, c3])
    shape = c | repeat(4, rotate(90))
    
    shape = combine([shape, c])
    return shape

def layer10():
    r = rectangle(w=60, h=60, fill=blue, stroke="none")
    shape1 = r
    
    p1 = point(x=-30, y=30)
    p2 = point(x=0, y=0)
    p3 = point(x=-10, y=0)
    p4 = point(x=-30, y=20)
    p = polygon([p1, p2, p3, p4], fill=orange, stroke="none")
    shape2 = p
    
    p1 = point(x=-30, y=30)
    p2 = point(x=0, y=0)
    p3 = point(x=15, y=0)
    p = polygon([p1, p2, p3], fill="#53a352", stroke="none")
    shape2 = combine([shape2, p])
    
    p1 = point(x=-30, y=20)
    p2 = point(x=-10, y=0)
    p3 = point(x=-10, y=-10)
    p4 = point(x=-30, y=10)
    p = polygon([p1, p2, p3, p4], fill=yellow, stroke="none")
    shape2 = combine([shape2, p])
    
    shape2 = shape2 | repeat(4, rotate(90))
    
    shape1 = combine([shape1, shape2])
    
    c = circle(r=15, fill=white_green, stroke="none")
    shape1 = combine([shape1, c])
    
    c = circle(r=5, fill="#594721", stroke="none")
    e = ellipse(w=20, h=3, fill=yellow, stroke="none") | repeat(10, rotate(20))
    shape = combine([shape1, e, c])
    return shape

def binCoeff(n):
    coeff = []
    for k in range(n+1):
        coeff += [1]

        for j in range(k+1, n+1):
            coeff[k] *= j
        for j in range(1, n-k+1):
            coeff[k] /= j

    return coeff


def getBezierPoints(u, n, coeff, cntrlPts):
    x, y = 0.0, 0.0

    for k in range(n):
        bezBlendFn = coeff[k] * math.pow(u, k) * math.pow(1-u, n-1-k)
        x += cntrlPts[k][0] * bezBlendFn
        y += cntrlPts[k][1] * bezBlendFn

    return x, y


def bezier(n, cntrlPts, nBezier):
    coeff = binCoeff(n-1)
    points = []
    # print(len(coeff))
    # print(coeff)

    for k in range(nBezier):
        u = float(k/nBezier)
        x, y = getBezierPoints(u, n, coeff, cntrlPts)
        points.append([x, y])
        
    return points

def layer11():
    n = 5
    cntrlPts = [
        [-30,-5],
        [-120,10],
        [-30,150],
        [10,10],
        [75,60]
    ]
    nBezier = 1000
    points = bezier(n, cntrlPts, nBezier)
    c = []
    
    r1, g1, b1 = 153, 50, 204
    r2, g2, b2 = 204, 67, 131

    rInc = (r2-r1)/500
    gInc = (g2-g1)/500
    bInc = (b2-b1)/500
    
    r, g, b = r1, g1, b1
    rad = 2
    radInc = (6-2)/1000
    for i in range(len(points)):
        # r, g, b = int(r), int(g), int(b)
        col = color(r=r, g=g, b=b)
        x, y = points[i][0], points[i][1]
        c.append(circle(x=x, y=y, r=rad, fill=col, stroke="none"))
        
        r += rInc
        g += gInc
        b += bInc
        rad += radInc
        
        if i == 800:
            rInc = (r2-r1)/200
            gInc = (g2-g1)/200
            bInc = (b2-b1)/200
            rInc *= -1
            gInc *= -1
            bInc *= -1
        
    shape = combine([i for i in c])
    shape = shape | repeat(4, rotate(90))
    
    return shape

show(clear())
s1 = layer1()
s2 = layer2()
s3 = layer3()
s4 = layer4()
s5 = layer5()
s6 = layer6()
s7 = layer7()
s8 = layer8()
s9 = layer9()
s10 = layer10()
s11 = layer11()

s = combine([s1, s2, s3, s7, s8, s4, s9, s11, s5, s6, s10])
show(s)