https://github.com/enzet/iconscript
Generating icons using text commands
https://github.com/enzet/iconscript
antlr go icons
Last synced: 29 days ago
JSON representation
Generating icons using text commands
- Host: GitHub
- URL: https://github.com/enzet/iconscript
- Owner: enzet
- Created: 2022-08-28T13:21:52.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-23T19:18:49.000Z (over 3 years ago)
- Last Synced: 2025-01-05T13:43:49.634Z (over 1 year ago)
- Topics: antlr, go, icons
- Language: Go
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# iconscript
iconscript is a language for describing pixel-wise pictograms in the style of the [Röntgen](https://github.com/enzet/Roentgen) project.
The grammar of the language is described in the ANTLR4 `grammar/IconScript.g4` file.
## SVG generation
There are two implementations of iconscript for parsing and generating SVG files.
* **Rust**: `cargo install iconscript`. Rust implementation is *faster* and *more reliable*. It uses [`linesweeper`](https://docs.rs/linesweeper/latest/linesweeper/) library for Boolean path operations and SVG optimizations.
* **JavaScript** (TypeScript): `npm install iconscript`. JavaScript implementation uses [Paper.js](http://paperjs.org/) library, that may produce wrong outputs.
## Syntax
Syntax slightly resembles the syntax of path commands in SVG. Positions on the plane are coded as two floating point number separated by comma: `,` or `+,`. `+` means that the position is relative to the `position`.
If current position is (5, 5), `+1,2` will give (6, 7) and update current position to (6, 7) as well.
### Global context
* `position` — vector of two floats, current position of the cursor.
* `width` — float, stroke width.
* `fill` — Boolean, whether objects should be filled.
### Commands
| **Command** | **Description** |
|---|---|
| `subtract` | Set subtraction mode |
| `fill` | Set fill mode |
| `w ` | Set `width` to a value |
| `m ` | Set `position` to a value |
| `l []` | Draw lines between positions |
| `e ` | Draw circle specified by center point and radius |
| `r ` | Draw rectangle specified by top left and bottom right points |
| `a ` | Draw arc specified by center point, radius, and two angles in radians |
### Variables
Variables can be defined with ` = []` and accessed with `@`.
### Scopes
Scopes group commands together using `{` and `}`. They can be nested and are used to incapsulate context changes.
### Example
```iconscript
square = fill r +0,0 +2,2
icon glider = {
m 6,2 @square m +4,4 @square
m +-8,4 @square m +4,0 @square m +4,0 @square
}
```
This code defines a square (`lf`, filled line — polygon with 5 points). It then reuses `square` variable 5 times to draw a glider.