From 751b804679f7ba38d34774d4c72fd1f4eea90670 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 25 Feb 2021 11:43:09 -0600 Subject: [PATCH] morepretty --- examples/gradient.nim | 14 +++++----- examples/image_tiled.nim | 4 +-- src/pixie.nim | 5 ++-- src/pixie/blends.nim | 1 - src/pixie/images.nim | 4 ++- src/pixie/paints.nim | 18 ++++++------ src/pixie/paths.nim | 4 +-- tests/test_paints.nim | 59 ++++++++++++++++++++-------------------- 8 files changed, 54 insertions(+), 55 deletions(-) diff --git a/examples/gradient.nim b/examples/gradient.nim index 6e7386e..3c0fc0c 100644 --- a/examples/gradient.nim +++ b/examples/gradient.nim @@ -14,17 +14,17 @@ image.fillPath( z """, Paint( - kind:pkGradientRadial, + kind: pkGradientRadial, gradientHandlePositions: @[ vec2(100, 100), vec2(200, 100), vec2(100, 200) - ], - gradientStops: @[ - ColorStop(color:rgba(255, 0, 0, 255).color, position: 0), - ColorStop(color:rgba(255, 0, 0, 40).color, position: 1.0), - ] - ) + ], + gradientStops: @[ + ColorStop(color: rgba(255, 0, 0, 255).color, position: 0), + ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0), + ] +) ) image.writeFile("examples/paint.png") diff --git a/examples/image_tiled.nim b/examples/image_tiled.nim index 2bb6f77..cac5af5 100644 --- a/examples/image_tiled.nim +++ b/examples/image_tiled.nim @@ -14,9 +14,9 @@ path.polygon( image.fillPath( path, Paint( - kind:pkImageTiled, + kind: pkImageTiled, image: readImage("tests/images/png/baboon.png"), - imageMat:scale(vec2(0.08, 0.08)) + imageMat: scale(vec2(0.08, 0.08)) ) ) diff --git a/src/pixie.nim b/src/pixie.nim index ed9cca4..74a956e 100644 --- a/src/pixie.nim +++ b/src/pixie.nim @@ -1,9 +1,8 @@ import bumpy, chroma, flatty/binny, os, pixie/blends, pixie/common, pixie/fileformats/bmp, pixie/fileformats/jpg, pixie/fileformats/png, - pixie/fileformats/svg, pixie/paints, pixie/images, pixie/masks, - pixie/paths, vmath + pixie/fileformats/svg, pixie/images, pixie/masks, pixie/paints, pixie/paths, vmath -export blends, bumpy, chroma, common, paints, images, masks, paths, vmath +export blends, bumpy, chroma, common, images, masks, paints, paths, vmath type FileFormat* = enum diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index 8b37575..aca4bbc 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -35,7 +35,6 @@ type bmIntersectMask bmExcludeMask - Blender* = proc(backdrop, source: ColorRGBA): ColorRGBA ## Function signature ## returned by blender. Masker* = proc(backdrop, source: uint8): uint8 ## Function signature returned diff --git a/src/pixie/images.nim b/src/pixie/images.nim index bc2c293..6bd4d59 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -543,7 +543,9 @@ proc getRgbaSmooth*(image: Image, x, y: float32, wrapped = false): ColorRGBA = lerp(bottomMix, topMix, diffY) -proc drawCorrect(a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal) = +proc drawCorrect( + a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal +) = ## Draws one image onto another using matrix with color blending. when type(a) is Image: diff --git a/src/pixie/paints.nim b/src/pixie/paints.nim index 72bef3f..66eb544 100644 --- a/src/pixie/paints.nim +++ b/src/pixie/paints.nim @@ -1,4 +1,4 @@ -import chroma, common, images, vmath, blends +import blends, chroma, common, images, vmath type PaintKind* = enum @@ -13,19 +13,19 @@ type ## Paint used to fill paths. case kind*: PaintKind of pkSolid: - color*: ColorRGBA ## Color to fill with. + color*: ColorRGBA ## Color to fill with. of pkImage, pkImageTiled: - image*: Image ## Image to fill with. - imageMat*: Mat3 ## Matrix of the filled image. + image*: Image ## Image to fill with. + imageMat*: Mat3 ## Matrix of the filled image. of pkGradientLinear, pkGradientRadial, pkGradientAngular: - gradientHandlePositions*: seq[Vec2] ## Gradient positions (image space). - gradientStops*: seq[ColorStop] ## Color stops (gradient space). - blendMode*: BlendMode ## Blend mode. + gradientHandlePositions*: seq[Vec2] ## Gradient positions (image space). + gradientStops*: seq[ColorStop] ## Color stops (gradient space). + blendMode*: BlendMode ## Blend mode. ColorStop* = object ## Color stop on a gradient curve. - color*: Color ## Color of the stop - position*: float32 ## Gradient Stop position 0..1. + color*: Color ## Color of the stop + position*: float32 ## Gradient Stop position 0..1. proc toLineSpace(at, to, point: Vec2): float32 = ## Convert position on to where it would fall on a line between at and to. diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 888c692..66af2df 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1,4 +1,4 @@ -import blends, bumpy, chroma, common, images, masks, strutils, vmath, paints +import blends, bumpy, chroma, common, images, masks, paints, strutils, vmath when defined(amd64) and not defined(pixieNoSimd): import nimsimd/sse2 @@ -35,7 +35,7 @@ type SomePath* = Path | string | seq[seq[Vec2]] -const epsilon = 0.0001 * PI ## Tiny value used for some computations. +const epsilon = 0.0001 * PI ## Tiny value used for some computations. when defined(release): {.push checks: off.} diff --git a/tests/test_paints.nim b/tests/test_paints.nim index 7f2a049..a832d86 100644 --- a/tests/test_paints.nim +++ b/tests/test_paints.nim @@ -14,8 +14,8 @@ block: image.fillPath( heartShape, Paint( - kind:pkSolid, - color:rgba(255, 0, 0, 255) + kind: pkSolid, + color: rgba(255, 0, 0, 255) ) ) image.writeFile("tests/images/paths/paintSolid.png") @@ -26,9 +26,9 @@ block: image.fillPath( heartShape, Paint( - kind:pkImage, - image:decodePng(readFile("tests/images/png/baboon.png")), - imageMat:scale(vec2(0.2, 0.2)) + kind: pkImage, + image: decodePng(readFile("tests/images/png/baboon.png")), + imageMat: scale(vec2(0.2, 0.2)) ) ) image.writeFile("tests/images/paths/paintImage.png") @@ -39,30 +39,29 @@ block: image.fillPath( heartShape, Paint( - kind:pkImageTiled, - image:decodePng(readFile("tests/images/png/baboon.png")), - imageMat:scale(vec2(0.02, 0.02)) + kind: pkImageTiled, + image: decodePng(readFile("tests/images/png/baboon.png")), + imageMat: scale(vec2(0.02, 0.02)) ) ) image.writeFile("tests/images/paths/paintImageTiled.png") - block: let image = newImage(100, 100) image.fillPath( heartShape, Paint( - kind:pkGradientLinear, + kind: pkGradientLinear, gradientHandlePositions: @[ vec2(0, 50), vec2(100, 50), - ], - gradientStops: @[ - ColorStop(color:rgba(255, 0, 0, 255).color, position: 0), - ColorStop(color:rgba(255, 0, 0, 40).color, position: 1.0), - ] - ) + ], + gradientStops: @[ + ColorStop(color: rgba(255, 0, 0, 255).color, position: 0), + ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0), + ] + ) ) image.writeFile("tests/images/paths/gradientLinear.png") @@ -72,17 +71,17 @@ block: image.fillPath( heartShape, Paint( - kind:pkGradientRadial, + kind: pkGradientRadial, gradientHandlePositions: @[ vec2(50, 50), vec2(100, 50), vec2(50, 100) - ], - gradientStops: @[ - ColorStop(color:rgba(255, 0, 0, 255).color, position: 0), - ColorStop(color:rgba(255, 0, 0, 40).color, position: 1.0), - ] - ) + ], + gradientStops: @[ + ColorStop(color: rgba(255, 0, 0, 255).color, position: 0), + ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0), + ] + ) ) image.writeFile("tests/images/paths/gradientRadial.png") @@ -93,17 +92,17 @@ block: image.fillPath( heartShape, Paint( - kind:pkGradientAngular, + kind: pkGradientAngular, gradientHandlePositions: @[ vec2(50, 50), vec2(100, 50), vec2(50, 100) - ], - gradientStops: @[ - ColorStop(color:rgba(255, 0, 0, 255).color, position: 0), - ColorStop(color:rgba(255, 0, 0, 40).color, position: 1.0), - ] - ) + ], + gradientStops: @[ + ColorStop(color: rgba(255, 0, 0, 255).color, position: 0), + ColorStop(color: rgba(255, 0, 0, 40).color, position: 1.0), + ] + ) ) image.writeFile("tests/images/paths/gradientAngular.png")