commit
5868034f08
5 changed files with 54 additions and 168 deletions
|
@ -308,8 +308,11 @@ image.draw(polygonImage)
|
||||||
### Blur
|
### Blur
|
||||||
[examples/blur.nim](examples/blur.nim)
|
[examples/blur.nim](examples/blur.nim)
|
||||||
```nim
|
```nim
|
||||||
|
let path = newPath()
|
||||||
|
path.polygon(vec2(100, 100), 70, sides = 6)
|
||||||
|
|
||||||
let mask = newMask(200, 200)
|
let mask = newMask(200, 200)
|
||||||
mask.fillPolygon(vec2(100, 100), 70, sides = 6)
|
mask.fillPath(path)
|
||||||
|
|
||||||
blur.blur(20)
|
blur.blur(20)
|
||||||
blur.draw(mask, blendMode = bmMask)
|
blur.draw(mask, blendMode = bmMask)
|
||||||
|
|
|
@ -7,8 +7,11 @@ let
|
||||||
|
|
||||||
image.fill(rgba(255, 255, 255, 255))
|
image.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
|
let path = newPath()
|
||||||
|
path.polygon(vec2(100, 100), 70, sides = 6)
|
||||||
|
|
||||||
let mask = newMask(200, 200)
|
let mask = newMask(200, 200)
|
||||||
mask.fillPolygon(vec2(100, 100), 70, sides = 6)
|
mask.fillPath(path)
|
||||||
|
|
||||||
blur.blur(20)
|
blur.blur(20)
|
||||||
blur.draw(mask, blendMode = bmMask)
|
blur.draw(mask, blendMode = bmMask)
|
||||||
|
|
150
src/pixie.nim
150
src/pixie.nim
|
@ -88,153 +88,3 @@ proc writeFile*(mask: Mask, filePath: string) =
|
||||||
else:
|
else:
|
||||||
raise newException(PixieError, "Unsupported file extension")
|
raise newException(PixieError, "Unsupported file extension")
|
||||||
writeFile(filePath, mask.encodeMask(fileFormat))
|
writeFile(filePath, mask.encodeMask(fileFormat))
|
||||||
|
|
||||||
proc fillRect*(
|
|
||||||
mask: Mask,
|
|
||||||
rect: Rect,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
|
||||||
) =
|
|
||||||
## Fills a rectangle.
|
|
||||||
let path = newPath()
|
|
||||||
path.rect(rect)
|
|
||||||
mask.fillPath(path, transform)
|
|
||||||
|
|
||||||
proc strokeRect*(
|
|
||||||
mask: Mask,
|
|
||||||
rect: Rect,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes a rectangle.
|
|
||||||
let path = newPath()
|
|
||||||
path.rect(rect)
|
|
||||||
mask.strokePath(path, transform, strokeWidth)
|
|
||||||
|
|
||||||
proc fillRoundedRect*(
|
|
||||||
mask: Mask,
|
|
||||||
rect: Rect,
|
|
||||||
nw, ne, se, sw: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
|
||||||
) =
|
|
||||||
## Fills a rounded rectangle.
|
|
||||||
let path = newPath()
|
|
||||||
path.roundedRect(rect, nw, ne, se, sw)
|
|
||||||
mask.fillPath(path, transform)
|
|
||||||
|
|
||||||
proc fillRoundedRect*(
|
|
||||||
mask: Mask,
|
|
||||||
rect: Rect,
|
|
||||||
radius: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
|
||||||
) =
|
|
||||||
## Fills a rounded rectangle.
|
|
||||||
let path = newPath()
|
|
||||||
path.roundedRect(rect, radius, radius, radius, radius)
|
|
||||||
mask.fillPath(path, transform)
|
|
||||||
|
|
||||||
proc strokeRoundedRect*(
|
|
||||||
mask: Mask,
|
|
||||||
rect: Rect,
|
|
||||||
nw, ne, se, sw: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes a rounded rectangle.
|
|
||||||
let path = newPath()
|
|
||||||
path.roundedRect(rect, nw, ne, se, sw)
|
|
||||||
mask.strokePath(path, transform, strokeWidth)
|
|
||||||
|
|
||||||
proc strokeRoundedRect*(
|
|
||||||
mask: Mask,
|
|
||||||
rect: Rect,
|
|
||||||
radius: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes a rounded rectangle.
|
|
||||||
let path = newPath()
|
|
||||||
path.roundedRect(rect, radius, radius, radius, radius)
|
|
||||||
mask.strokePath(path, transform, strokeWidth)
|
|
||||||
|
|
||||||
proc strokeSegment*(
|
|
||||||
mask: Mask,
|
|
||||||
segment: Segment,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes a segment (draws a line from segment.at to segment.to).
|
|
||||||
let path = newPath()
|
|
||||||
path.moveTo(segment.at)
|
|
||||||
path.lineTo(segment.to)
|
|
||||||
mask.strokePath(path, transform, strokeWidth)
|
|
||||||
|
|
||||||
proc fillEllipse*(
|
|
||||||
mask: Mask,
|
|
||||||
center: Vec2,
|
|
||||||
rx, ry: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
|
||||||
) =
|
|
||||||
## Fills an ellipse.
|
|
||||||
let path = newPath()
|
|
||||||
path.ellipse(center, rx, ry)
|
|
||||||
mask.fillPath(path, transform)
|
|
||||||
|
|
||||||
proc strokeEllipse*(
|
|
||||||
mask: Mask,
|
|
||||||
center: Vec2,
|
|
||||||
rx, ry: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes an ellipse.
|
|
||||||
let path = newPath()
|
|
||||||
path.ellipse(center, rx, ry)
|
|
||||||
mask.strokePath(path, transform, strokeWidth)
|
|
||||||
|
|
||||||
proc fillCircle*(
|
|
||||||
mask: Mask,
|
|
||||||
center: Vec2,
|
|
||||||
radius: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
|
||||||
) =
|
|
||||||
## Fills a circle.
|
|
||||||
let path = newPath()
|
|
||||||
path.ellipse(center, radius, radius)
|
|
||||||
mask.fillPath(path, transform)
|
|
||||||
|
|
||||||
proc strokeCircle*(
|
|
||||||
mask: Mask,
|
|
||||||
center: Vec2,
|
|
||||||
radius: float32,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes a circle.
|
|
||||||
let path = newPath()
|
|
||||||
path.ellipse(center, radius, radius)
|
|
||||||
mask.fillPath(path, transform, strokeWidth)
|
|
||||||
|
|
||||||
proc fillPolygon*(
|
|
||||||
mask: Mask,
|
|
||||||
pos: Vec2,
|
|
||||||
size: float32,
|
|
||||||
sides: int,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0)
|
|
||||||
) =
|
|
||||||
## Fills a polygon.
|
|
||||||
let path = newPath()
|
|
||||||
path.polygon(pos, size, sides)
|
|
||||||
mask.fillPath(path, transform)
|
|
||||||
|
|
||||||
proc strokePolygon*(
|
|
||||||
mask: Mask,
|
|
||||||
pos: Vec2,
|
|
||||||
size: float32,
|
|
||||||
sides: int,
|
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
|
||||||
strokeWidth = 1.0
|
|
||||||
) =
|
|
||||||
## Strokes a polygon.
|
|
||||||
let path = newPath()
|
|
||||||
path.polygon(pos, size, sides)
|
|
||||||
mask.strokePath(path, transform, strokeWidth)
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
## Load SVG files.
|
## Load SVG files.
|
||||||
|
|
||||||
import chroma, pixie/common, pixie/images, pixie/internal, pixie/paints,
|
import chroma, pixie/common, pixie/images, pixie/paints, pixie/paths, strutils,
|
||||||
pixie/paths, strutils, tables, vmath, xmlparser, xmltree
|
tables, vmath, xmlparser, xmltree
|
||||||
|
|
||||||
when defined(pixieDebugSvg):
|
when defined(pixieDebugSvg):
|
||||||
import strtabs
|
import strtabs
|
||||||
|
|
|
@ -98,62 +98,92 @@ block:
|
||||||
writeFile("tests/images/masks/circleMaskSharpened.png", mask.encodePng())
|
writeFile("tests/images/masks/circleMaskSharpened.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.rect(rect(vec2(10, 10), vec2(30, 30)))
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillRect(rect(vec2(10, 10), vec2(30, 30)))
|
mask.fillPath(path)
|
||||||
writeFile("tests/images/masks/drawRect.png", mask.encodePng())
|
writeFile("tests/images/masks/drawRect.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.rect(rect(vec2(10, 10), vec2(30, 30)))
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.strokeRect(rect(vec2(10, 10), vec2(30, 30)), strokeWidth = 10)
|
mask.strokePath(path, strokeWidth = 10)
|
||||||
writeFile("tests/images/masks/strokeRect.png", mask.encodePng())
|
writeFile("tests/images/masks/strokeRect.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10)
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillRoundedRect(rect(vec2(10, 10), vec2(30, 30)), 10)
|
mask.fillPath(path)
|
||||||
writeFile("tests/images/masks/drawRoundedRect.png", mask.encodePng())
|
writeFile("tests/images/masks/drawRoundedRect.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10)
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.strokeRoundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, strokeWidth = 10)
|
mask.strokePath(path, strokeWidth = 10)
|
||||||
writeFile("tests/images/masks/strokeRoundedRect.png", mask.encodePng())
|
writeFile("tests/images/masks/strokeRoundedRect.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.moveTo(vec2(10, 10))
|
||||||
|
path.lineTo(vec2(90, 90))
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.strokeSegment(
|
mask.strokePath(path, strokeWidth = 10)
|
||||||
segment(vec2(10, 10), vec2(90, 90)),
|
|
||||||
strokeWidth = 10
|
|
||||||
)
|
|
||||||
writeFile("tests/images/masks/drawSegment.png", mask.encodePng())
|
writeFile("tests/images/masks/drawSegment.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.ellipse(vec2(50, 50), 20, 10)
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillEllipse(vec2(50, 50), 20, 10)
|
mask.fillPath(path)
|
||||||
writeFile("tests/images/masks/drawEllipse.png", mask.encodePng())
|
writeFile("tests/images/masks/drawEllipse.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.ellipse(vec2(50, 50), 20, 10)
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.strokeEllipse(vec2(50, 50), 20, 10, strokeWidth = 10)
|
mask.strokePath(path, strokeWidth = 10)
|
||||||
writeFile("tests/images/masks/strokeEllipse.png", mask.encodePng())
|
writeFile("tests/images/masks/strokeEllipse.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.polygon(vec2(50, 50), 30, 6)
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillPolygon(vec2(50, 50), 30, 6)
|
mask.fillPath(path)
|
||||||
writeFile("tests/images/masks/drawPolygon.png", mask.encodePng())
|
writeFile("tests/images/masks/drawPolygon.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.polygon(vec2(50, 50), 30, 6)
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.strokePolygon(vec2(50, 50), 30, 6, strokeWidth = 10)
|
mask.strokepath(path, strokeWidth = 10)
|
||||||
writeFile("tests/images/masks/strokePolygon.png", mask.encodePng())
|
writeFile("tests/images/masks/strokePolygon.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.rect(rect(25, 25, 50, 50))
|
||||||
|
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillRect(rect(25, 25, 50, 50))
|
mask.fillpath(path)
|
||||||
mask.blur(20)
|
mask.blur(20)
|
||||||
writeFile("tests/images/maskblur20.png", mask.encodePng())
|
writeFile("tests/images/maskblur20.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.rect(rect(25, 25, 150, 150))
|
||||||
|
|
||||||
let mask = newMask(200, 200)
|
let mask = newMask(200, 200)
|
||||||
mask.fillRect(rect(25, 25, 150, 150))
|
mask.fillPath(path)
|
||||||
mask.blur(25)
|
mask.blur(25)
|
||||||
|
|
||||||
let minified = mask.minifyBy2()
|
let minified = mask.minifyBy2()
|
||||||
|
|
Loading…
Reference in a new issue