Add gradient and tiled example.

This commit is contained in:
treeform 2021-02-25 08:57:49 -08:00
parent 8032c9963c
commit 84b8410cef
7 changed files with 73 additions and 0 deletions

View file

@ -165,6 +165,54 @@ image.draw(lines)
``` ```
![example output](examples/masking.png) ![example output](examples/masking.png)
### Gradient
[examples/gradient.nim](examples/gradient.nim)
```nim
image.fillPath(
"""
M 20 60
A 40 40 90 0 1 100 60
A 40 40 90 0 1 180 60
Q 180 120 100 180
Q 20 120 20 60
z
""",
Paint(
kind:pkGradientRadial,
gradientHandlePositions: @[
vec2(100, 100),
vec2(200, 100),
vec2(100, 200)
],
gradientStops: @[
ColorStop(color:rgba(255, 0, 0, 255).color, position: 0),
ColorStop(color:rgba(255, 0, 0, 40).color, position: 1.0),
]
)
)
```
![example output](examples/gradient.png)
### Image tiled
[examples/image_tiled.nim](examples/image_tiled.nim)
```nim
var path: Path
path.polygon(
vec2(100, 100),
70,
sides = 8
)
image.fillPath(
path,
Paint(
kind:pkImageTiled,
image: readImage("tests/images/png/baboon.png"),
imageMat:scale(vec2(0.08, 0.08))
)
)
```
![example output](examples/image_tiled.png)
### Shadow ### Shadow
[examples/shadow.nim](examples/shadow.nim) [examples/shadow.nim](examples/shadow.nim)
```nim ```nim

BIN
examples/gradient.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

23
examples/image_tiled.nim Normal file
View file

@ -0,0 +1,23 @@
import pixie
let
image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var path: Path
path.polygon(
vec2(100, 100),
70,
sides = 8
)
image.fillPath(
path,
Paint(
kind:pkImageTiled,
image: readImage("tests/images/png/baboon.png"),
imageMat:scale(vec2(0.08, 0.08))
)
)
image.writeFile("examples/image_tiled.png")

BIN
examples/image_tiled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -16,6 +16,8 @@ var exampleFiles = [
"examples/rounded_rectangle.nim", "examples/rounded_rectangle.nim",
"examples/heart.nim", "examples/heart.nim",
"examples/masking.nim", "examples/masking.nim",
"examples/gradient.nim",
"examples/image_tiled.nim",
"examples/shadow.nim", "examples/shadow.nim",
"examples/blur.nim", "examples/blur.nim",
"examples/tiger.nim" "examples/tiger.nim"