Skip to content

Latest commit

ย 

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

2D Graphics Toolkit

A comprehensive Windows-based 2D graphics application implementing various computer graphics algorithms for drawing lines, circles, ellipses, polygons, curves, and filling shapes. Built using the Windows API (Win32) and C++.

License Language Platform

๐Ÿ“‹ Table of Contents

โœจ Features

  • Interactive Drawing Interface: Point-and-click interface for drawing various shapes
  • Multiple Algorithm Implementations: Each shape type has multiple algorithm implementations
  • Real-time Preview: See shapes as you draw them
  • Color Selection: Choose from multiple colors for drawing
  • Fill Operations: Various fill algorithms including flood fill and scanline fill
  • File I/O: Save and load your drawings
  • Curve Support: Bezier, Hermite, and Cardinal Spline curves
  • Optimized Rendering: Double-buffered drawing for smooth performance

๐ŸŽจ Implemented Algorithms

Line Drawing Algorithms

  • DDA (Digital Differential Analyzer) - Simple incremental line drawing
  • Bresenham's Line Algorithm - Integer-based efficient line drawing
  • Parametric Line - Parametric equation-based line drawing
  • Horizontal Line - Optimized horizontal line drawing

Circle Drawing Algorithms

  • Direct Circle - Mathematical circle using direct equation
  • Polar Circle - Polar coordinate-based circle
  • Iterative Polar Circle - Optimized polar circle
  • Midpoint Circle (Bresenham) - Efficient integer-based circle
  • Modified Midpoint Circle - Enhanced midpoint algorithm

Ellipse Drawing Algorithms

  • Direct Ellipse - Direct mathematical ellipse
  • Polar Ellipse - Polar coordinate ellipse
  • Bresenham's Ellipse (Midpoint) - Integer-based efficient ellipse

Polygon Drawing

  • General Polygon - N-sided polygon with Bresenham lines
  • Rectangle - Axis-aligned rectangle
  • Square - Equal-sided rectangle

Curve Drawing

  • Bezier Curves - Smooth parametric curves
  • Hermite Curves - Tangent-based smooth curves
  • Cardinal Splines - Interpolating spline curves

Fill Algorithms

  • Circle Fills:

    • Fill with horizontal lines
    • Quarter circle fill
    • Concentric circles fill
  • Polygon Fills:

    • Convex polygon scanline fill
    • Non-convex polygon scanline fill
  • Flood Fill:

    • Recursive flood fill
    • Non-recursive (iterative) flood fill
  • Special Fills:

    • Fill rectangle with horizontal Bezier curves
    • Fill square with vertical Hermite curves

๐Ÿ“ Project Structure

