Vizzy is a simple graphics language for drawing shapes on a canvas.
I, @TanOfAllCodes am the original author. Vizzy is licensed under the MIT License. See LICENSE for details.
The Vizzy compiler is built on Rust. It implements the following concepts to create a graphics programming language:
- Lexical Analysis: The compiler reads the .vizzy file and breaks it into tokens, like "canvas", "point", or "color". This is done using the Pest parser with parser.pest.
- Parsing: The compiler checks the tokens against grammar rules in parser.pest to build a structure of commands, such as canvas settings or shapes.
- Rules: Grammar rules define valid syntax, like "canvas width= height= color=;". These ensure commands are correct.
- Intermediate Representation (IR): Parsed commands are stored as a list of shapes (e.g., Point, Circle) in memory, forming the IR used for rendering.
Chain of Events:
- The compiler reads the .vizzy file (e.g., main.vizzy).
- Lexical analysis turns the text into tokens.
- Parsing matches tokens to grammar rules.
- Valid commands are converted into an IR (shape objects).
- The IR is rendered onto a canvas to create output.png.
Clone the repository and build Vizzy:
git clone https://github.com/TanOfAllCodes/vizzy
cd vizzy
cargo build --releaseCD into the example-project directory after building Vizzy.
chmod +x run.sh
./run.shcanvas width=800 height=600 color="#FFFFFF";
point x=100 y=100 color="blue";
circle x=200 y=200 radius=50 color="red" fill=true;
rectangle x=300 y=300 width=100 height=80 color="green" fill=false;
Run the program:
./target/release/vizzy example.vizzy output.pngView output.png to see your drawing.
To add a development dependency (e.g., toml-cli for scripts):
Edit Cargo.toml to include it under [dev-dependencies]:
[dev-dependencies]
toml-cli = "0.2"Rebuild the project to install the dependency:
cargo build --releaseTo change the path of the compiler, change the va_config.toml file:
compiler_path = "/home/$USER/Desktop/visualad-workspace/visualad/target/release/vizzy"The Vizzy repository is organized to support the compiler and user projects:
├── example-project # Directory for a sample Vizzy project
│ ├── main.vizzy # Vizzy program with drawing commands
│ ├── output.png # Generated image from running main.vizzy
│ ├── run.sh # Script to execute the Vizzy compiler
│ └── va_config.toml # Config file specifying the compiler path
├── LICENSE.md # MIT license file for the project
├── README.md # Documentation file (this file)
└── vizzy # Directory containing the Vizzy compiler
├── Cargo.lock # Locks dependency versions for reproducibility
├── Cargo.toml # Configures the vizzy binary and dependencies
└── src # Source code for the Vizzy compiler
├── canvas.rs # Handles canvas rendering and colors
├── lib.rs # Core compiler logic and module definitions
├── main.rs # Command-line interface for the compiler
├── parser.pest # Grammar file for parsing .vizzy syntax
├── parser.rs # Logic to parse .vizzy files
└── shapes # Directory for shape definitions
├── arc.rs # Defines arc shape properties and rendering
├── circle.rs # Defines circle shape properties and rendering
├── curve.rs # Defines curve shape properties and rendering
├── ellipse.rs # Defines ellipse shape properties and rendering
├── line.rs # Defines line shape properties and rendering
├── mod.rs # Module declarations for shapes
├── point.rs # Defines point shape properties and rendering
├── quadrilateral.rs # Defines quadrilateral shape properties and rendering
├── rectangle.rs # Defines rectangle shape properties and rendering
└── triangle.rs # Defines triangle shape properties and rendering