xxxxxxxxxx
59
let things = [];
function setup() {
createCanvas(400, 400);
things.push(new Thing(50, 50))
things.push(new Thing(200, 200))
}
function draw() {
background(220);
drawthings(things);
}
function drawthings(things){
for(let i=0;i<things.length;i++){
things[i].display();
}
}
class Thing{
constructor(x,y){
this.r=10;
this.l=100;
this.amt=5;
this.angle=90;
this.x=x;
this.y=y;
this._id= Thing.incrementId();
}
static incrementId(){
// from here <3 https://stackoverflow.com/a/41916397/6934388
if (!this.latestId) this.latestId = 1
else this.latestId++
return this.latestId
}
move(){
}
display(){
console.log(this._id+' display');
translate(this.x, this.y);
circle(0, 0, this.r);
for (let i =0; i<this.amt+1 ;i++){
rotate(radians(this.angle/this.amt+1));
line(0,0, this.l, 0);
}
}
}