2020-12-03 07:20:14 +00:00
|
|
|
import pixie, chroma
|
|
|
|
|
2021-01-03 04:28:36 +00:00
|
|
|
block:
|
|
|
|
let pathStr = """
|
|
|
|
m 1 2 3 4 5 6
|
|
|
|
"""
|
|
|
|
let path = parsePath(pathStr)
|
|
|
|
doAssert $path == "m1 2 m3 4 m5 6"
|
|
|
|
|
2020-12-03 07:35:23 +00:00
|
|
|
block:
|
|
|
|
let pathStr = """
|
|
|
|
m 1 2
|
|
|
|
l 3 4
|
|
|
|
h 5
|
|
|
|
v 6
|
|
|
|
c 0 0 0 0 0 0
|
|
|
|
q 1 1 1 1
|
|
|
|
t 2 2
|
|
|
|
a 7 7 7 7 7 7 7
|
|
|
|
z
|
|
|
|
"""
|
|
|
|
let path = parsePath(pathStr)
|
|
|
|
doAssert $path == "m1 2 l3 4 h5 v6 c0 0 0 0 0 0 q1 1 1 1 t2 2 a7 7 7 7 7 7 7 Z"
|
|
|
|
|
|
|
|
block:
|
|
|
|
let pathStr = """
|
|
|
|
M 1 2
|
|
|
|
L 3 4
|
|
|
|
H 5
|
|
|
|
V 6
|
|
|
|
C 0 0 0 0 0 0
|
|
|
|
Q 1 1 1 1
|
|
|
|
T 2 2
|
|
|
|
A 7 7 7 7 7 7 7
|
|
|
|
z
|
|
|
|
"""
|
|
|
|
let path = parsePath(pathStr)
|
|
|
|
doAssert $path == "M1 2 L3 4 H5 V6 C0 0 0 0 0 0 Q1 1 1 1 T2 2 A7 7 7 7 7 7 7 Z"
|
|
|
|
|
2020-12-03 07:20:14 +00:00
|
|
|
block:
|
2021-01-22 14:42:21 +00:00
|
|
|
let
|
|
|
|
pathStr = "M 0.1E-10 0.1e10 L2+2 L3-3 L0.1E+10-1"
|
|
|
|
path = parsePath(pathStr)
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
2021-01-25 16:55:25 +00:00
|
|
|
let
|
|
|
|
image = newImage(100, 100)
|
|
|
|
pathStr = "M 10 10 L 90 90"
|
|
|
|
color = rgba(255, 0, 0, 255)
|
2020-12-03 07:20:14 +00:00
|
|
|
image.strokePath(pathStr, color, 10)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathStroke1.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
2021-01-25 16:55:25 +00:00
|
|
|
let
|
|
|
|
image = newImage(100, 100)
|
|
|
|
pathStr = "M 10 10 L 50 60 90 90"
|
|
|
|
color = rgba(255, 0, 0, 255)
|
2020-12-03 07:20:14 +00:00
|
|
|
image.strokePath(pathStr, color, 10)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathStroke2.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.strokePath(
|
|
|
|
"M 15 10 L 30 90 60 30 90 90",
|
|
|
|
rgba(255, 255, 0, 255),
|
|
|
|
strokeWidth = 10
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathStroke3.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
2021-01-25 16:55:25 +00:00
|
|
|
let
|
|
|
|
image = newImage(100, 100)
|
|
|
|
pathStr = "M 10 10 H 90 V 90 H 10 L 10 10"
|
|
|
|
color = rgba(0, 0, 0, 255)
|
2020-12-03 07:20:14 +00:00
|
|
|
image.fillPath(pathStr, color)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathBlackRectangle.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
2021-01-22 14:42:21 +00:00
|
|
|
block:
|
|
|
|
let
|
|
|
|
image = newImage(100, 100)
|
|
|
|
pathStr = "M 10 10 H 90 V 90 H 10 Z"
|
|
|
|
color = rgba(0, 0, 0, 255)
|
|
|
|
image.fillPath(parsePath(pathStr), color)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2021-01-22 14:42:21 +00:00
|
|
|
image.writeFile("tests/images/paths/pathBlackRectangleZ.png")
|
|
|
|
|
2020-12-03 07:20:14 +00:00
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(
|
|
|
|
"M 10 10 H 90 V 90 H 10 L 10 10",
|
|
|
|
rgba(255, 255, 0, 255)
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathYellowRectangle.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
2021-01-25 02:23:14 +00:00
|
|
|
var path: Path
|
2020-12-03 07:20:14 +00:00
|
|
|
path.moveTo(10, 10)
|
|
|
|
path.lineTo(10, 90)
|
|
|
|
path.lineTo(90, 90)
|
|
|
|
path.lineTo(90, 10)
|
|
|
|
path.lineTo(10, 10)
|
2021-01-25 16:55:25 +00:00
|
|
|
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(path, rgba(255, 0, 0, 255))
|
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathRedRectangle.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(
|
|
|
|
"M30 60 A 20 20 0 0 0 90 60 L 30 60",
|
|
|
|
parseHtmlColor("#FC427B").rgba
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathBottomArc.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(
|
|
|
|
"""
|
|
|
|
M 10,30
|
|
|
|
A 20,20 0,0,1 50,30
|
|
|
|
A 20,20 0,0,1 90,30
|
|
|
|
Q 90,60 50,90
|
|
|
|
Q 10,60 10,30 z
|
|
|
|
""",
|
|
|
|
parseHtmlColor("#FC427B").rgba
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathHeart.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(
|
|
|
|
"M 20 50 A 20 10 45 1 1 80 50 L 20 50",
|
|
|
|
parseHtmlColor("#FC427B").rgba
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathRotatedArc.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(
|
|
|
|
"M 0 50 A 50 50 0 0 0 50 0 L 50 50 L 0 50",
|
|
|
|
parseHtmlColor("#FC427B").rgba
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathInvertedCornerArc.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let image = newImage(100, 100)
|
|
|
|
image.fillPath(
|
|
|
|
"M 0 50 A 50 50 0 0 1 50 0 L 50 50 L 0 50",
|
|
|
|
parseHtmlColor("#FC427B").rgba
|
|
|
|
)
|
2021-01-25 16:55:25 +00:00
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathCornerArc.png")
|
2020-12-03 07:20:14 +00:00
|
|
|
|
|
|
|
block:
|
|
|
|
let
|
2021-01-25 02:23:14 +00:00
|
|
|
image = newImage(100, 100)
|
2020-12-03 07:20:14 +00:00
|
|
|
r = 10.0
|
|
|
|
x = 10.0
|
|
|
|
y = 10.0
|
|
|
|
h = 80.0
|
|
|
|
w = 80.0
|
2021-01-25 02:23:14 +00:00
|
|
|
var path: Path
|
2021-01-25 16:55:25 +00:00
|
|
|
path.moveTo(x + r, y)
|
|
|
|
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)
|
|
|
|
image.fillPath(path, rgba(255, 0, 0, 255))
|
|
|
|
image.toStraightAlpha()
|
2020-12-20 17:15:59 +00:00
|
|
|
image.writeFile("tests/images/paths/pathRoundRect.png")
|