drawEllipse, drawCircle
This commit is contained in:
parent
318d90e509
commit
0362d03b0b
12
README.md
12
README.md
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
BIN
tests/images/drawEllipse.png
Normal file
BIN
tests/images/drawEllipse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/images/drawRoundedRect.png
Normal file
BIN
tests/images/drawRoundedRect.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 917 B |
BIN
tests/images/masks/drawEllipse.png
Normal file
BIN
tests/images/masks/drawEllipse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 561 B |
BIN
tests/images/masks/drawRoundedRect.png
Normal file
BIN
tests/images/masks/drawRoundedRect.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 491 B |
|
@ -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")
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue