xxxxxxxxxx
70
let r;
function setup() {
createCanvas(500, 500);
}
function draw() {
background(0);
r = new Light();
r.draw();
}
class Light{
constructor(){
this.dir = random(0,TWO_PI);
this.pos = createVector(mouseX, mouseY);
this.nbRays = 1000;
}
draw(){
stroke(255);
let radii = 100;
for(let i = 0 ; i < this.nbRays ; i++){
let rx = sin(i/this.nbRays*TWO_PI) * radii + this.pos.x
let ry = cos(i/this.nbRays*TWO_PI) * radii + this.pos.y
let l = new Line();
l.fromPoints(createVector(rx, ry), this.pos)
l.drawLine();
// intersects with boundary
}
}
}
class Ray{
constructor(){
this.line = new Line();
}
}
class Line{
constructor(){
// y = ax + b
this.a = 0;
this.b = 0;
}
fromPoints(p1, p2){
this.a = ( p2.y - p1.y ) / ( p2.x - p1.x );
this.b = p1.y - this.a * p1.x;
}
drawLine(){
// draw between x min and x max
//line(0, this.b, // x1 . y1
//width, width*this.a+this.b// x2 y2
//)
for(let i = 0; i < 10; i++){
let p1 = createVector(0, this.b);
let p2 = createVector(width, width*this.a+this.b);
point(p5.Vector.lerp(p1,p2,random()))
}
}
intersectsLine(line){
}
}