xxxxxxxxxx
124
const sceneW = 400;
const sceneH = 400;
const Y_AXIS = 1;
const X_AXIS = 2;
const da = 1 / sceneW
var cols,rows,current,sliderFOV,particle;
var grid = [];
var stack = [];
let walls = [];
var gate = false;
var gate1 = false;
var scl = 40;
function setup() {
createCanvas(800, 400);
cols = floor(sceneW/scl);
rows = floor(sceneH/scl);
//maze
for(var j = 0; j < rows; j++){
for(var i = 0; i< cols; i++){
var cell = new Cell(i,j);
grid.push(cell)
}
}
current = grid[0];
//ray
particle = new Particle();
//sliderFOV = createSlider(1,180,45);
//sliderFOV.input(changeFOV);
}
function move(d){
if(keyIsDown(LEFT_ARROW)){
particle.rotate(-0.05);
}
if(keyIsDown(RIGHT_ARROW)){
particle.rotate(0.05);
}
if(keyIsDown(UP_ARROW)){
particle.move(0.5,d);
}
if(keyIsDown(DOWN_ARROW)){
particle.move(-0.5,d);
}
}
function draw() {
background(0);
if(!gate){
gate = backtracking();
}
if(gate){
for(let wall of walls){
//console.log(wall)
wall.show();
}
particle.show();
//celling
fill(230,0,0,10);
//rect(sceneW,0,width,sceneH/2);
//setGradient(sceneW,0,width,sceneH/2,color(255,0,0),color(0),Y_AXIS);
//floor
//setGradient(sceneW,sceneH,width,sceneH,color(51,0,0),color(0),Y_AXIS);
var scene = particle.look(walls);
var w = sceneW / scene.length;
move(scene);
push();
translate(sceneW,0);
for(let i = 0; i < scene.length; i++){
const d = scene[i] / sceneW;
const sq = scene[i] * scene[i];
const wSq = sceneW * sceneW;
const h = 30 / d;
const b = 5 / d * 0.6;
fill(b);
rectMode(CENTER);
rect((i + 0.5) * w, sceneH / 2, w, h);
}
pop();
}
}
function setGradient(x, y, w, h, c1, c2, axis) {
noFill();
if (axis === Y_AXIS) {
// Top to bottom gradient
for (let i = y; i <= y + h; i++) {
let inter = map(i, y, y + h, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(x, i, x + w, i);
}
} else if (axis === X_AXIS) {
// Left to right gradient
for (let i = x; i <= x + w; i++) {
let inter = map(i, x, x + w, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y + h);
}
}
}