Pookkalam by Athul Raj K

Code

#from google.colab import files
#files.upload()

#import numpy as np
#import matplotlib.pyplot as plt
#%matplotlib inline

import joy
import math

def rhodonea(a=7,d=2,A=30):
  #y=A*cos((a/d)*theta), 0<=theta<=2*pi*d
  i=0
  theta=[]
  while i<=2*d*math.pi:
    theta.append(i)
    i+=0.01
  r=[A*math.cos((a/d)*j) for j in theta]
  x=[]
  y=[]
  for i in range(len(r)):
    x.append(r[i]*math.cos(theta[i]))
    y.append(r[i]*math.sin(theta[i]))
  #show the fig
  #plt.plot(x,y)
  p=[point(x[i],y[i]) for i in range(len(theta))]
  return p

def outer_rect(col='#ff78f1',phase_diff=0,strk='#ff78f1'):
  el_rect=(rectangle(h=20,w=20,fill=col,stroke=strk)|rotate(45)|scale(x=1.1,y=1.7))
  theta=[]
  j=0
  while j<=360:
    theta.append(j)
    j+=30
  r=90
  o_rect=line(0,0,0,0)
  for i in range(len(theta)):
    o_rect+=el_rect|rotate((30)*i+phase_diff)|translate(r*math.cos(((theta[i]+phase_diff)/180)*math.pi),r*math.sin(((theta[i]+phase_diff)/180)*math.pi))
  return o_rect


#x(t) = (2+.5*cos(nt))cos(t)
#y(t) = (2+.5*cos(nt))sin(t)
def wave_on_circle(n=8,sharpness=0.1,phase_diff=0,A=30):
  j=0
  theta=[]
  while j<=2*math.pi:
    theta.append(j)
    j+=0.01
  x=[]
  y=[]
  for i in range(len(theta)):
    x.append((2+sharpness*math.cos(phase_diff+n*theta[i]))*math.cos(phase_diff+theta[i])*A)
    y.append((2+sharpness*math.cos(phase_diff+n*theta[i]))*math.sin(phase_diff+theta[i])*A)
  #plt.plot(x,y)
  p=[point(x[i],y[i]) for i in range(len(theta))]
  return p
  

def wave_in_btw():
  j=0
  n=8
  A=30
  sharpness=0.12
  phase_diff=math.pi
  theta=[]
  while j<=2*math.pi:
    theta.append(j)
    j+=0.001
  x=[]
  y=[]
  for i in range(len(theta)):
    x.append((2+sharpness*math.cos(n*theta[i]))*math.cos(theta[i])*A)
    y.append((2+sharpness*math.cos(n*theta[i]))*math.sin(theta[i])*A)
  #plt.plot(x,y)
  x_=[]
  y_=[]
  for i in range(len(theta)):
    x_.append((2+sharpness*math.cos(phase_diff+n*theta[i]))*math.cos(phase_diff+theta[i])*A)
    y_.append((2+sharpness*math.cos(phase_diff+n*theta[i]))*math.sin(phase_diff+theta[i])*A)
  #plt.plot(x_,y_)
  #plt.show()
  down_x=[]
  down_y=[]
  for i in range(len(theta)):
    if x[i]**2+y[i]**2 < x_[i]**2 + y_[i]**2:
      down_x.append(x[i])
      down_y.append(y[i])
    else:
      down_x.append(x_[i])
      down_y.append(y_[i])
  #plt.plot(down_x,down_y)
  #plt.show()
  up_x=[]
  up_y=[]
  for i in range(len(theta)):
    if x[i]**2+y[i]**2 > x_[i]**2 + y_[i]**2:
      up_x.append(x[i])
      up_y.append(y[i])
    else:
      up_x.append(x_[i])
      up_y.append(y_[i])
  #plt.plot(up_x,up_y)
  #plt.show()



if __name__=='__main__':
    center_flower_1=polygon(rhodonea(A=31),fill="#db0f6b",stroke="#ad0935",stroke_opacity=0.3)
    center_flower_2=polygon(rhodonea(7,8,46),fill='yellow',stroke='#ad1111',stroke_opacity=0.1,stroke_width=1.5)
    #p1_base=center_flower_2+center_flower_1

    #p1_outer_circle=circle(r=45,stroke='#ff8c12',stroke_width=4)
    #show(p1_base)


    test_1=center_flower_2|repeat(5,scale(0.8))
    test_2=line(0,0,0,0)
    for i in range(1,11):
      test_2+=polygon(rhodonea(A=31),fill=("red" if i%2==1 else '#ffffff'),stroke="#ad0935",stroke_opacity=0.3,fill_opacity=(0.6*i))|scale(0.9/(i-0.1))
    test_3=(polygon(rhodonea(A=31),fill="red",stroke="#ad0935",stroke_opacity=0.3)+test_2 | scale(1.2,1.2))
    center_test=test_1+test_3
    #show(center_test)

    base_circle=circle(r=66,fill='#ff9100',stroke='#ff8c12')
    base_fl=polygon(rhodonea(7,8,71),fill='#fffde6',stroke='#fa8416')
    p2_base=base_fl+base_circle
    #show(p2_base)

    mid_p1=polygon(wave_on_circle(A=27,sharpness=0.12),fill='#ffffff',stroke='#ff9100')+polygon(wave_on_circle(A=26,sharpness=0.12,phase_diff=math.pi),fill='#ff9100',stroke='#ff8c12')
    #show(circle(r=92.6,fill='#6e0e80')+outer_rect()+outer_rect(col='#ffffff',phase_diff=15)+p2_base+mid_p1+p1_base)
    main_item=circle(r=92.6,fill='yellow')+outer_rect(col='#ff78f1',strk='#ff78f1')+outer_rect(col='#d10fad',phase_diff=15)+p2_base+mid_p1+center_test
    #show(main_item)

    o_circle = circle(r=150, fill="brown",stroke='brown')
    o_layer1 = rectangle (w=209,h=209,fill="#db201d", stroke="#db201d") | repeat (15,rotate(50))
    o_layer2 = rectangle (w=193,h=193,fill="red", stroke="red")|rotate(15) | repeat (15,rotate(50))
    o_layer3 = rectangle (w=178,h=178,fill="orange", stroke="orange")|rotate(0) | repeat (15,rotate(50))
    o_layer4 = rectangle (w=165,h=165,fill="yellow", stroke="yellow")|rotate(15) | repeat (15,rotate(50))
    o_layer5 = rectangle (w=153,h=153,fill="white", stroke="white")|rotate(0) | repeat (15,rotate(50))
    cur_piece=(o_circle+o_layer1+o_layer2+o_layer3+o_layer4+o_layer5+(main_item|scale(x=0.95,y=0.95)))|scale(x=0.8,y=0.8)

    test_end_1=polygon(wave_on_circle(A=64.5,sharpness=0.12),stroke='#a52a2a',fill='white')+polygon(wave_on_circle(A=64.5,sharpness=0.12,phase_diff=math.pi),fill='black',stroke='black')
    x=(circle(r=138,fill='black')+circle(r=120,fill='black')+test_end_1)
    show(x)
    show(cur_piece)

    #show(x+cur_piece)is not working
    """why doesn't it work!!!!"""