Skip to content

Instantly share code, notes, and snippets.

@LadyScream
Created January 24, 2018 01:39
Show Gist options
  • Save LadyScream/4eab4a213eaeecb6e6dd9bf7c38ff71c to your computer and use it in GitHub Desktop.
Save LadyScream/4eab4a213eaeecb6e6dd9bf7c38ff71c to your computer and use it in GitHub Desktop.
3D Knot in @beesandbombs style
import math
a = 0
tetha = 0
phi = 0
beta = 0
betaChange = 0.0015
mR = 5
MR = 10
sides = 10
life = 40
array = []
class circle:
def __init__(self, x, y, z, r):
self.x = x
self.y = y
self.z = z
self.r = r
self.lifetime = life
def setup():
size(600, 600, P3D)
def draw():
global a, tetha, phi, beta, array
a = a + 0.01
fill(32)
noStroke()
background(255, 200, 200)
translate(width/2, height/2, -100)
rotateY(a)
beta += betaChange
beta = beta % PI
radius = 0.8 + 1.6 * math.sin(6*beta) * 200
tetha = 2 * beta
phi = 0.6 * PI * math.sin(12*beta)
x = math.cos(tetha) * math.cos(phi) * radius
y = math.sin(tetha) * math.cos(phi) * radius
z = math.sin(phi) * radius
array.append( circle(x, y, z, random(mR, MR)) )
for i in range(len(array)-1,0,-1):
pushMatrix()
translate(array[i].x, array[i].y, array[i].z)
r = array[i].r
if (array[i].lifetime > life*0.95):
r = map(array[i].lifetime, life*0.95, life, array[i].r, 0)
if (array[i].lifetime <= life*0.05):
r = map(array[i].lifetime, 0, life*0.05, 0, array[i].r)
sphere(r)
array[i].lifetime -= 0.1
if (array[i].lifetime <= 0):
del array[i]
popMatrix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment