Add blur example.

This commit is contained in:
treeform 2020-12-04 08:32:03 -08:00
parent 7067ad62ee
commit 65b14f5dde
7 changed files with 61 additions and 6 deletions

View file

@ -18,6 +18,33 @@ This library is being actively developed and is not yet ready for use. Since you
## Examples
### examples/blur.nim
```nim
var trees = readImage("examples/data/trees.png")
var blur = trees.copy()
blur.blur(10)
var p = newPath()
let
size = 80.0
x = 100.0
y = 100.0
p.moveTo(x + size * cos(0.0), y + size * sin(0.0))
for side in 0 ..< 7:
p.lineTo(
x + size * cos(side.float32 * 2.0 * PI / 6.0),
y + size * sin(side.float32 * 2.0 * PI / 6.0)
)
p.closePath()
var mask = newImage(200, 200)
mask.fillPath(p, rgba(255, 0, 0, 255))
mask.sharpOpacity()
blur.draw(mask, blendMode = bmMask)
image.draw(trees)
image.draw(blur)
```
![example output](examples/blur.png)
### examples/rounded_rectangle.nim
```nim
var path = newPath()
@ -38,7 +65,6 @@ path.arcTo(x, y, x+w, y, nw)
path.closePath()
path.closePath()
image.fillPath(path, rgba(255, 0, 0, 255))
#image.strokePath(path, rgba(0, 0, 0, 255), strokeWidth = 5.0)
```
![example output](examples/rounded_rectangle.png)

29
examples/blur.nim Normal file
View file

@ -0,0 +1,29 @@
import pixie, chroma, vmath
var image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var trees = readImage("examples/data/trees.png")
var blur = trees.copy()
blur.blur(10)
var p = newPath()
let
size = 80.0
x = 100.0
y = 100.0
p.moveTo(x + size * cos(0.0), y + size * sin(0.0))
for side in 0 ..< 7:
p.lineTo(
x + size * cos(side.float32 * 2.0 * PI / 6.0),
y + size * sin(side.float32 * 2.0 * PI / 6.0)
)
p.closePath()
var mask = newImage(200, 200)
mask.fillPath(p, rgba(255, 0, 0, 255))
mask.sharpOpacity()
blur.draw(mask, blendMode = bmMask)
image.draw(trees)
image.draw(blur)
image.writeFile("examples/blur.png")

BIN
examples/blur.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
examples/data/trees.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

View file

@ -1,6 +1,7 @@
import pixie, chroma
var image = newImageFill(200, 200, rgba(255, 255, 255, 255))
var image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var path = newPath()
let
@ -20,6 +21,5 @@ path.arcTo(x, y, x+w, y, nw)
path.closePath()
path.closePath()
image.fillPath(path, rgba(255, 0, 0, 255))
#image.strokePath(path, rgba(0, 0, 0, 255), strokeWidth = 5.0)
image.writeFile("examples/rounded_rectangle.png")

View file

@ -1,6 +1,7 @@
import pixie, chroma
var image = newImageFill(200, 200, rgba(255, 255, 255, 255))
var image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
var p = newPath()
p.moveTo(50, 50)
@ -9,6 +10,5 @@ p.lineTo(150, 150)
p.lineTo(150, 50)
p.closePath()
image.fillPath(p, rgba(255, 0, 0, 255))
#image.strokePath(p, rgba(0, 0, 0, 255), strokeWidth = 5.0)
image.writeFile("examples/square.png")

View file

@ -14,7 +14,7 @@ for k, path in walkDir("examples"):
if path.endsWith(".nim"):
discard execCmd("nim c -r -d:danger " & path)
let code = readFile(path)
let innerCode = code.cutBetween("var image = newImageFill(200, 200, rgba(255, 255, 255, 255))", "image.writeFile")
let innerCode = code.cutBetween("image.fill(rgba(255, 255, 255, 255))", "image.writeFile")
if innerCode != "":
md.add "### " & path.replace("\\", "/")
md.add "```nim"