xxxxxxxxxx
81
class Worm {
constructor(x,y,z,radius,angle,c,anglei,anglej){
this.x =x;
this.y =y;
this.z =z;
this.radius = radius;
this.angle = angle;
this.rry = [];
this.xn =random(0.01);
this.yn =random(0.03);
this.inc = 0.003;
this.anglei=anglei;
this.anglej=anglej;
this.c =c;
}
update(){
let xn =frameCount * this.xn
let yn =frameCount * this.yn;
for(let i=0; i<this.radius; i+=1){
let p = map(noise(xn,yn),0,1,0,360);
let x = sin(this.anglei) * cos(this.anglej) * (i);
let y = cos(this.anglei) * (i);
let z = sin(this.anglej) * sin(this.anglei) * (i);
let v2 = createVector(x,y,z);
v2.rotate(p);
this.rry.unshift(v2);
xn+=this.inc;
yn+=this.inc;
}
}
display(){
push();
translate(this.x,this.y,this.z);
beginShape(LINES);
stroke(this.c);
noFill();
for(let i=0; i<this.rry.length; i+=1){
let v2 = createVector(this.rry[i].x,this.rry[i].y,this.rry[i].z);
if(i == 0){
strokeWeight(0.2);
push();
translate(v2.x,v2.y,v2.z);
sphere(2);
pop();
}
strokeWeight(1);
curveVertex(v2.x,v2.y,v2.z);
}
endShape();
pop();
this.rry = [];
}
}