xxxxxxxxxx
84
let points = [];
let cols = ["#001219","#005f73","#0a9396","#94d2bd","#e9d8a6","#ee9b00","#ca6702","#bb3e03","#ae2012","#9b2226"]
let puller1;
let puller2;
let i = 0;
function setup() {
createCanvas(1000, 1600, SVG);
background(255);
puller1 = createVector(random(width), random(height));
puller2 = createVector(random(width), random(height));
points[i] = new Point(i * 10, 0, points.length);
}
function draw() {
for(i = 0; i < points.length; i++){
if(points[i] !== undefined){
points[i].update();
}
}
strokeWeight(5);
stroke(0);
if(frameCount > 100){
}
}
class Point{
constructor(x, y, index){
this.pos = createVector(x, y);
this.npos = undefined;
this.vel = createVector(0, 1);
this.dir = createVector(0, 1);
this.grav = createVector(0, 1);
this.grav.setMag(0.1);
this.dist = 0;
this.index = index;
this.c = floor(random(cols.length));
this.col = color(cols[this.c]);
}
new(){
if(i < width / 10){
i ++;
points[i] = new Point(i * 10, 0, points.length);
} else{
save("whirl.svg");
print("saved svg");
noLoop();
}
}
update(){
this.dist = dist(this.pos.x, this.pos.y, puller1.x, puller1.y);
if(this.dist < 400){
this.dir = p5.Vector.sub(puller1, this.pos);
this.dir.setMag(map(this.dir.mag(), 0, 400, 0.5, 0));
this.vel.add(this.dir);
}
this.dist = dist(this.pos.x, this.pos.y, puller2.x, puller2.y);
if(this.dist < 400){
this.dir = p5.Vector.sub(puller2, this.pos);
this.dir.setMag(map(this.dir.mag(), 0, 400, 0.5, 0));
this.vel.add(this.dir);
}
this.vel.add(this.grav);
// this.vel.limit(10);
this.npos = p5.Vector.add(this.pos, this.vel);
stroke(0);
strokeWeight(1);
line(this.pos.x, this.pos.y, this.npos.x, this.npos.y);
this.pos.add(this.vel)
if(this.pos.x < 0 || this.pos.y < 0 || this.pos.x > width || this.pos.y > height){
points[this.index].new();
points[this.index] = undefined;
}
}
}