Skip to content

This repo showcases 2D line drawing using Bresenham, Midpoint, and Parametric algorithms with SDL. It includes features for clearing the screen, drawing pixels and markers, and generating random lines. Press 1, 2, or 3 to draw lines in red, green, or blue. Press 4 to clear the screen and display a starry sky.

Notifications You must be signed in to change notification settings

tashi-2004/2D-Line-Drawing-Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

2D-Line-Drawing-Algorithms-VectorLineRenderer

This project demonstrates the implementation of three fundamental line drawing algorithms in 2D space using SDL:

  • Bresenham Line Algorithm
  • Midpoint Line Algorithm
  • Parametric Line Algorithm

Project Structure

The project consists of two main files:

  • Algo.cpp: Contains the main function which sets up the SDL environment and handles rendering and input.
  • Header.h: Contains all the function implementations for line drawing, pixel drawing, clearing the back buffer, and handling input.

Functionality

Initialization

The program initializes SDL, creates a window and a renderer, and sets up the initial screen.

Clearing the Back Buffer

The ClearBackBuffer function clears the screen to a specified color.

Drawing Pixels

The DrawPixel function draws a single pixel at a given position with a specified color.

Drawing Markers

The DrawMarker function draws a square marker of a specified size and color at a given position.

Line Drawing Algorithms

The project implements three line drawing algorithms:

  • Bresenham Line Algorithm: Efficiently draws lines using integer calculations.
  • Midpoint Line Algorithm: Draws lines by determining the midpoint between two points.
  • Parametric Line Algorithm: Draws lines using parametric equations.

Random Line Drawing

When key 1, 2, or 3 are pressed, the program draws a random line of a specified color (red, green, or blue/purple) on the screen and marks the start and end points with yellow pixels.

1 2 3

Sky of Stars

When key 4 is pressed, all lines are cleared, and the screen is filled with randomly placed white pixels, simulating a sky full of stars.

4

Final Output

5

Video

video.mp4

Handling User Input

The HandleInput function captures keyboard input to draw lines or clear the screen based on the user's key presses.

Setup

To set up the SDL library in Visual Studio, follow the instructions provided in this YouTube tutorial.

How to Run

  1. Clone this repository.
  2. Set up SDL in your development environment.
  3. Compile and run Algo.cpp.

Contributors

Contact

For any questions or suggestions, feel free to contact at [abbasitashfeen7@gmail.com]


Enjoy experimenting with 2D line drawing algorithms!

About

This repo showcases 2D line drawing using Bresenham, Midpoint, and Parametric algorithms with SDL. It includes features for clearing the screen, drawing pixels and markers, and generating random lines. Press 1, 2, or 3 to draw lines in red, green, or blue. Press 4 to clear the screen and display a starry sky.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages