Merge pull request #113 from guzba/master

drawRect image, mask + single import
This commit is contained in:
treeform 2021-02-18 11:41:40 -08:00 committed by GitHub
commit b55a90f10d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 41 additions and 14 deletions

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
let
trees = readImage("examples/data/trees.png")

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
let
image = newImage(200, 200)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
let
image = newImage(200, 200)

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
let
trees = readImage("examples/data/trees.png")

View file

@ -1,4 +1,4 @@
import chroma, pixie
import pixie
var image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))

View file

@ -1,4 +1,4 @@
import chroma, pixie, vmath
import pixie
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

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())