Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Unreleased

- **Breaking change**: unify syntax
([#2](https://github.com/enzet/iconscript/issues/9)).
- Add `fill` command.
- Remove `lf` command.
- Make `r` and `e` respect fill and width scope parameters.

# 0.2.0

- **Breaking change**: use SVG path commands format
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@ Syntax slightly resembles the syntax of path commands in SVG.

### Global context

- `width` — stroke width.
- `position` — current position of the cursor.
- `width` — float, stroke width.
- `position` — vector (float, float), current position of the cursor.
- `fill` -- Boolean, whether objects should be filled.

### Commands

`<vector>` is 2D coordinates in the form `<x>,<y>` or `+<x>,<y>` (`+` means
that the position is relative to the __position__).

| Command | Description |
| ------------------------------------ | --------------------------------------------------------------------------------- |
| `subtract` | Set subtraction mode |
| `w <float>` | Set `width` to a value |
| `m <vector>` | Set `position` to a value |
| `l [<vector>]` | Draw lines between positions |
| `lf [<vector>]` | Draw filled lines between positions |
| `e <vector> <float>` | Draw circle specified by center point and radius |
| `r <vector> <vector>` | Draw rectangle specified by top left and bottom right points |
| `a <vector> <float> <float> <float>` | Draw arc specified by center point, radius, start angle, and end angle in radians |
| Command | Description |
| ----------------------------------------------- | ------------------------- |
| `subtract` | Set subtraction mode |
| `fill` | Set fill mode |
| `m <point>` | Set `position` to a value |
| `w <width>` | Set `width` to a value |
| `l [<point>]` | Draw polyline |
| `r <top left point> <bottom right point>` | Draw rectangle |
| `e <center> <radius>` | Draw circle |
| `a <center> <radius> <start angle> <end angle>` | Draw arc |

### Variables

Expand All @@ -57,12 +58,12 @@ used to incapsulate context changes.
### Example

```iconscript
square = lf +0,0 +2,0 +0,2 +-2,0 +0,-2
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.
This code defines a square (filled rectangle). It then reuses `square` variable
5 times to draw a glider.
File renamed without changes.
8 changes: 6 additions & 2 deletions js/doc/public.moi → doc/public.moi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
\javascript {iconscript-parser.bundle.min.js}
\javascript {iconscript-ui.bundle.min.js}

iconscript is a simple language for describing simple pixel-wise pictograms in
the style of the \ref {#roentgen} {Röntgen} project.
iconscript is a language for describing pixel-wise pictograms in the style of
the \ref {#roentgen} {Röntgen} project implemented in Rust and TypeScript. You
can install it with:
\list
{\c {cargo install iconscript }— fast Rust implementation,}
{\c {npm install iconscript }— TypeScript implementation used on this page.}

\html {
<div class="container">
Expand Down
62 changes: 62 additions & 0 deletions doc/syntax.moi
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
\2 {Syntax} {iconscript_syntax}

Syntax slightly resembles the syntax of path commands in \abbr {SVG}. Positions
on the plane are coded as two floating point number separated by comma:
\c {\formal {x},\formal {y}} or \c {+\formal {x},\formal {y}}.
\c {+} means that the position is relative to the \c {position}.

If current position is (5, 5), `+1,2` will give (6, 7) and update current
position to (6, 7) as well.

\3 {Global context} {iconscript_global_context}

\list
{\c {position} — vector of two floats, current position of the cursor.}
{\c {width} — float, stroke width.}
{\c {fill} — Boolean, whether objects should be filled.}

\3 {Commands} {iconscript_commands}

\table
{{\b {Command}} {\b {Description}}}
{{\c {\skw {subtract}}} {Set subtraction mode}}
{{\c {\skw {fill}}} {Set fill mode}}
{{\c {\skw {w} \formal {float}}} {Set \c {width} to a value}}
{{\c {\skw {m} \formal {position}}} {Set \c {position} to a value}}
{{\c {\skw {l} [\formal {position}]}} {Draw lines between positions}}
{
{\c {\skw {e} \formal {position} \formal {float}}}
{Draw circle specified by center point and radius}
}
{
{\c {\skw {r} \formal {position} \formal {position}}}
{Draw rectangle specified by top left and bottom right points}
}
{
{\c {\skw {a} \formal {position} \formal {float} \formal {float}
\formal {float}}}
{Draw arc specified by center point, radius, and two angles in radians}
}

\3 {Variables} {iconscript_variables}

Variables can be defined with \c {<variable> = [<command>]} and accessed with
\c {@<variable>}.

\3 {Scopes} {iconscript_scopes}

Scopes group commands together using \c {\{} and \c {\}}. They can be nested and
are used to incapsulate context changes.

\3 {Example} {iconscript_example}

\code {iconscript} {
square = \skw {fill} \skw{r} +0,0 +2,2
\skw {icon} glider = \{
\skw {m} 6,2 @square \skw {m} +4,4 @square
\skw {m} +-8,4 @square \skw {m} +4,0 @square \skw {m} +4,0 @square
\}
}

This code defines a square (\c {lf}, filled line — polygon with 5 points). It
then reuses \c {square} variable 5 times to draw a glider.
6 changes: 4 additions & 2 deletions grammar/IconScript.g4
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ command
| rectangle
| setPosition
| setRemove
| setWidth ;
| setWidth
| setFill ;

// Figures.
arc : 'a' position FLOAT FLOAT FLOAT ;
circle : 'e' position FLOAT ;
line : ('l' | 'lf') position+ ;
line : 'l' position+ ;
rectangle : 'r' position position ;

// Icon name.
Expand All @@ -43,3 +44,4 @@ name : IDENTIFIER ;
setPosition : 'm' position ;
setWidth : 'w' FLOAT ;
setRemove : 'subtract' ;
setFill : 'fill' ;
55 changes: 0 additions & 55 deletions js/doc/syntax.moi

This file was deleted.

Loading