Skip to content

sadiqui/drawing-shapes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Drawing Shapes in Rust

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.

example

πŸ“ Project Structure

  • main.rs: Entry point, contains the logic for image creation.
  • geometrical_shapes.rs: Module with shape definitions and trait implementations.

πŸ“Œ Code backbone

  1. Traits:

    • Drawable: with methods draw(&mut Image) and color(&self) -> Color.
    • Displayable: with method display(&mut self, x: i32, y: i32, color: Color).
  2. Structs (with a new constructor as specified):

    • Point: from two i32 values.
    • Line: from references to two Points.
    • Triangle: from references to three Points.
    • Rectangle: from references to two Points.
    • Circle: from center Point and radius i32.

❔ FAQ

  1. Can't find the isolated Point ?

    • The isolated Point is there, all other shapes are formed using Point, 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.
  2. What algorithm followed in Line formation ?

  3. What algorithm followed in Circle formation ?

πŸ«‚ Collaborators

About

Rust program that draws various geometrical shapes on a canvas and generate an image as output.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages