drawSegment + updated examples

This commit is contained in:
Ryan Oldenburg 2021-02-18 13:55:26 -06:00
parent b55a90f10d
commit 3016790e8a
8 changed files with 56 additions and 26 deletions

View file

@ -26,25 +26,23 @@ Features:
### Square ### Square
[examples/square.nim](examples/square.nim) [examples/square.nim](examples/square.nim)
```nim ```nim
var p: Path let
p.rect(50, 50, 100, 100) pos = vec2(50, 50)
wh = vec2(100, 100)
image.fillPath(p, rgba(255, 0, 0, 255)) image.drawRect(rect(pos, wh), rgba(255, 0, 0, 255))
``` ```
![example output](examples/square.png) ![example output](examples/square.png)
### Line ### Line
[examples/line.nim](examples/line.nim) [examples/line.nim](examples/line.nim)
```nim ```nim
var p: Path let
p.moveTo(25, 25) start = vec2(25, 25)
p.lineTo(175, 175) stop = vec2(175, 175)
color = parseHtmlColor("#FF5C00").rgba
image.strokePath( image.drawSegment(segment(start, stop), color, strokeWidth = 10)
p,
parseHtmlColor("#FF5C00").rgba,
strokeWidth = 10,
)
``` ```
![example output](examples/line.png) ![example output](examples/line.png)

View file

@ -1,18 +1,13 @@
import pixie import pixie
let let image = newImage(200, 200)
image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
var p: Path let
p.moveTo(25, 25) start = vec2(25, 25)
p.lineTo(175, 175) stop = vec2(175, 175)
color = parseHtmlColor("#FF5C00").rgba
image.strokePath( image.drawSegment(segment(start, stop), color, strokeWidth = 10)
p,
parseHtmlColor("#FF5C00").rgba,
strokeWidth = 10,
)
image.writeFile("examples/line.png") image.writeFile("examples/line.png")

View file

@ -1,11 +1,12 @@
import pixie import pixie
var image = newImage(200, 200) let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
var p: Path let
p.rect(50, 50, 100, 100) pos = vec2(50, 50)
wh = vec2(100, 100)
image.fillPath(p, rgba(255, 0, 0, 255)) image.drawRect(rect(pos, wh), rgba(255, 0, 0, 255))
image.writeFile("examples/square.png") image.writeFile("examples/square.png")

View file

@ -61,3 +61,21 @@ proc drawRect*(mask: Mask, rect: Rect) =
var path: Path var path: Path
path.rect(rect) path.rect(rect)
mask.fillPath(path) mask.fillPath(path)
proc drawSegment*(
image: Image,
segment: Segment,
color: ColorRGBA,
strokeWidth = 1.0,
blendMode = bmNormal
) =
var path: Path
path.moveTo(segment.at)
path.lineTo(segment.to)
image.strokePath(path, color, strokeWidth, wrNonZero, blendMode)
proc drawSegment*(mask: Mask, segment: Segment, strokeWidth: float32) =
var path: Path
path.moveTo(segment.at)
path.lineTo(segment.to)
mask.strokePath(path, strokeWidth)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

View file

@ -55,3 +55,13 @@ block:
image.fill(rgba(0, 255, 255, 255)) image.fill(rgba(0, 255, 255, 255))
image.drawRect(rect(vec2(10, 10), vec2(30, 30)), rgba(255, 255, 0, 255)) image.drawRect(rect(vec2(10, 10), vec2(30, 30)), rgba(255, 255, 0, 255))
image.writeFile("tests/images/drawRect.png") image.writeFile("tests/images/drawRect.png")
block:
let image = newImage(100, 100)
image.fill(rgba(0, 255, 255, 255))
image.drawSegment(
segment(vec2(10, 10), vec2(90, 90)),
rgba(255, 255, 0, 255),
strokeWidth = 10
)
image.writeFile("tests/images/drawSegment.png")

View file

@ -107,3 +107,11 @@ block:
let mask = newMask(100, 100) let mask = newMask(100, 100)
mask.drawRect(rect(vec2(10, 10), vec2(30, 30))) mask.drawRect(rect(vec2(10, 10), vec2(30, 30)))
writeFile("tests/images/masks/drawRect.png", mask.encodePng()) writeFile("tests/images/masks/drawRect.png", mask.encodePng())
block:
let mask = newMask(100, 100)
mask.drawSegment(
segment(vec2(10, 10), vec2(90, 90)),
strokeWidth = 10
)
writeFile("tests/images/masks/drawSegment.png", mask.encodePng())