update documentation to include reticles and vector math
It's probably not very good though.
This commit is contained in:
parent
37c575748b
commit
fd3f37d744
2 changed files with 339 additions and 170 deletions
|
@ -63,45 +63,96 @@ Additionally, the syntax `a | b` may be used to signify that one of the listed t
|
|||
-
|
||||
a : number
|
||||
-> number
|
||||
|
||||
-
|
||||
a : vector
|
||||
-> vector
|
||||
```
|
||||
|
||||
`-`, when used in its unary form `-x`, returns the number `x` with the opposite sign.
|
||||
When used on vectors, returns the same vector facing the reverse direction (the individual components are negated.)
|
||||
|
||||
This operation is not defined for colors, because it doesn't make sense to have a color with negative RGBA values.
|
||||
|
||||
```haku
|
||||
+
|
||||
a : number
|
||||
b : number
|
||||
-> number
|
||||
|
||||
+
|
||||
a : vector
|
||||
b : vector
|
||||
-> vector
|
||||
|
||||
+
|
||||
a : rgba
|
||||
b : rgba
|
||||
-> rgba
|
||||
```
|
||||
|
||||
`+` adds two numbers together.
|
||||
`+` adds two numbers, vectors, or colors together.
|
||||
|
||||
```haku
|
||||
-
|
||||
a : number
|
||||
b : number
|
||||
-> number
|
||||
|
||||
-
|
||||
a : vector
|
||||
b : vector
|
||||
-> vector
|
||||
|
||||
-
|
||||
a : rgba
|
||||
b : rgba
|
||||
-> rgba
|
||||
```
|
||||
|
||||
`-`, when used in its binary form `x - y`, subtracts two numbers from one another.
|
||||
`-`, when used in its binary form `x - y`, subtracts two numbers, vectors, or colors from one another.
|
||||
|
||||
```haku
|
||||
*
|
||||
a : number
|
||||
b : number
|
||||
-> number
|
||||
|
||||
*
|
||||
a : vector
|
||||
b : vector
|
||||
-> vector
|
||||
|
||||
*
|
||||
a : rgba
|
||||
b : rgba
|
||||
-> rgba
|
||||
```
|
||||
|
||||
`*` multiplies two numbers together.
|
||||
When used on vectors, it scales them component-wise.
|
||||
Likewise for colors.
|
||||
|
||||
```haku
|
||||
/
|
||||
a : number
|
||||
b : number
|
||||
-> number
|
||||
|
||||
/
|
||||
a : vector
|
||||
b : vector
|
||||
-> vector
|
||||
|
||||
/
|
||||
a : rgba
|
||||
b : rgba
|
||||
-> rgba
|
||||
```
|
||||
|
||||
`/` divides a number by another number.
|
||||
When used on vectors, it divides them component-wise.
|
||||
Likewise for colors.
|
||||
|
||||
```haku
|
||||
floor
|
||||
|
@ -324,7 +375,7 @@ The following functions are used to compare values and work with `boolean`s.
|
|||
-> boolean
|
||||
```
|
||||
|
||||
If `b` is `()` or `False`, `not` returns `true`.
|
||||
If `b` is `()` or `False`, `not` returns `True`.
|
||||
Otherwise it returns `False`.
|
||||
|
||||
```haku
|
||||
|
@ -459,25 +510,6 @@ vecW
|
|||
|
||||
---
|
||||
|
||||
Note that mathematical operations are currently not defined for vectors.
|
||||
You may define your own vector operations like so:
|
||||
|
||||
```haku
|
||||
-- Vector addition
|
||||
addv = \a, b ->
|
||||
vec (vecX a + vecX b) (vecY a + vecY b) (vecZ a + vecZ b) (vecW a + vecW b)
|
||||
|
||||
-- Likewise for subtraction, multiplication, and division.
|
||||
```
|
||||
|
||||
Note that haku-defined vector operations like these are more costly the more components they operate on.
|
||||
Therefore, it's recommended to only define them for two dimensions, unless you really need more.
|
||||
|
||||
```haku
|
||||
addv2 = \a, b ->
|
||||
vec (vecX a + vecX b) (vecY a + vecY b)
|
||||
```
|
||||
|
||||
## Colors
|
||||
|
||||
```haku
|
||||
|
@ -520,6 +552,7 @@ For example, consider multiplicatively blending two colors.
|
|||
|
||||
```haku
|
||||
-- This is how you can multiply two colors together.
|
||||
-- Note that the `*` operator works for colors, so you don't need to define this in your brushes.
|
||||
mulRgba = \a, b ->
|
||||
rgba (rgbaR a * rgbaR b) (rgbaG a * rgbaG b) (rgbaB a * rgbaB b) (rgbaA a * rgbaA b)
|
||||
```
|
||||
|
@ -539,12 +572,12 @@ mulRgba = \a, b ->
|
|||
Note that haku does not clamp colors to the `0` to `1` range.
|
||||
It is perfectly valid to have a color that is out of range or even `NaN`, but when drawing scribbles:
|
||||
|
||||
- any number less than `0` is clamped to `0`.
|
||||
- any number greater than `1` is clamped to `1`.
|
||||
- `∞` is clamped back to `1`.
|
||||
- `-∞` is clamped back to `0`.
|
||||
- any scribble with a `NaN` color is ignored.
|
||||
|
||||
Note that just like vectors, arithmetic operations on colors are currently not defined.
|
||||
|
||||
Before scribbles are drawn to the wall, colors are converted to 8-bit integers for more efficient rasterization and storage.
|
||||
This means some loss of precision will happen, which may cause issues with brushes like this one:
|
||||
|
||||
|
@ -625,7 +658,7 @@ stroke
|
|||
|
||||
Creates a stroke scribble, which outlines the provided shape with a stroke of the given thickness and color.
|
||||
|
||||
Point shapes are drawn as squares, and `line` shapes have square caps at the line's endpoints.
|
||||
Point shapes are drawn as circles, and `line` shapes have round caps at the line's endpoints.
|
||||
|
||||
```haku
|
||||
fill
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue