xxxxxxxxxx
73
let ang = 0
let ring1 = []
let ring2 = []
let ring3 = []
let spheres = []
function plant(x, y, z, radius, s) {
let v = createVector(x, y, z).mult(radius)
rotateY(ang)
translate(v.x, v.y, v.z)
sphere(s)
translate(-v.x, -v.y, -v.z)
rotateY(-ang)
}
function circle_div(n) {
let ang = 2*PI/n
let x = cos(random(ang))
let y = sin(random(ang))
let v = createVector(x, y)
let points = [{x: x, y: 0, z: y}]
while(--n > 0) {
v.rotate(ang)
points.push({x: v.x, y: random(-0.03, 0.03), z: v.y})
}
return points
}
function populate() {
ring1 = circle_div(50)
ring2 = circle_div(40)
ring3 = circle_div(30)
}
function setup() {
createCanvas(600, 400, WEBGL);
noStroke()
camera( -width/2, 30, -width,
-width/2, 0, 0,
1, 3, 0 )
for(let s = 0; s < 50*40*30; ++s) {
spheres[s] = { d: random(2,10), c: random() }
}
populate()
}
function draw() {
background(0);
ambientMaterial(255)
ambientLight(20)
directionalLight(255,255,255, 1, 0, 0.5)
let i = 0
for(d of ring1) {
plant(d.x, d.y, d.z, width, spheres[i].d)
++i
}
for(d of ring2) {
plant(d.x, d.y, d.z, 0.9*width, spheres[i].d)
++i
}
for(d of ring3) {
plant(d.x, d.y, d.z, 0.8*width, spheres[i].d)
++i
}
ang = ang - 0.001
}