updated examples

This commit is contained in:
Ryan Oldenburg 2021-01-29 14:17:24 -06:00
parent c65acc6cd7
commit 0b60f4ddd4
8 changed files with 31 additions and 15 deletions

View file

@ -21,13 +21,16 @@ This library is being actively developed and is not yet ready for use. Since you
### Blur
[examples/blur.nim](examples/blur.nim)
```nim
var p = newPath()
var p: Path
p.polygon(100, 100, 70, sides=6)
p.closePath()
var mask = newImage(200, 200)
let mask = newImage(200, 200)
mask.fillPath(p, rgba(255, 255, 255, 255))
blur.blur(20)
blur.draw(mask, blendMode = bmMask)
image.draw(trees)
image.draw(blur)
```
@ -36,19 +39,21 @@ image.draw(blur)
### Rounded rectangle
[examples/rounded_rectangle.nim](examples/rounded_rectangle.nim)
```nim
var path = newPath()
let
x = 50.0
y = 50.0
w = 100.0
h = 100.0
r = 25.0
var path: Path
path.moveTo(x+r, y)
path.arcTo(x+w, y, x+w, y+h, r)
path.arcTo(x+w, y+h, x, y+h, r)
path.arcTo(x, y+h, x, y, r)
path.arcTo(x, y, x+w, y, r)
path.closePath()
image.fillPath(path, rgba(255, 0, 0, 255))
```
![example output](examples/rounded_rectangle.png)
@ -56,12 +61,13 @@ image.fillPath(path, rgba(255, 0, 0, 255))
### Square
[examples/square.nim](examples/square.nim)
```nim
var p = newPath()
var p: Path
p.moveTo(50, 50)
p.lineTo(50, 150)
p.lineTo(150, 150)
p.lineTo(150, 50)
p.closePath()
image.fillPath(p, rgba(255, 0, 0, 255))
```
![example output](examples/square.png)
@ -69,7 +75,8 @@ image.fillPath(p, rgba(255, 0, 0, 255))
### Tiger
[examples/tiger.nim](examples/tiger.nim)
```nim
var tiger = readImage("examples/data/tiger.svg")
let tiger = readImage("examples/data/tiger.svg")
image.draw(
tiger,
translate(vec2(100, 100)) *

View file

@ -1,17 +1,22 @@
import pixie, chroma, vmath
var trees = readImage("examples/data/trees.png")
var blur = trees.copy()
var image = newImage(200, 200)
let
trees = readImage("examples/data/trees.png")
blur = trees.copy()
image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var p = newPath()
var p: Path
p.polygon(100, 100, 70, sides=6)
p.closePath()
var mask = newImage(200, 200)
let mask = newImage(200, 200)
mask.fillPath(p, rgba(255, 255, 255, 255))
blur.blur(20)
blur.draw(mask, blendMode = bmMask)
image.draw(trees)
image.draw(blur)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View file

@ -1,21 +1,23 @@
import pixie, chroma
var image = newImage(200, 200)
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var path = newPath()
let
x = 50.0
y = 50.0
w = 100.0
h = 100.0
r = 25.0
var path: Path
path.moveTo(x+r, y)
path.arcTo(x+w, y, x+w, y+h, r)
path.arcTo(x+w, y+h, x, y+h, r)
path.arcTo(x, y+h, x, y, r)
path.arcTo(x, y, x+w, y, r)
path.closePath()
image.fillPath(path, rgba(255, 0, 0, 255))
image.writeFile("examples/rounded_rectangle.png")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -3,12 +3,13 @@ import pixie, chroma
var image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var p = newPath()
var p: Path
p.moveTo(50, 50)
p.lineTo(50, 150)
p.lineTo(150, 150)
p.lineTo(150, 50)
p.closePath()
image.fillPath(p, rgba(255, 0, 0, 255))
image.writeFile("examples/square.png")

View file

@ -1,9 +1,10 @@
import pixie, chroma, vmath
var image = newImage(200, 200)
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var tiger = readImage("examples/data/tiger.svg")
let tiger = readImage("examples/data/tiger.svg")
image.draw(
tiger,
translate(vec2(100, 100)) *

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB