diff --git a/README.md b/README.md index c26662e..0146936 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/examples/blur.nim b/examples/blur.nim new file mode 100644 index 0000000..70c53d4 --- /dev/null +++ b/examples/blur.nim @@ -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") diff --git a/examples/blur.png b/examples/blur.png new file mode 100644 index 0000000..4f32190 Binary files /dev/null and b/examples/blur.png differ diff --git a/examples/data/trees.png b/examples/data/trees.png new file mode 100644 index 0000000..1f2a886 Binary files /dev/null and b/examples/data/trees.png differ diff --git a/examples/rounded_rectangle.nim b/examples/rounded_rectangle.nim index 28f5896..6164ec0 100644 --- a/examples/rounded_rectangle.nim +++ b/examples/rounded_rectangle.nim @@ -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") diff --git a/examples/square.nim b/examples/square.nim index 446b6ea..3155e18 100644 --- a/examples/square.nim +++ b/examples/square.nim @@ -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") diff --git a/tools/gen_readme.nim b/tools/gen_readme.nim index 960b51f..3ab7819 100644 --- a/tools/gen_readme.nim +++ b/tools/gen_readme.nim @@ -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"