2D-Graphics-Toolkit/
โ”œโ”€โ”€ include/                      # Header files
โ”‚   โ”œโ”€โ”€ Bezier.h                 # Bezier curve declarations
โ”‚   โ”œโ”€โ”€ CardinalSpline.h         # Cardinal spline declarations
โ”‚   โ”œโ”€โ”€ CircleAlgorithms.h       # Circle drawing algorithms
โ”‚   โ”œโ”€โ”€ CircleFillAlgorithms.h   # Circle filling algorithms
โ”‚   โ”œโ”€โ”€ EllipseAlgorithms.h      # Ellipse drawing algorithms
โ”‚   โ”œโ”€โ”€ FloodFill.h              # Flood fill algorithms
โ”‚   โ”œโ”€โ”€ GraphicsTypes.h          # Common types and enums
โ”‚   โ”œโ”€โ”€ Hermite.h                # Hermite curve declarations
โ”‚   โ”œโ”€โ”€ LineAlgorithms.h         # Line drawing algorithms
โ”‚   โ”œโ”€โ”€ Point.h                  # Point structure
โ”‚   โ”œโ”€โ”€ PolygonAlgorithms.h      # Polygon drawing algorithms
โ”‚   โ”œโ”€โ”€ PolygonFillAlgorithms.h  # Polygon fill algorithms
โ”‚   โ”œโ”€โ”€ Utils.h                  # Utility functions
โ”‚   โ””โ”€โ”€ Window.h                 # Main window and graphics framework
โ”‚
โ”œโ”€โ”€ src/                         # Implementation files
โ”‚   โ”œโ”€โ”€ circle/                  # Circle algorithm implementations
โ”‚   โ”‚   โ”œโ”€โ”€ DirectCircle.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ IterativePolarCircle.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ MidpointCircle.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ ModifiedMidpointCircle.cpp
โ”‚   โ”‚   โ””โ”€โ”€ PolarCircle.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ circle fill/             # Circle fill implementations
โ”‚   โ”‚   โ”œโ”€โ”€ FillCircleWithCircles.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ FillCircleWithLines.cpp
โ”‚   โ”‚   โ””โ”€โ”€ FillQuarterCircle.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ curve/                   # Curve implementations
โ”‚   โ”‚   โ”œโ”€โ”€ Bezier.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ CardinalSpline.cpp
โ”‚   โ”‚   โ””โ”€โ”€ Hermite.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ elipse/                  # Ellipse implementations
โ”‚   โ”‚   โ”œโ”€โ”€ BresenhamElipse.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ DirectElipse.cpp
โ”‚   โ”‚   โ””โ”€โ”€ PolarElipse.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ flood fill/              # Flood fill implementations
โ”‚   โ”‚   โ”œโ”€โ”€ NonRecursiveFloodFIll.cpp
โ”‚   โ”‚   โ””โ”€โ”€ RecursiveFloodFill.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ line/                    # Line algorithm implementations
โ”‚   โ”‚   โ”œโ”€โ”€ BresenhamLine.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ BresenhamPolygonLine.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ DDALine.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ HorizontalLine.cpp
โ”‚   โ”‚   โ””โ”€โ”€ ParametricLine.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ polygon/                 # Polygon implementations
โ”‚   โ”‚   โ”œโ”€โ”€ Polygon.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ Rectangle.cpp
โ”‚   โ”‚   โ””โ”€โ”€ Square.cpp
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ polygon fill/            # Polygon fill implementations
โ”‚   โ”‚   โ”œโ”€โ”€ ConvexFIll.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ FillRectangleWithHorizontalBezier.cpp
โ”‚   โ”‚   โ”œโ”€โ”€ FillSquareWithVerticalHermite.cpp
โ”‚   โ”‚   โ””โ”€โ”€ NonConvexFill.cpp
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ window/                  # Window management implementations
โ”‚       โ”œโ”€โ”€ Buffer.cpp           # Offscreen buffer management
โ”‚       โ”œโ”€โ”€ Draw.cpp             # Drawing coordination
โ”‚       โ”œโ”€โ”€ File.cpp             # File I/O operations
โ”‚       โ”œโ”€โ”€ Menu.cpp             # Menu handling
โ”‚       โ”œโ”€โ”€ Mouse.cpp            # Mouse event handling
โ”‚       โ””โ”€โ”€ Window.cpp           # Main window implementation
โ”‚
โ”œโ”€โ”€ docs/                        # Documentation
โ”‚   โ””โ”€โ”€ Documentation.md         # Detailed framework documentation
โ”‚
โ”œโ”€โ”€ cmake-build-debug/           # CMake build files (generated)
โ”œโ”€โ”€ CMakeLists.txt              # CMake build configuration
โ”œโ”€โ”€ main.cpp                    # Application entry point
โ”œโ”€โ”€ LICENSE                     # License file
โ””โ”€โ”€ README.md                   # This file

๐Ÿ’ป Requirements

Software Requirements

  • Operating System: Windows 7 or later
  • Compiler:
    • MSVC (Visual Studio 2017 or later)
    • MinGW-w64 (GCC 7.0 or later)
    • Clang for Windows
  • Build System: CMake 3.31 or later
  • IDE (Optional but recommended):
    • CLion
    • Visual Studio
    • VS Code with C++ extensions

