xxxxxxxxxx
61
let allPoints = []; //___________________ make a array for allPoints of type class Point
let newallPoints = []; //________________ make a array for newallPoints of type class Point
let cx, cy;
let t, beginning;
function setup() {
createCanvas(640, 640);
beginning = millis();
cx = width / 2;
cy = height / 2;
allPoints.push(new Point(cx, cy, 0));
stroke(0);
strokeWeight(3);
}
function draw() {
background(255);
t = millis();
let nowl = allPoints.length;
for (let i = 0; i < nowl; i++) {
print("frame "+frameCount+" nowl "+nowl+" i "+i);
let p = allPoints[i];
p.move();
if (p.alive) {
allPoints.push(new Point(cx, cy, 0));
//newallPoints.push(p);
}
}
let ang = TWO_PI / 350;//frameCount;
for (let a = 0; a < TWO_PI; a += ang) newallPoints.push(new Point(cx, cy, a));
arrayCopy(newallPoints,allPoints);
//allPoints = newallPoints;
let ecouled = millis() - t;
print(allPoints.length, ecouled, allPoints.length / (ecouled / 1000));
if (allPoints.length > 30) {
print("total time : " + (millis() - beginning));
noLoop();
}
}
class Point {
constructor(x, y, a) {
this.x = x;
this.y = y;
this.a = a;
this.alive = true;
}
move() {
if (this.x < 0 || this.y < 0 || this.x > width || this.y > height) this.alive = false;
this.x += cos(this.a) * 2;
this.y += sin(this.a) * 2;
print(this.x, this.y, this.a,this.alive);
point(this.x, this.y); //__________________________ show
}
} //___ end class