xxxxxxxxxx
37
let rays = 360;
let sight = [];
let bgc = 100
function setup() {
createCanvas(400, 400);
background(bgc);
for(let i = 0; i < 5; i++){
line(random(width), random(height), random(width), random(height));
}
angleMode(DEGREES);
loadPixels();
stroke(255, 255, 255);
for(let i = 0; i < rays; i++){
ray(200, 200, i * (360 / rays));
}
fill(255, 0, 0);
circle(200, 200, 10);
}
function draw() {
stroke(255, 0, 0);
strokeWeight(5);
for(let i = 0; i < sight.length; i++){
point(sin(sight[i][0]) * sight[i][1] + 200, cos(sight[i][0]) * sight[i][1] + 200);
}
}
function ray(x, y, r){
if(pixels[(round(x) + round(y) * width) * 4] === bgc && x < width && y < height && y > 0 && x > 0){
point(sin(r) + x, cos(r) + y);
ray(sin(r) + x, cos(r) + y, r)
}
else{
sight.push([r, dist(200, 200, x, y)]);
}
}