This project is an exercise in using traits, modules, and image processing in Rust. The goal is to draw various geometrical shapes on a canvas and generate an image as output.
main.rs: Entry point, contains the logic for image creation.geometrical_shapes.rs: Module with shape definitions and trait implementations.
-
Traits:
Drawable: with methodsdraw(&mut Image)andcolor(&self) -> Color.Displayable: with methoddisplay(&mut self, x: i32, y: i32, color: Color).
-
Structs (with a
newconstructor as specified):Point: from twoi32values.Line: from references to twoPoints.Triangle: from references to threePoints.Rectangle: from references to twoPoints.Circle: from centerPointand radiusi32.
-
Can't find the isolated
Point?- The isolated
Pointis there, all other shapes are formed usingPoint, so its existence is sufficient proof of the Point's presence. Noticing the Point is often hard due to its samll size (1px); also due to the random cordinate logic, it could collid with another shape.
- The isolated
-
What algorithm followed in
Lineformation ?- DDA algorithm (Digital Differential Analyzer).
-
What algorithm followed in
Circleformation ?- Midpoint algorithm (8 symmetric of Bresenham).
