Created
December 9, 2020 22:55
-
-
Save pleasemarkdarkly/51f939d266dde0cc8e34b34ba76eb42f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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