Merge pull request #84 from guzba/master
updated examples, little stuff
This commit is contained in:
commit
3cf15bdb09
10 changed files with 43 additions and 24 deletions
17
README.md
17
README.md
|
@ -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))
|
||||
```
|
||||

|
||||
|
@ -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))
|
||||
```
|
||||

|
||||
|
@ -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)) *
|
||||
|
|
|
@ -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 |
|
@ -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 |
|
@ -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")
|
||||
|
|
|
@ -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 |
|
@ -554,13 +554,6 @@ proc blendHardLight(backdrop, source: ColorRGBA): ColorRGBA =
|
|||
result = result.toStraightAlpha()
|
||||
|
||||
proc blendSoftLight(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
# proc softLight(backdrop, source: int32): uint8 {.inline.} =
|
||||
# ## Pegtop
|
||||
# (
|
||||
# ((255 - 2 * source) * backdrop ^ 2) div 255 ^ 2 +
|
||||
# (2 * source * backdrop) div 255
|
||||
# ).uint8
|
||||
|
||||
when defined(amd64) and not defined(pixieNoSimd):
|
||||
let
|
||||
vb = mm_setr_ps(backdrop.r.float32, backdrop.g.float32, backdrop.b.float32, 0)
|
||||
|
@ -577,6 +570,16 @@ proc blendSoftLight(backdrop, source: ColorRGBA): ColorRGBA =
|
|||
result = alphaFix(backdrop, source, vb, vs, vm)
|
||||
else:
|
||||
blendSoftLightFloats(backdrop.color, source.color).rgba
|
||||
# proc softLight(backdrop, source: int32): uint8 {.inline.} =
|
||||
# ## Pegtop
|
||||
# (
|
||||
# ((255 - 2 * source) * (backdrop ^ 2)) div (255 ^ 2) +
|
||||
# (2 * source * backdrop) div 255
|
||||
# ).uint8
|
||||
# result.r = softLight(backdrop.r.int32, source.r.int32)
|
||||
# result.g = softLight(backdrop.g.int32, source.g.int32)
|
||||
# result.b = softLight(backdrop.b.int32, source.b.int32)
|
||||
# result = alphaFix(backdrop, source, result)
|
||||
|
||||
proc blendDifference(backdrop, source: ColorRGBA): ColorRGBA =
|
||||
let
|
||||
|
|
|
@ -39,14 +39,14 @@ func lerp*(a, b: Color, v: float32): Color {.inline.} =
|
|||
result.a = lerp(a.a, b.a, v)
|
||||
|
||||
proc toPremultipliedAlpha*(c: Color): Color {.inline.} =
|
||||
## Converts a color to premultiplied alpha from straight.
|
||||
## Converts a color to premultiplied alpha from straight alpha.
|
||||
result.r = c.r * c.a
|
||||
result.g = c.g * c.a
|
||||
result.b = c.b * c.a
|
||||
result.a = c.a
|
||||
|
||||
proc toStraightAlpha*(c: Color): Color {.inline.} =
|
||||
## Converts a color to from premultiplied alpha to straight.
|
||||
## Converts a color from premultiplied alpha to straight alpha.
|
||||
if c.a != 0 and c.a != 1:
|
||||
result = c
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue