xxxxxxxxxx
let angleOffset = 0;
let particleSpeed = 0.01;
function setup() {
createCanvas(600, 600, WEBGL);
}
function draw() {
background(30);
// interaction based on mouse position
rotateX(map(mouseY, 0, height, -PI/4, PI/4));
rotateY(map(mouseX, 0, width, -PI/4, PI/4));
// only the outer ring
push();
noFill();
stroke(255);
strokeWeight(4);
ellipse(0, 0, 400, 400);
pop();
// two pipes
push();
translate(-100, 0, 0);
rotate(angleOffset);
pipe(50, 10, color(255, 0, 0));
pop();
push();
translate(100, 0, 0);
rotate(-angleOffset);
pipe(50, 10, color(0, 255, 0));
pop();
// angle offset
angleOffset += particleSpeed;
}
function pipe(radius, thickness, particleColor) {
//drawing the pipe
noFill();
stroke(255);
strokeWeight(thickness);
torus(radius, thickness);
// drawing the particle
push();
fill(particleColor);
rotateZ(angleOffset);
sphere(5);
pop();
}