2022-07-09 18:08:34 +00:00
|
|
|
import pixie, xrays
|
2021-02-08 02:33:53 +00:00
|
|
|
|
2021-02-09 03:12:28 +00:00
|
|
|
block:
|
|
|
|
let mask = newMask(100, 100)
|
|
|
|
mask.fill(200)
|
|
|
|
mask.applyOpacity(0.5)
|
|
|
|
doAssert mask[0, 0] == 100
|
|
|
|
doAssert mask[88, 88] == 100
|
|
|
|
|
2021-02-09 04:26:51 +00:00
|
|
|
block:
|
|
|
|
let mask = newMask(100, 100)
|
|
|
|
mask.fill(200)
|
|
|
|
mask.invert()
|
|
|
|
doAssert mask[0, 0] == 55
|
|
|
|
|
2021-06-18 20:36:00 +00:00
|
|
|
block:
|
|
|
|
let
|
|
|
|
mask = newMask(100, 100)
|
|
|
|
r = 10.0
|
|
|
|
x = 10.0
|
|
|
|
y = 10.0
|
|
|
|
h = 80.0
|
|
|
|
w = 80.0
|
2021-08-06 19:38:03 +00:00
|
|
|
let path = newPath()
|
2021-06-18 20:36:00 +00:00
|
|
|
path.moveTo(x + r, y)
|
2021-05-19 05:04:39 +00:00
|
|
|
# path.arcTo(x + w, y, x + w, y + h, r)
|
|
|
|
# path.arcTo(x + w, y + h, x, y + h, r)
|
|
|
|
# path.arcTo(x, y + h, x, y, r)
|
|
|
|
# path.arcTo(x, y, x + w, y, r)
|
2021-06-18 20:36:00 +00:00
|
|
|
path.roundedRect(x, y, w, h, r, r, r, r)
|
|
|
|
mask.fillPath(path)
|
2021-02-08 02:33:53 +00:00
|
|
|
|
2021-06-18 20:36:00 +00:00
|
|
|
let minified = mask.minifyBy2()
|
2021-02-08 20:31:20 +00:00
|
|
|
|
2021-06-18 20:36:00 +00:00
|
|
|
doAssert minified.width == 50 and minified.height == 50
|
2021-02-08 20:31:20 +00:00
|
|
|
|
2022-07-09 18:08:34 +00:00
|
|
|
minified.xray("tests/masks/maskMinified.png")
|
2021-02-09 01:51:15 +00:00
|
|
|
|
2021-10-03 20:31:39 +00:00
|
|
|
block:
|
|
|
|
let
|
2021-10-03 22:17:04 +00:00
|
|
|
a = readImage("tests/masks/maskMinified.png")
|
2021-10-03 20:31:39 +00:00
|
|
|
b = a.magnifyBy2()
|
2022-07-09 18:08:34 +00:00
|
|
|
b.xray("tests/masks/maskMagnified.png")
|
2021-10-03 20:31:39 +00:00
|
|
|
|
2021-02-09 01:51:15 +00:00
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fill(rgba(255, 100, 100, 255))
|
|
|
|
|
2021-08-06 19:38:03 +00:00
|
|
|
let path = newPath()
|
2021-02-09 01:51:15 +00:00
|
|
|
path.ellipse(image.width / 2, image.height / 2, 25, 25)
|
|
|
|
|
|
|
|
let mask = newMask(image.width, image.height)
|
|
|
|
mask.fillPath(path)
|
|
|
|
|
|
|
|
image.draw(mask)
|
2022-07-09 18:08:34 +00:00
|
|
|
image.xray("tests/masks/circleMask.png")
|
2021-02-09 01:51:15 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let a = newMask(100, 100)
|
|
|
|
a.fill(255)
|
|
|
|
|
2021-08-06 19:38:03 +00:00
|
|
|
let path = newPath()
|
2021-02-09 01:51:15 +00:00
|
|
|
path.ellipse(a.width / 2, a.height / 2, 25, 25)
|
|
|
|
|
|
|
|
let b = newMask(a.width, a.height)
|
|
|
|
b.fillPath(path)
|
|
|
|
|
|
|
|
a.draw(b)
|
2022-07-09 18:08:34 +00:00
|
|
|
a.xray("tests/masks/maskedMask.png")
|
2021-02-09 01:57:36 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let a = newMask(100, 100)
|
|
|
|
a.fill(255)
|
|
|
|
|
2021-08-06 19:38:03 +00:00
|
|
|
let path = newPath()
|
2021-02-09 01:57:36 +00:00
|
|
|
path.ellipse(a.width / 2, a.height / 2, 25, 25)
|
|
|
|
|
|
|
|
let b = newImage(a.width, a.height)
|
|
|
|
b.fillPath(path, rgba(0, 0, 0, 255))
|
|
|
|
|
|
|
|
a.draw(b)
|
2022-07-09 18:08:34 +00:00
|
|
|
a.xray("tests/masks/imageMaskedMask.png")
|
2021-02-09 21:22:22 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-06 19:38:03 +00:00
|
|
|
let path = newPath()
|
2021-02-09 21:22:22 +00:00
|
|
|
path.rect(40, 40, 20, 20)
|
|
|
|
|
|
|
|
let a = newMask(100, 100)
|
|
|
|
a.fillPath(path)
|
|
|
|
|
|
|
|
a.spread(10)
|
|
|
|
|
2022-07-09 18:08:34 +00:00
|
|
|
a.xray("tests/masks/spread.png")
|
2021-02-11 19:13:09 +00:00
|
|
|
|
2022-03-19 02:24:56 +00:00
|
|
|
block:
|
|
|
|
let path = newPath()
|
|
|
|
path.rect(40, 40, 20, 20)
|
|
|
|
|
|
|
|
let a = newMask(100, 100)
|
|
|
|
a.fillPath(path)
|
|
|
|
|
|
|
|
a.spread(-5)
|
|
|
|
|
2022-07-09 18:08:34 +00:00
|
|
|
a.xray("tests/masks/negativeSpread.png")
|
2022-03-19 02:24:56 +00:00
|
|
|
|
2021-02-11 19:13:09 +00:00
|
|
|
block:
|
|
|
|
let mask = newMask(100, 100)
|
|
|
|
|
2021-08-06 19:38:03 +00:00
|
|
|
let path = newPath()
|
2021-02-11 19:13:09 +00:00
|
|
|
path.ellipse(mask.width / 2, mask.height / 2, 25, 25)
|
|
|
|
|
|
|
|
mask.fillPath(path)
|
|
|
|
mask.ceil()
|
|
|
|
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/circleMaskSharpened.png")
|
2021-02-18 19:29:40 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.rect(rect(vec2(10, 10), vec2(30, 30)))
|
|
|
|
|
2021-02-18 19:29:40 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.fillPath(path)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/drawRect.png")
|
2021-02-18 19:55:26 +00:00
|
|
|
|
2021-02-18 22:23:54 +00:00
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.rect(rect(vec2(10, 10), vec2(30, 30)))
|
|
|
|
|
2021-02-18 22:23:54 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.strokePath(path, strokeWidth = 10)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/strokeRect.png")
|
2021-02-19 18:04:27 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10)
|
|
|
|
|
2021-02-19 18:04:27 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.fillPath(path)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/drawRoundedRect.png")
|
2021-02-18 22:23:54 +00:00
|
|
|
|
2021-02-18 19:55:26 +00:00
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10)
|
2021-02-18 19:55:26 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.strokePath(path, strokeWidth = 10)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/strokeRoundedRect.png")
|
2021-02-19 18:04:27 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.moveTo(vec2(10, 10))
|
|
|
|
path.lineTo(vec2(90, 90))
|
|
|
|
|
2021-02-19 18:04:27 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.strokePath(path, strokeWidth = 10)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/drawSegment.png")
|
2021-02-18 22:30:47 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.ellipse(vec2(50, 50), 20, 10)
|
|
|
|
|
2021-02-18 22:30:47 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.fillPath(path)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/drawEllipse.png")
|
2021-02-18 22:40:35 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.ellipse(vec2(50, 50), 20, 10)
|
|
|
|
|
2021-02-18 22:40:35 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.strokePath(path, strokeWidth = 10)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/strokeEllipse.png")
|
2021-02-19 18:04:27 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.polygon(vec2(50, 50), 30, 6)
|
|
|
|
|
2021-02-19 18:04:27 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.fillPath(path)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/drawPolygon.png")
|
2021-02-19 18:04:27 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.polygon(vec2(50, 50), 30, 6)
|
|
|
|
|
2021-02-19 18:04:27 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.strokepath(path, strokeWidth = 10)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/masks/strokePolygon.png")
|
2021-02-27 00:42:40 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.rect(rect(25, 25, 50, 50))
|
|
|
|
|
2021-02-27 00:42:40 +00:00
|
|
|
let mask = newMask(100, 100)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.fillpath(path)
|
2021-02-27 00:42:40 +00:00
|
|
|
mask.blur(20)
|
2022-07-09 18:08:34 +00:00
|
|
|
mask.xray("tests/images/maskblur20.png")
|
2021-06-18 21:03:25 +00:00
|
|
|
|
|
|
|
block:
|
2021-08-13 02:32:41 +00:00
|
|
|
let path = newPath()
|
|
|
|
path.rect(rect(25, 25, 150, 150))
|
|
|
|
|
2021-06-18 21:03:25 +00:00
|
|
|
let mask = newMask(200, 200)
|
2021-08-13 02:32:41 +00:00
|
|
|
mask.fillPath(path)
|
2021-06-18 21:03:25 +00:00
|
|
|
mask.blur(25)
|
|
|
|
|
|
|
|
let minified = mask.minifyBy2()
|
2022-07-09 18:08:34 +00:00
|
|
|
minified.xray("tests/masks/minifiedBlur.png")
|
2022-06-21 02:40:09 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let path = newPath()
|
|
|
|
path.polygon(vec2(50, 50), 30, 6)
|
|
|
|
|
|
|
|
let mask = newMask(100, 100)
|
|
|
|
mask.fillPath(path)
|
|
|
|
|
|
|
|
let magnified = mask.magnifyBy2()
|
2022-07-09 18:08:34 +00:00
|
|
|
magnified.xray("tests/masks/drawPolygonMagnified.png")
|