r/processing • • Nov 21 '19

Basic 2D Raycaster

Post image
200 Upvotes

9 comments sorted by

View all comments

15

u/[deleted] Nov 21 '19

Source for those that asked: https://github.com/fiskurgit/ProcKtTemplate/blob/master/src/prockt/sketches/Sketch026.kt

It uses an old bouncing ball sketch for the angle/collision logic, using that I adapted it for (pseudo) light rays. Every time there's a collision the alpha is reduced, once the alpha hits zero the ray is removed from the stack. The speed dictates how far the ray travels each frame (lower speed on the right images, higher speed (left images) creates a nice diffraction effect). The code isn't as clean as I'd like but it's a starting point.