Skip to content

Instantly share code, notes, and snippets.

@pleasemarkdarkly
Created December 9, 2020 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pleasemarkdarkly/51f939d266dde0cc8e34b34ba76eb42f to your computer and use it in GitHub Desktop.
Save pleasemarkdarkly/51f939d266dde0cc8e34b34ba76eb42f to your computer and use it in GitHub Desktop.
// 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;
function setup() {
createCanvas(1000, 1000);
for (let i = 0; i < 5; 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, 0));
walls.push(new Boundary(width, 0, width, height));
walls.push(new Boundary(width, height, 0, height));
walls.push(new Boundary(0, height, 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.show();
particle.look(walls);
xoff += 0.01;
yoff += 0.01;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment