xxxxxxxxxx
114
let rad;
let v;
let turn = 0;
let swarm = [];
let num;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
colorMode(HSB, 360, 100, 100, 100);
rad = width*.3;
v = width*.1
num = height*.5;
frameRate(30)
for (let i = 0; i < num; i++) {
swarm.push(new Particle());
}
}
function draw() {
//background(40, 20, 100);
background(10);
lights();
push();
rotateY(turn);
rotateX(turn);
rotateZ(turn);
//noStroke();
drawTrack(100, rad, v);
drawEdges(100, rad, v);
turn += 0.003
pop();
//for(let i=0; i < swarm.length; i++){
// swarm[i].run();
//}
}
function drawTrack(steps, rad, v) {
//beginShape(TRIANGLE_STRIP);
beginShape(QUAD_STRIP);
fill(0);
strokeWeight(2);
stroke(255);
for (let step = 0; step < (steps + 1); step += 1) {
let u = step * TAU / steps;
let x = (rad - v * cos(0.5 * u)) * cos(u);
let y = (rad - v * cos(0.5 * u)) * sin(u);
let z = -v * sin(0.5 * u);
vertex(x, y, z);
x = (rad + v * cos(0.5 * u)) * cos(u);
y = (rad + v * cos(0.5 * u)) * sin(u);
z = v * sin(0.5 * u);
vertex(x, y, z);
}
endShape(CLOSE);
}
function drawEdges(steps, rad, v) {
for (let step = 0; step < (steps + 1); step += 1) {
fill(260, random(100), 100);
stroke(0)
let u = step * TAU / steps;
let x = (rad - v * cos(0.5 * u)) * cos(u);
let y = (rad - v * cos(0.5 * u)) * sin(u);
let z = -v * sin(0.5 * u);
push();
translate(x, y, z);
//box(10)c
box(random(6,10))
pop();
x = (rad + v * cos(0.5 * u)) * cos(u);
y = (rad + v * cos(0.5 * u)) * sin(u);
z = v * sin(0.5 * u);
push();
translate(x, y, z);
box(random(6,10))
//box(10);
pop();
}
}
class Particle{
constructor(){
this.loc = createVector(0, 0, 0);
this.rad = 10;
this.vel = createVector(0, 0, 0);
this.ts = random(5);
this.color = random(70,250)
}
run(){
this.update();
this.display();
}
update(){
this.a = p5.Vector.random3D();
this.a.mult(random(3));
this.vel.add(this.a);
this.vel.limit(this.ts);
this.loc.add(this.vel);
}
display(){
push();
//stroke(0);
noStroke();
fill(this.color, random(100), random(100));
translate(this.loc);
rotateY(this.loc.y);
rotateZ(this.loc.z);
ellipsoid(this.rad, random(20), random(20));
pop();
}
}