xxxxxxxxxx
60
class Asteroids {
constructor(fnX, fnY, fnVelx, fnVely, fnSize, fnRGB){
this.x = [];
this.y = [];
this.velocity_x = [];
this.velocity_y = [];
this.size = [];
this.rgb = [];
}
}
class Asteroid{
constructor(aX, aY, aVelx, aVely, aSize){
this.x = aX;
this.y = aY;
this.velx = aVelx;
this.vely = aVely;
this.size = aSize;
}
draw() {
circle(this.x, this.y, this.size);
this.x += this.velx;
this.y += this.vely;
// ignorerer det her
this.x *= !(this.x > width);
this.x = this.x * !(this.x < 0) + width * (this.x < 0);
this.y *= !(this.y > height);
this.y = this.y * !(this.y < 0) + height * (this.y < 0);
}
}
let asteroidListe = [];
function setup() {
createCanvas(400, 400);
for(let t = 0; t < 9000; t = t +1) {
// gør noget 10 gange
let tempAsteroid =
new Asteroid(200, 20*t, random(-2,2), random(-2,2), 10);
asteroidListe.push(tempAsteroid);
}
}
function draw() {
background(220);
for(let ast of asteroidListe ){
ast.draw();
}
}