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++.
- Features
- Implemented Algorithms
- Project Structure
- Requirements
- Building the Project
- Usage
- Extending the Project
- License
- 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
- 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
- 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
- Direct Ellipse - Direct mathematical ellipse
- Polar Ellipse - Polar coordinate ellipse
- Bresenham's Ellipse (Midpoint) - Integer-based efficient ellipse
- General Polygon - N-sided polygon with Bresenham lines
- Rectangle - Axis-aligned rectangle
- Square - Equal-sided rectangle
- Bezier Curves - Smooth parametric curves
- Hermite Curves - Tangent-based smooth curves
- Cardinal Splines - Interpolating spline curves
-
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
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
- 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
- Windows API (Win32) - Pre-installed with Windows SDK
- Standard C++ Library (C++17)
- Clone the repository:
git clone https://github.com/Hemdan47/2D-Graphics-Toolkit.git
cd 2D-Graphics-Toolkit- Create build directory:
mkdir build
cd build- Generate build files:
cmake ..- Build the project:
cmake --build . --config Release- Run the executable:
# From the build directory
cd Release
./2D-Graphics-Toolkit.exe
# Or from the build directory directly
./Release/2D-Graphics-Toolkit.exe- Open CLion
- Select File โ Open and choose the project directory
- CLion will automatically detect CMakeLists.txt
- Click the Build button (hammer icon) or press
Ctrl+F9 - Click Run (play icon) or press
Shift+F10
- Open Visual Studio
- Select File โ Open โ CMake
- Choose the
CMakeLists.txtfile - Wait for CMake to configure
- Select Build โ Build All or press
Ctrl+Shift+B - Run with Debug โ Start Without Debugging or press
Ctrl+F5
- Launch the application - A window will open with a menu bar
- Select a drawing algorithm from the Shapes menu:
- Choose from Lines, Circles, Ellipses, Polygons, or Curves
- 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
- The shape appears using the selected algorithm
- Open the Colors menu
- Select from:
- Black
- Red
- Green
- Blue
- White
- Draw a closed shape (circle, polygon, etc.)
- Select a fill mode from the Fill menu
- Click inside the shape to fill it
- New Canvas: File โ New (clears current drawing)
- Save Drawing: File โ Save (saves to .bin file)
- Load Drawing: File โ Load (loads from .bin file)
- Shapes โ Lines โ Choose algorithm (DDA, Bresenham, or Parametric)
- Click for start point
- Click for end point
- Shapes โ Circles โ Choose algorithm
- Click for center point
- Click to define radius
- Shapes โ Ellipses โ Choose algorithm
- Click for center point
- Click to define semi-major axis length
- Shapes โ Polygon
- Click to add vertices (as many as needed)
- Right-click to close polygon
- Shapes โ Curves โ Choose type (Bezier, Hermite, Cardinal)
- Click to add control points
- Right-click when done
- Declare function in appropriate header file (e.g.,
LineAlgorithms.h) - Implement algorithm in corresponding source file
- Add menu constant in
GraphicsTypes.h - Update
DrawingModeenum - Add menu item in
Window.cppโInitializeMenus() - Handle menu command in
HandleMenuCommand() - Add drawing case in
RedrawAll()orDrawShapeToBuffer()
- Follow steps for adding algorithm above
- Implement mouse handling logic in
HandleMouseClick() - Add preview drawing in
HandleMouseMove()if needed
This project is licensed under the MIT License - see the LICENSE file for details.