drawRect image, mask

This commit is contained in:
Ryan Oldenburg 2021-02-18 13:29:40 -06:00
parent bdf8e5601d
commit 505e2ff2d9
7 changed files with 34 additions and 7 deletions

View file

@ -1,8 +1,9 @@
import flatty/binny, os, pixie/blends, pixie/common, pixie/fileformats/bmp,
pixie/fileformats/jpg, pixie/fileformats/png, pixie/fileformats/svg,
pixie/images, pixie/masks, pixie/paths, pixie/gradients
import bumpy, chroma, flatty/binny, os, pixie/blends, pixie/common,
pixie/fileformats/bmp, pixie/fileformats/jpg, pixie/fileformats/png,
pixie/fileformats/svg, pixie/gradients, pixie/images, pixie/masks,
pixie/paths, vmath
export blends, common, images, masks, paths, gradients
export blends, bumpy, chroma, common, gradients, images, masks, paths, vmath
type
FileFormat* = enum
@ -48,3 +49,15 @@ proc writeFile*(image: Image, filePath: string) =
else:
raise newException(PixieError, "Unsupported image file extension")
image.writeFile(filePath, fileformat)
proc drawRect*(
image: Image, rect: Rect, color: ColorRGBA, blendMode = bmNormal
) =
var path: Path
path.rect(rect)
image.fillPath(path, color, wrNonZero, blendMode)
proc drawRect*(mask: Mask, rect: Rect) =
var path: Path
path.rect(rect)
mask.fillPath(path)

View file

@ -1,4 +1,4 @@
import images, vmath, chroma, common
import chroma, common, images, vmath
type ColorStop* = object
## Represents color on a gradient curve.

View file

@ -370,6 +370,9 @@ proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
proc rect*(path: var Path, pos: Vec2, wh: Vec2, clockwise = true) {.inline.} =
path.rect(pos.x, pos.y, wh.x, wh.y, clockwise)
proc rect*(path: var Path, rect: Rect, clockwise = true) {.inline.} =
path.rect(rect.x, rect.y, rect.w, rect.h, clockwise)
const splineCircleK = 4.0 * (-1.0 + sqrt(2.0)) / 3
proc roundedRect*(

BIN
tests/images/drawRect.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
block:
let
@ -49,3 +49,9 @@ block:
a.draw(b, translate(vec2(250, 250)) * rotationMat3(360 * PI / 180))
a.writeFile("tests/images/rotate360.png")
block:
let image = newImage(100, 100)
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")

View file

@ -1,4 +1,4 @@
import chroma, pixie, pixie/fileformats/png, vmath
import pixie, pixie/fileformats/png
block:
let mask = newMask(100, 100)
@ -102,3 +102,8 @@ block:
mask.ceil()
writeFile("tests/images/masks/circleMaskSharpened.png", mask.encodePng())
block:
let mask = newMask(100, 100)
mask.drawRect(rect(vec2(10, 10), vec2(30, 30)))
writeFile("tests/images/masks/drawRect.png", mask.encodePng())