Make blur example shorter.
This commit is contained in:
parent
7c4615282a
commit
d1adfba46e
4 changed files with 21 additions and 34 deletions
20
README.md
20
README.md
|
@ -20,26 +20,12 @@ This library is being actively developed and is not yet ready for use. Since you
|
|||
|
||||
### 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.polygon(100, 100, 70, sides=6)
|
||||
p.closePath()
|
||||
|
||||
var mask = newImage(200, 200)
|
||||
mask.fillPath(p, rgba(255, 0, 0, 255))
|
||||
mask.sharpOpacity()
|
||||
mask.fillPath(p, rgba(255, 255, 255, 255))
|
||||
blur.blur(10)
|
||||
blur.draw(mask, blendMode = bmMask)
|
||||
image.draw(trees)
|
||||
image.draw(blur)
|
||||
|
|
|
@ -1,28 +1,16 @@
|
|||
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 image = newImage(200, 200)
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
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.polygon(100, 100, 70, sides=6)
|
||||
p.closePath()
|
||||
|
||||
var mask = newImage(200, 200)
|
||||
mask.fillPath(p, rgba(255, 0, 0, 255))
|
||||
mask.sharpOpacity()
|
||||
mask.fillPath(p, rgba(255, 255, 255, 255))
|
||||
blur.blur(10)
|
||||
blur.draw(mask, blendMode = bmMask)
|
||||
image.draw(trees)
|
||||
image.draw(blur)
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 85 KiB |
|
@ -899,3 +899,16 @@ proc rect*(path: Path, x, y, w, h: float32) =
|
|||
path.lineTo(x, y+h)
|
||||
path.lineTo(x, y)
|
||||
path.closePath()
|
||||
|
||||
proc polygon*(path: Path, x, y, size: float32, sides: int) =
|
||||
## Draws a n sided regular polygon at x,y with size.
|
||||
let
|
||||
size = 80.0
|
||||
x = 100.0
|
||||
y = 100.0
|
||||
path.moveTo(x + size * cos(0.0), y + size * sin(0.0))
|
||||
for side in 0 .. sides:
|
||||
path.lineTo(
|
||||
x + size * cos(side.float32 * 2.0 * PI / sides.float32),
|
||||
y + size * sin(side.float32 * 2.0 * PI / sides.float32)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue