https://github.com/aminehabchi/drawing
Drawing various geometric shapes on a image in rust and java
https://github.com/aminehabchi/drawing
abstraction geometry interface oop polymorphism rust trait
Last synced: about 1 month ago
JSON representation
Drawing various geometric shapes on a image in rust and java
- Host: GitHub
- URL: https://github.com/aminehabchi/drawing
- Owner: aminehabchi
- Created: 2025-05-13T08:59:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-15T22:46:16.000Z (10 months ago)
- Last Synced: 2025-11-13T16:37:40.428Z (7 months ago)
- Topics: abstraction, geometry, interface, oop, polymorphism, rust, trait
- Language: Java
- Homepage:
- Size: 41.8 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust Geometric Drawing Library

## Overview
This project is a Rust library for drawing various geometric shapes on a raster image. The implementation uses a trait-based system for shape rendering with a clever design that separates drawing behavior from display logic.
## Core Concepts
### Traits
The library is built around two key traits:
1. **Drawable** - Defines how shapes are drawn on an image
- Provides default implementation for random color generation
- Each shape implements its own draw method
2. **Displayable** - Abstracts the actual pixel-setting operation
- Allows separation between drawing logic and the display medium
- Makes the library adaptable to different output types
### Shapes
The library includes implementations for the following shapes:

**Points**: The simplest geometric element, a single pixel on the screen. Points can be created with specific coordinates or randomly generated within image bounds.


**Lines**: Connect two points with a line-drawing algorithm that ensures smooth lines are drawn between any two arbitrary points, handling all edge cases.

**Circles**: Defined by a center point and radius. The implementation uses a sophisticated algorithm to approximate a circle on a pixel grid, optimizing for visual smoothness.
**Triangles**: Created from three points. The implementation draws three lines connecting the points to form a triangle.
**Rectangles**: Defined by two opposite corners. The implementation draws four lines to form a rectangle aligned with the coordinate axes.

**Cubes**: Created from two rectangles representing the front and back faces, with connecting lines to create a 3D perspective.
## Technical Highlights
- **Efficient Line Drawing**: A custom algorithm that determines the most appropriate pixels to light up
- **Random Shape Generation**: Support for creating random instances of each shape type
- **Color Management**: Automatic random color generation for visual variety
- **Boundary Checking**: Safe pixel plotting that respects image boundaries
- **Modular Design**: Clean separation of concerns with traits and structs
## Applications
This library can be used for:
- Education: Demonstrating basic computer graphics concepts
- Visualization: Creating simple geometric visualizations
- Art Generation: Producing abstract geometric art
- Game Development: Building simple 2D graphics engines
## Dependencies
- `raster` - For image manipulation and saving
- `rand` - For random number generation