xxxxxxxxxx
54
let floorplan;
let isovist = [];
function preload(){
floorplan = loadImage("floorplan.jpg");
}
function setup() {
createCanvas(floorplan.width, floorplan.height);
}
function draw() {
// image(floorplan,0,0)
background(0);
// fill("red")
// noStroke();
beginShape();
for(let i = 1; i< isovist.length; i++){
vertex(isovist[i].x, isovist[i].y)
}
endShape(CLOSE);
noFill();
stroke("red")
// strokeWeight(2);
// for(let i = 1; i< isovist.length; i++){
// line(isovist[0].x, isovist[0].y,
// isovist[i].x, isovist[i].y)
// }
}
function mouseMoved(){
isovist = [createVector(mouseX,mouseY)];
for(let alph = 0; alph<2*PI; alph+=0.05){
let walls = 0;
let coord = createVector(mouseX, mouseY);
let length = 0;
while(walls < 6
&& coord.x>0 && coord.x< width
&& coord.y>0 && coord.y< height){
if(floorplan.get(coord.x, coord.y)[0] < 100){
walls++;
}
else{walls=0}
length++;
coord = createVector( mouseX + cos(alph) * length,
mouseY + sin(alph) * length)
}
isovist.push(coord);
}
}