introduce tags, structs, and reticles
this was meant to be split into smaller changes, but I realised I edited my existing revision too late.
This commit is contained in:
parent
8356b6c750
commit
5b7d9586ea
26 changed files with 1113 additions and 351 deletions
70
docs/rkgk.dj
70
docs/rkgk.dj
|
@ -27,7 +27,8 @@ In case you edited anything in the input box on the right, paste the following t
|
|||
-- Try playing around with the numbers,
|
||||
-- and see what happens!
|
||||
|
||||
stroke 8 #000 (vec 0 0)
|
||||
withDotter \d ->
|
||||
stroke 8 #000 (d To)
|
||||
```
|
||||
|
||||
rakugaki is a drawing program for digital scribbles and other pieces of art.
|
||||
|
@ -83,10 +84,11 @@ If you want to draw multiple scribbles, you can wrap them into a list, which we
|
|||
|
||||
```haku
|
||||
-- Draw two colorful dots instead of one!
|
||||
[
|
||||
stroke 8 #F00 (vec 4 0)
|
||||
stroke 8 #00F (vec (-4) 0))
|
||||
]
|
||||
withDotter \d ->
|
||||
[
|
||||
stroke 8 #F00 (vec ((vecX (d To)) + 4) (vecY (d To)))
|
||||
stroke 8 #00F (vec ((vecX (d To)) - 4) (vecY (d To)))
|
||||
]
|
||||
```
|
||||
|
||||
::: aside
|
||||
|
@ -103,25 +105,29 @@ And what's even crazier is that you can compose lists _further_---you can make a
|
|||
It'll draw the first inner list, which contains two scribbles, and then it'll draw the second inner list, which contains two scribbles.
|
||||
|
||||
```haku
|
||||
[
|
||||
withDotter \d ->
|
||||
[
|
||||
stroke 8 #F00 (vec 4 (-4))
|
||||
stroke 8 #00F (vec (-4) (-4))
|
||||
[
|
||||
stroke 8 #F00 (vec ((vecX (d To)) + 4) (vecY (d To)))
|
||||
stroke 8 #00F (vec ((vecX (d To)) - 4) (vecY (d To)))
|
||||
]
|
||||
[
|
||||
stroke 8 #FF0 (vec (vecX (d To)) ((vecY (d To)) + 4))
|
||||
stroke 8 #0FF (vec (vecX (d To)) ((vecY (d To)) - 4))
|
||||
]
|
||||
]
|
||||
[
|
||||
stroke 8 #FF0 (vec 4 4)
|
||||
stroke 8 #0FF (vec (-4) 4)
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
::: aside
|
||||
|
||||
Another weird thing: when negating a number, you have to put it in parentheses.
|
||||
I know this example is kind of horrendous to read right now.
|
||||
|
||||
This is because haku does not see your spaces---`vec -4`, `vec - 4`, and `vec-4` all mean the same thing!
|
||||
In this case, it will always choose the 2nd interpretation---vec minus four.
|
||||
So to make it interpret our minus four as, well, _minus four_, we need to enclose it in parentheses.
|
||||
This is because haku currently does not have vector math, which means we have to disassemble and reassemble vectors manually.
|
||||
|
||||
{% Another weird thing: when negating a number, you have to put it in parentheses. %}
|
||||
{% This is because haku does not see your spaces---`vec -4`, `vec - 4`, and `vec-4` all mean the same thing! %}
|
||||
{% In this case, it will always choose the 2nd interpretation---vec minus four. %}
|
||||
{% So to make it interpret our minus four as, well, _minus four_, we need to enclose it in parentheses. %}
|
||||
|
||||
:::
|
||||
|
||||
|
@ -142,15 +148,24 @@ Anyways!
|
|||
Recall that super simple brush from before...
|
||||
|
||||
```haku
|
||||
stroke 8 #000 (vec 0 0)
|
||||
withDotter \d ->
|
||||
stroke 8 #000 (d To)
|
||||
```
|
||||
|
||||
This reads as "a stroke that's 8 pixels wide, has the color `#000`, and is drawn at the point `(0, 0)` relative to the mouse cursor."
|
||||
This reads as "given a dotter, output a stroke that's 8 pixels wide, has the color `#000`, and is drawn at the dotter's `To` coordinates."
|
||||
|
||||
All these symbols are very meaningful to haku.
|
||||
If you reorder or remove any one of them, your brush isn't going to work!
|
||||
|
||||
- Reading from left to right, we start with `stroke`.\
|
||||
- Reading from left to right, we start with `withDotter`.
|
||||
We can't draw without knowing _where_ to draw, and the `withDotter` incantation lets us ask the UI for that.
|
||||
|
||||
- Then, `\d ->` lets us name the data we get back from the UI.
|
||||
`d` ends up containing a few useful properties, but the most useful one for us is `To`, which contains the current mouse position (where *`To`* draw).
|
||||
|
||||
- We'll get to what all these sigils mean to haku later!
|
||||
|
||||
- On the next line we have a `stroke`.
|
||||
`stroke` is a _function_---a recipe for producing data!\
|
||||
haku has [many such built-in recipes](/docs/system.html).
|
||||
`stroke` is one of them.
|
||||
|
@ -192,7 +207,8 @@ Note how it's parenthesized though---recall that function arguments are separate
|
|||
And with all that, we let haku mix all the ingredients together, and get a black dot under the cursor.
|
||||
|
||||
```haku
|
||||
stroke 8 #000 (vec 0 0)
|
||||
withDotter \d ->
|
||||
stroke 8 #000 (d To)
|
||||
```
|
||||
|
||||
Nice!
|
||||
|
@ -206,8 +222,16 @@ So to spice things up, haku has a few shapes you can choose from!
|
|||
Recall that 3rd argument to `stroke`.
|
||||
We can actually pass any arbitrary shape to it, and haku will outline it for us.
|
||||
|
||||
Right now haku supports two additional shapes: rectangles and circles.
|
||||
You can try them out by playing with this brush!
|
||||
The experience of drawing with that example brush is pretty crap, because it can draw dots that don't connect with each other at all.
|
||||
Let's fix that by drawing a `line` instead!
|
||||
|
||||
```haku
|
||||
withDotter \d ->
|
||||
stroke 8 #000 (line (d From) (d To))
|
||||
```
|
||||
|
||||
We replace the singular position `d To` with a `line`. `line` expects two arguments, which are vectors defining the line's start and end points.
|
||||
For the starting position we use a _different_ property of `d`, which is `From`---this is the _previous_ value of `To`, which allows us to draw a continuous line.
|
||||
|
||||
```haku
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue