Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Paint OOPS - a shapes editor in C++ and OpenGL

Language: C++ Graphics Platforms License: MIT

A paint and shapes editor written in C++ with OpenGL/GLUT, built to exercise the whole OOP toolbox: a shape class hierarchy with inheritance, encapsulation, polymorphism, and one deliberate case of multiple inheritance.


What is this?

A classic MS-Paint-style canvas where every drawable thing is an object. Point is the root of the hierarchy; lines, circles, polygons, and rectangles specialize it. Drawing happens through GLUT mouse callbacks, and every tool and option lives in a right-click context menu.

Paint canvas with polygons, rectangles, circles and brush strokes

Features

  • Shapes: point, line, rectangle (filled or outline), circle, and regular polygons with 3 to 20 edges (at 20 they visually converge to a circle)
  • Brushes: airbrush (4 to 16 px) and a radial brush mode
  • Eraser in three sizes
  • Undo / redo / clear, from the keyboard or the menu
  • 7 colours including a random mode, plus border thickness control (2 to 6 px)
  • Everything reachable from a right-click GLUT menu, no toolbar chrome

More sessions:

Radial brush All features
Radial brush stroke Canvas with many shapes
Radial brush variation

Controls

Keyboard

Key Action
q / Esc Quit
c Clear the canvas
+ / - Increase / decrease brush or polygon size
u Undo
r Redo

Right-click menu

Colour        > Red · Green · Blue · Purple · Yellow · Black · Random
Shapes        > Point · Line · Rectangle (Fill/Unfill) · Circle
              > Airbrush (4/8/12/16 px) · Polygon (3..20 edges)
Radial Brush  > On · Off
Border        > 2 · 4 · 5 · 6 px
Eraser        > Small · Medium · Large
Undo · Redo · Clear · Quit

The class hierarchy

This is the point of the project: shapes as a type family.

classDiagram
    Point <|-- shape
    Point <|-- line
    shape <|-- circle
    shape <|-- Polygon
    Polygon <|-- Rectangle
    line <|-- Rectangle

    class Point {
        -int newX
        -int newY
        -float newR
        -float newG
        -float newB
        -int s
        +getX()
        +getY()
        +setPosition(x, y)
        +setColour(r, g, b)
    }
    class shape {
        #int flag
        +setflag(f)
    }
    class line {
        #float sx1
        #float sy1
        #float sx2
        #float sy2
        +drawLine(sx, sy, ex, ey)
    }
    class circle {
        #float cx
        #float cy
        #float px
        #float py
        +drawCircle(x, y, x1, y1)
    }
    class Polygon {
        #int edges
        #int length
        #float peri
        #float interior
        #float exterior
        +perimeter()
        +int_ext()
        +draw_polygon(x1, y1, x2, y2)
    }
    class Rectangle {
        #int dx1
        #int dy1
        #int dx2
        #int dy2
        +drawRectangle(x1, y1, x2, y2)
    }
Loading
  • Encapsulation: Point keeps position, colour, and size private behind getters/setters
  • Inheritance: shape adds a curve/polygon flag; circle and Polygon build on it
  • Multiple inheritance: Rectangle derives from both Polygon and line, reusing polygon math and line drawing
  • Polymorphism: every drawn shape decomposes into base-class Point objects held in a single vector<Point>; undo/redo rewinds and replays ranges of that vector

Build and run

Linux

sudo apt install g++ freeglut3-dev
cd src
make        # builds and launches ./Paint

macOS

The same makefile detects Darwin and links against the system OpenGL and GLUT frameworks:

cd src
make

Project structure

Paint_OOPS/
├── src/
│   ├── main.cpp        # GLUT setup, menus, mouse/keyboard callbacks, undo/redo
│   ├── point.cpp/.h    # Point: position, colour, size (root of the hierarchy)
│   ├── shapes.cpp/.h   # shape: curve-vs-polygon flag
│   ├── line.cpp/.h     # line drawing
│   ├── curve.cpp/.h    # circle
│   ├── polygon.cpp/.h  # Polygon + Rectangle (multiple inheritance)
│   └── makefile
├── Output/             # Screenshots from real sessions
└── docs/               # Logo + original project presentation (pptx)

License

MIT

About

MS-Paint-style shapes editor in C++ with OpenGL/GLUT. A full OOP class hierarchy: inheritance, encapsulation, polymorphism, and multiple inheritance, with undo/redo, brushes and 3-20 edge polygons.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages