xxxxxxxxxx
77
let walls = [];
let ray;
let particle;
const sceneW = 400;
const sceneH = 400;
let sliderFOV;
function setup() {
createCanvas(800, 400);
walls.push(new Boundary(0,0,sceneW,0));
walls.push(new Boundary(sceneW,0,sceneW,sceneH));
walls.push(new Boundary(sceneW,sceneH,0,sceneH));
walls.push(new Boundary(0,sceneH,0,0));
for(var i = 0; i < 5; i++){
walls.push(new Boundary(random(sceneW),random(sceneH),random(sceneW),random(sceneH)));
}
particle = new Particle();
sliderFOV = createSlider(1,180,45);
sliderFOV.input(changeFOV);
}
function changeFOV(){
let fov = sliderFOV.value();
particle.updateFOV(fov);
}
function draw() {
if(keyIsDown(LEFT_ARROW)){
particle.rotate(-0.05);
}
if(keyIsDown(RIGHT_ARROW)){
particle.rotate(0.05);
}
if(keyIsDown(UP_ARROW)){
particle.move(1);
}
if(keyIsDown(DOWN_ARROW)){
particle.move(-1)
}
background(10);
for(let wall of walls){
wall.show();
}
//particle.update(mouseX,mouseY);
particle.show();
var scene = particle.look(walls);
var w = sceneW / scene.length;
push();
translate(sceneW,0);
for(let i = 0; i < scene.length; i++){
noStroke();
let b = map(scene[i]*scene[i],0,sceneW*sceneW,255,0);
fill(b);
let h = map(scene[i],0,sceneW,sceneH,0)
rectMode(CENTER);
rect(i * w + w / 2,sceneH/2,w,h);
}
pop();
//ray.show();
//ray.lookAt(mouseX,mouseY);
//let pt = ray.cast(wall);
//if(pt){
// fill(255);
// ellipse(pt.x,pt.y,10,10);
//}
}