drawEllipse, drawCircle

This commit is contained in:
Ryan Oldenburg 2021-02-18 16:30:47 -06:00
parent 318d90e509
commit 0362d03b0b
10 changed files with 73 additions and 0 deletions

View file

@ -46,6 +46,18 @@ image.drawSegment(segment(start, stop), color, strokeWidth = 10)
```
![example output](examples/line.png)
### Rounded rectangle
[examples/rounded_rectangle.nim](examples/rounded_rectangle.nim)
```nim
let
pos = vec2(50, 50)
wh = vec2(100, 100)
r = 25.0
image.drawRoundedRect(rect(pos, wh), r, rgba(0, 255, 0, 255))
```
![example output](examples/rounded_rectangle.png)
### Heart
[examples/heart.nim](examples/heart.nim)
```nim

View file

@ -9,3 +9,5 @@ let
r = 25.0
image.drawRoundedRect(rect(pos, wh), r, rgba(0, 255, 0, 255))
image.writeFile("examples/rounded_rectangle.png")

View file

@ -111,3 +111,43 @@ proc drawSegment*(mask: Mask, segment: Segment, strokeWidth: float32) =
path.moveTo(segment.at)
path.lineTo(segment.to)
mask.strokePath(path, strokeWidth)
proc drawEllipse*(
image: Image,
center: Vec2,
rx, ry: float32,
color: ColorRGBA,
blendMode = bmNormal
) =
var path: Path
path.ellipse(center, rx, ry)
image.fillPath(path, color, wrNonZero, blendMode)
proc drawEllipse*(
mask: Mask,
center: Vec2,
rx, ry: float32
) =
var path: Path
path.ellipse(center, rx, ry)
mask.fillPath(path)
proc drawCircle*(
image: Image,
center: Vec2,
radius: float32,
color: ColorRGBA,
blendMode = bmNormal
) =
var path: Path
path.ellipse(center, radius, radius)
image.fillPath(path, color, wrNonZero, blendMode)
proc drawCircle*(
mask: Mask,
center: Vec2,
radius: float32
) =
var path: Path
path.ellipse(center, radius, radius)
mask.fillPath(path)

View file

@ -450,6 +450,9 @@ proc ellipse*(path: var Path, cx, cy, rx, ry: float32) =
path.bezierCurveTo(cx + magicX, cy - ry, cx + rx, cy - magicY, cx + rx, cy)
path.closePath()
proc ellipse*(path: var Path, center: Vec2, rx, ry: float32) {.inline.} =
path.ellipse(center.x, center.y, rx, ry)
proc polygon*(path: var Path, x, y, size: float32, sides: int) =
## Draws a n sided regular polygon at (x, y) with size.
path.moveTo(x + size * cos(0.0), y + size * sin(0.0))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

View file

@ -75,3 +75,14 @@ block:
strokeWidth = 10
)
image.writeFile("tests/images/drawSegment.png")
block:
let image = newImage(100, 100)
image.fill(rgba(0, 255, 255, 255))
image.drawEllipse(
vec2(50, 50),
25,
25,
rgba(255, 255, 0, 255)
)
image.writeFile("tests/images/drawEllipse.png")

View file

@ -120,3 +120,8 @@ block:
strokeWidth = 10
)
writeFile("tests/images/masks/drawSegment.png", mask.encodePng())
block:
let mask = newMask(100, 100)
mask.drawEllipse(vec2(50, 50), 20, 10)
writeFile("tests/images/masks/drawEllipse.png", mask.encodePng())