drawSegment + updated examples
This commit is contained in:
parent
b55a90f10d
commit
3016790e8a
20
README.md
20
README.md
|
@ -26,25 +26,23 @@ Features:
|
|||
### Square
|
||||
[examples/square.nim](examples/square.nim)
|
||||
```nim
|
||||
var p: Path
|
||||
p.rect(50, 50, 100, 100)
|
||||
let
|
||||
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)
|
||||
|
||||
### Line
|
||||
[examples/line.nim](examples/line.nim)
|
||||
```nim
|
||||
var p: Path
|
||||
p.moveTo(25, 25)
|
||||
p.lineTo(175, 175)
|
||||
let
|
||||
start = vec2(25, 25)
|
||||
stop = vec2(175, 175)
|
||||
color = parseHtmlColor("#FF5C00").rgba
|
||||
|
||||
image.strokePath(
|
||||
p,
|
||||
parseHtmlColor("#FF5C00").rgba,
|
||||
strokeWidth = 10,
|
||||
)
|
||||
image.drawSegment(segment(start, stop), color, strokeWidth = 10)
|
||||
```
|
||||
![example output](examples/line.png)
|
||||
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
import pixie
|
||||
|
||||
let
|
||||
image = newImage(200, 200)
|
||||
|
||||
let image = newImage(200, 200)
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
var p: Path
|
||||
p.moveTo(25, 25)
|
||||
p.lineTo(175, 175)
|
||||
let
|
||||
start = vec2(25, 25)
|
||||
stop = vec2(175, 175)
|
||||
color = parseHtmlColor("#FF5C00").rgba
|
||||
|
||||
image.strokePath(
|
||||
p,
|
||||
parseHtmlColor("#FF5C00").rgba,
|
||||
strokeWidth = 10,
|
||||
)
|
||||
image.drawSegment(segment(start, stop), color, strokeWidth = 10)
|
||||
|
||||
image.writeFile("examples/line.png")
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import pixie
|
||||
|
||||
var image = newImage(200, 200)
|
||||
let image = newImage(200, 200)
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
var p: Path
|
||||
p.rect(50, 50, 100, 100)
|
||||
let
|
||||
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")
|
||||
|
|
|
@ -61,3 +61,21 @@ proc drawRect*(mask: Mask, rect: Rect) =
|
|||
var path: Path
|
||||
path.rect(rect)
|
||||
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)
|
||||
|
|
BIN
tests/images/drawSegment.png
Normal file
BIN
tests/images/drawSegment.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
tests/images/masks/drawSegment.png
Normal file
BIN
tests/images/masks/drawSegment.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 466 B |
|
@ -55,3 +55,13 @@ block:
|
|||
image.fill(rgba(0, 255, 255, 255))
|
||||
image.drawRect(rect(vec2(10, 10), vec2(30, 30)), rgba(255, 255, 0, 255))
|
||||
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")
|
||||
|
|
|
@ -107,3 +107,11 @@ block:
|
|||
let mask = newMask(100, 100)
|
||||
mask.drawRect(rect(vec2(10, 10), vec2(30, 30)))
|
||||
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())
|
||||
|
|
Loading…
Reference in a new issue