Libraries

  • Windows API (Win32) - Pre-installed with Windows SDK
  • Standard C++ Library (C++17)

๐Ÿ”จ Building the Project

Using CMake (Command Line)

  1. Clone the repository:
git clone https://github.com/Hemdan47/2D-Graphics-Toolkit.git
cd 2D-Graphics-Toolkit
  1. Create build directory:
mkdir build
cd build
  1. Generate build files:
cmake ..
  1. Build the project:
cmake --build . --config Release
  1. Run the executable:
# From the build directory
cd Release
./2D-Graphics-Toolkit.exe

# Or from the build directory directly
./Release/2D-Graphics-Toolkit.exe

Using CLion

  1. Open CLion
  2. Select File โ†’ Open and choose the project directory
  3. CLion will automatically detect CMakeLists.txt
  4. Click the Build button (hammer icon) or press Ctrl+F9
  5. Click Run (play icon) or press Shift+F10

Using Visual Studio

  1. Open Visual Studio
  2. Select File โ†’ Open โ†’ CMake
  3. Choose the CMakeLists.txt file
  4. Wait for CMake to configure
  5. Select Build โ†’ Build All or press Ctrl+Shift+B
  6. Run with Debug โ†’ Start Without Debugging or press Ctrl+F5

๐ŸŽฎ Usage

Basic Drawing

  1. Launch the application - A window will open with a menu bar
  2. Select a drawing algorithm from the Shapes menu:
    • Choose from Lines, Circles, Ellipses, Polygons, or Curves
  3. Click on the canvas to define points:
    • Lines/Circles/Ellipses: Click twice (start and end points)
    • Polygons: Click multiple times, right-click to finish
    • Rectangles: Click and drag
  4. The shape appears using the selected algorithm

Selecting Colors

  1. Open the Colors menu
  2. Select from:
    • Black
    • Red
    • Green
    • Blue
    • White

Filling Shapes

  1. Draw a closed shape (circle, polygon, etc.)
  2. Select a fill mode from the Fill menu
  3. Click inside the shape to fill it

File Operations

  • New Canvas: File โ†’ New (clears current drawing)
  • Save Drawing: File โ†’ Save (saves to .bin file)
  • Load Drawing: File โ†’ Load (loads from .bin file)

Shape-Specific Instructions

Drawing a Line

  1. Shapes โ†’ Lines โ†’ Choose algorithm (DDA, Bresenham, or Parametric)
  2. Click for start point
  3. Click for end point

Drawing a Circle

  1. Shapes โ†’ Circles โ†’ Choose algorithm
  2. Click for center point
  3. Click to define radius

Drawing an Ellipse

  1. Shapes โ†’ Ellipses โ†’ Choose algorithm
  2. Click for center point
  3. Click to define semi-major axis length

Drawing a Polygon

  1. Shapes โ†’ Polygon
  2. Click to add vertices (as many as needed)
  3. Right-click to close polygon

Drawing Curves

  1. Shapes โ†’ Curves โ†’ Choose type (Bezier, Hermite, Cardinal)
  2. Click to add control points
  3. Right-click when done

๐Ÿ”ง Extending the Project

Adding a New Drawing Algorithm

  1. Declare function in appropriate header file (e.g., LineAlgorithms.h)
  2. Implement algorithm in corresponding source file
  3. Add menu constant in GraphicsTypes.h
  4. Update DrawingMode enum
  5. Add menu item in Window.cpp โ†’ InitializeMenus()
  6. Handle menu command in HandleMenuCommand()
  7. Add drawing case in RedrawAll() or DrawShapeToBuffer()

Adding a New Shape Type

  1. Follow steps for adding algorithm above
  2. Implement mouse handling logic in HandleMouseClick()
  3. Add preview drawing in HandleMouseMove() if needed

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A comprehensive Windows-based 2D graphics application implementing various computer graphics algorithms for drawing lines, circles, ellipses, polygons, curves, and filling shapes. Built using the Windows API (Win32) and C++.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages