Code
from math import sin
def genBars(h=100, r=240, g=20, b=20, w=20):
lines = line(x1=0,y1=0,x2=0,y2=0)
w *= 2
step = 3.14 / w
for i in range(w):
val = step * (i + 1)
xStep = i / 2
sVal = max(pow(sin(val), 0.5), 0.1)
clr = color(r * sVal, g * sVal , b * sVal)
lines += line(x1=xStep, x2=xStep, y1=0,y2=h, stroke=clr, fill=clr)
return lines
def genSphere(n=80, r=230, g=20, b=20):
step = 1/n
cir = circle(r=0)
for i in range(n):
val = step * (i + 1)
sVal = max(pow(val, 0.25), 0.1)
clr = color(r * sVal, g * sVal , b * sVal)
cir += circle(r=100, fill=clr, stroke=clr) | scale(1 - val)
return cir
def genConectors():
bar = genBars(r=192,g=192,b=192) | translate(x=-10)
bar2 = bar | translate(y=-100)
bar3 = genBars(r=192,g=192,b=192) | rotate(90) | translate(y=-10)
bar4 = bar3 | translate(x=100)
bar5 = genBars(r=192,g=192,b=192, h=150) | rotate(-45) | translate(x=-120)
bar6 = genBars(r=192,g=192,b=192, h=150) | rotate(45) | translate(x=100)
bar7 = genBars(r=192,g=192,b=192, h=150) | rotate(-45) | translate(y=-100)
bar8 = genBars(r=192,g=192,b=192, h=150) | rotate(45) | translate(y=-120)
return bar + bar2 + bar3 + bar4 + bar5 + bar6 + bar7 + bar8
def genAtoms():
a1 = genSphere(r=0, g=190, b=200) | scale(0.25) | translate(y=100)
a2 = genSphere(r=0, g=150, b=0) | scale(0.25) | translate(y=-100)
a3 = genSphere(r=255, g=215, b=0) | scale(0.25) | translate(x=-100)
a4 = genSphere(r=87, g=25, b=150) | scale(0.25) | translate(x=100)
return a1 + a2 + a3 + a4
sphere = genSphere(r=255, g=215, b=0) | scale(0.33)
connector = genConectors()
atoms = genAtoms()
arr= connector + sphere + atoms
show(arr)