xxxxxxxxxx
74
let a = 0;
let the_time = 0;
let lights = [];
function setup() {
createCanvas(400, 400);
frameRate(30);
lights.push(new LightShooter(350, 350, 123, 160, 300, 15, 2, 1));
lights.push(new LightShooter(25, 25, 200, -25, 100, 2, 8, 1));
for (var i=0; i < TWO_PI ;i+=PI/20){
var x = 200+(cos(i)*100);
var y = 200+(sin(i)*100);
lights.push(new LightShooter(x, y, 100, 0, 400, 3, 2, 1));
}
}
function line_at_angle(x,y, angle, length){
push();
translate(x,y);
rotate(radians(angle));
stroke('red');
line(0,0, length, 0);
pop();
}
function draw() {
background(220);
for (let i = 0; i < lights.length;i++){
lights[i].rotate();
lights[i].shoot();
}
the_time++;
}
class LightShooter {
constructor(x, y, length, mina, maxa, step,rayamt, delay){
this.x=x;
this.y=y;
this.length=length;
this.mina=mina;
this.maxa=maxa;
this.cura=mina;
this.step=step;
this.rayamt = rayamt;
this.delay=delay;
this.time = the_time;
}
rotate(){
if (the_time > this.time + this.delay ) {
this.cura = this.cura + this.step;
if (this.cura >= this.maxa || this.cura <= this.mina) {
this.step = -this.step;
}
this.time=the_time;
}
}
shoot () {
let ang = this.cura;
let count = 0;
while(ang >= this.mina && ang < this.maxa && count < this.rayamt){
line_at_angle(this.x, this.y, ang, this.length);
ang+=this.step;
count++;
}
}
}