xxxxxxxxxx
51
// Daniel Shiffman
// https://thecodingtrain.com/CodingChallenges/145-2d-ray-casting.html
// https://youtu.be/TOEi6T2mtHo
// 2D Ray Casting
// https://editor.p5js.org/codingtrain/sketches/Nqsq3DFv-
let walls = [];
let ray;
let particle;
let xoff = 0;
let yoff = 10000;
let wallNumber = 3;
function setup() {
// Make canvas and save SVG when clicked
createCanvas(1000, 1000, SVG).mousePressed(saveIt);
for (let i = 0; i < wallNumber; i++) {
let x1 = random(width);
let x2 = random(width);
let y1 = random(height);
let y2 = random(height);
walls[i] = new Boundary(x1, y1, x2, y2);
}
walls.push(new Boundary(0, 0, width-1, 0));
walls.push(new Boundary(width-1, 0, width-1, height-1));
walls.push(new Boundary(width-1, height-1, 0, height-1));
walls.push(new Boundary(0, height-1, 0, 0));
particle = new Particle();
}
function draw() {
background(0);
for (let wall of walls) {
wall.show();
}
particle.update(noise(xoff) * width, noise(yoff) * height);
//particle.update(width/2, height/2);
particle.show();
particle.look(walls);
//xoff += 0.01;
//yoff += 0.01;
}
function saveIt() {
save("mySVG.svg")
console.log("SVG saved.")
}