Skip to content

2D Ray Casting is a ray visualizer built in python using the pygame library that allows users to move a light source around and cast the appropriate rays onto walls.

Notifications You must be signed in to change notification settings

MugPand/2D-Ray-Casting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2D Ray Casting

2D Ray Casting Logo

2D Ray Casting is a ray visualizer built in python using the pygame library that allows users to move a light source around and cast the appropriate rays onto walls. It was inspired by a video discussing the fundamentals of drawing and casting rays in Javascript (https://www.youtube.com/watch?v=TOEi6T2mtHo). The formula used to check for ray-Wall collisions can be found in the line segment portion of https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection.

Getting Started

To get started:

  1. Run pip install -r requirements.txt
  2. Start the application by running python main.py

Usage

2D Ray Casting Screenshot1

The application places a light source, comprised of NUM_RAYS (initially set to 360), draws 4 border walls, and randomly generates and draws anywhere from 0-10 additional walls.

The light sources tracks the movement of the mouse and adjusts its rays and collisions accordingly.

Restarting the application or pressing R generates a new list of Walls, allowing each run to cast rays onto various wall objects.

2D Ray Casting Screenshow2

Future Iterations

  • Add keyboard controls to generate new walls.
  • So far, the Wall, Light, and Ray objects have been created, although more can be added in the future i.e. Mirrors/Transparent surfaces.

About

2D Ray Casting is a ray visualizer built in python using the pygame library that allows users to move a light source around and cast the appropriate rays onto walls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages