Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.mbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test "paths examples" {

// Get path bounds
match path.bounds() {
Some(bounds) => println("Path bounds: " + bounds.to_string())
Some(bounds) => println("Path bounds: " + @debug.to_string(bounds))
None => println("Empty path")
}

Expand Down Expand Up @@ -824,4 +824,4 @@ ISC License (same as original Vg library)
## Credits

Original Vg library by Daniel Bünzli: https://github.com/dbuenzli/vg
MoonBit port with extensive tests and examples.
MoonBit port with extensive tests and examples.
8 changes: 4 additions & 4 deletions __snapshot__/spirograph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 45 additions & 8 deletions advanced_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ test "quadratic bezier curves" (it : @test.Test) {
.qcurve_to(@vg.Point::new(50.0, 10.0), @vg.Point::new(90.0, 50.0)) // Arch shape
.qcurve_to(@vg.Point::new(50.0, 90.0), @vg.Point::new(10.0, 50.0)) // Return with opposite arch
.close_path()
inspect(
@debug.debug_inspect(
qcurve_path,
content="Path([MoveTo({x: 10, y: 50}), QCurveTo({x: 50, y: 10}, {x: 90, y: 50}), QCurveTo({x: 50, y: 90}, {x: 10, y: 50}), Close])",
content=(
#|Path(
#| [
#| MoveTo({ x: 10, y: 50 }),
#| QCurveTo({ x: 50, y: 10 }, { x: 90, y: 50 }),
#| QCurveTo({ x: 50, y: 90 }, { x: 10, y: 50 }),
#| Close,
#| ],
#|)
),
)
let doc = @svg.new_svg(100.0, 100.0)
.render_rectangle(0.0, 0.0, 100.0, 100.0, @color.gray(0.95))
Expand All @@ -26,9 +35,18 @@ test "elliptical arcs" (it : @test.Test) {
.earc_to(30.0, 20.0, 0.0, false, true, @vg.Point::new(80.0, 50.0)) // Elliptical arc
.earc_to(30.0, 20.0, 0.0, false, true, @vg.Point::new(20.0, 50.0)) // Return arc
.close_path()
inspect(
@debug.debug_inspect(
arc_path,
content="Path([MoveTo({x: 20, y: 50}), EArcTo(30, 20, 0, false, true, {x: 80, y: 50}), EArcTo(30, 20, 0, false, true, {x: 20, y: 50}), Close])",
content=(
#|Path(
#| [
#| MoveTo({ x: 20, y: 50 }),
#| EArcTo(30, 20, 0, false, true, { x: 80, y: 50 }),
#| EArcTo(30, 20, 0, false, true, { x: 20, y: 50 }),
#| Close,
#| ],
#|)
),
)
let doc = @svg.new_svg(100.0, 100.0)
.render_rectangle(0.0, 0.0, 100.0, 100.0, @color.gray(0.95))
Expand All @@ -49,9 +67,18 @@ test "smooth curve stitching" (it : @test.Test) {
)
.smooth_ccurve_to(@vg.Point::new(110.0, 90.0), @vg.Point::new(130.0, 50.0)) // Smooth continuation
.smooth_ccurve_to(@vg.Point::new(150.0, 10.0), @vg.Point::new(170.0, 50.0)) // Another smooth curve
inspect(
@debug.debug_inspect(
smooth_path,
content="Path([MoveTo({x: 10, y: 50}), CurveTo({x: 30, y: 10}, {x: 50, y: 10}, {x: 70, y: 50}), CurveTo({x: 90, y: 90}, {x: 110, y: 90}, {x: 130, y: 50}), CurveTo({x: 150, y: 10}, {x: 150, y: 10}, {x: 170, y: 50})])",
content=(
#|Path(
#| [
#| MoveTo({ x: 10, y: 50 }),
#| CurveTo({ x: 30, y: 10 }, { x: 50, y: 10 }, { x: 70, y: 50 }),
#| CurveTo({ x: 90, y: 90 }, { x: 110, y: 90 }, { x: 130, y: 50 }),
#| CurveTo({ x: 150, y: 10 }, { x: 150, y: 10 }, { x: 170, y: 50 }),
#| ],
#|)
),
)
let doc = @svg.new_svg(180.0, 100.0)
.render_rectangle(0.0, 0.0, 180.0, 100.0, @color.gray(0.95))
Expand Down Expand Up @@ -99,10 +126,20 @@ test "advanced blend modes" {
("hard_light_blend", @color.hard_light_blend(red, blue)),
("soft_light_blend", @color.soft_light_blend(red, blue)),
]
inspect(
@debug.debug_inspect(
blend_results,
content=(
#|[("normal_blend", {r: 0.8333333333333335, g: 0, b: 0.16666666666666666, a: 0.96}), ("multiply_blend", {r: 0, g: 0, b: 0, a: 0.96}), ("screen_blend", {r: 1, g: 0, b: 1, a: 0.96}), ("overlay_blend", {r: 1, g: 0, b: 0, a: 0.96}), ("hard_light_blend", {r: 0, g: 0, b: 1, a: 0.96}), ("soft_light_blend", {r: 1, g: 0, b: 0, a: 0.96})]
#|[
#| (
#| "normal_blend",
#| { r: 0.8333333333333335, g: 0, b: 0.16666666666666666, a: 0.96 },
#| ),
#| ("multiply_blend", { r: 0, g: 0, b: 0, a: 0.96 }),
#| ("screen_blend", { r: 1, g: 0, b: 1, a: 0.96 }),
#| ("overlay_blend", { r: 1, g: 0, b: 0, a: 0.96 }),
#| ("hard_light_blend", { r: 0, g: 0, b: 1, a: 0.96 }),
#| ("soft_light_blend", { r: 1, g: 0, b: 0, a: 0.96 }),
#|]
),
)
}
Expand Down
2 changes: 1 addition & 1 deletion canvas/canvas.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct CanvasDocument {
width : Double
height : Double
commands : Array[String]
} derive(Show)
} derive(Debug)

///|
/// Create a new Canvas document
Expand Down
3 changes: 2 additions & 1 deletion canvas/moon.pkg
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
"moonbitlang/core/debug",
"bobzhang/vg/geometry",
"bobzhang/vg/color",
}

options(
"is-main": false,
)
)
92 changes: 77 additions & 15 deletions color/color_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@
///|
test "rgba color creation" {
let c = @color.rgba(0.5, 0.7, 0.9, 0.8)
inspect(c, content="{r: 0.5, g: 0.7, b: 0.9, a: 0.8}")
@debug.debug_inspect(
c,
content=(
#|{ r: 0.5, g: 0.7, b: 0.9, a: 0.8 }
),
)
}

///|
test "rgb color creation" {
let c = @color.rgb(0.2, 0.4, 0.6)
inspect(c, content="{r: 0.2, g: 0.4, b: 0.6, a: 1}")
@debug.debug_inspect(
c,
content=(
#|{ r: 0.2, g: 0.4, b: 0.6, a: 1 }
),
)
}

///|
test "gray color creation" {
let c = @color.gray(0.5)
inspect(c, content="{r: 0.5, g: 0.5, b: 0.5, a: 1}")
@debug.debug_inspect(
c,
content=(
#|{ r: 0.5, g: 0.5, b: 0.5, a: 1 }
),
)
}

///|
test "transparent color" {
let c = @color.transparent()
inspect(c, content="{r: 0, g: 0, b: 0, a: 0}")
@debug.debug_inspect(
c,
content=(
#|{ r: 0, g: 0, b: 0, a: 0 }
),
)
}

///|
Expand All @@ -39,10 +59,22 @@ test "predefined colors" {
("purple", @color.purple()),
("gold", @color.gold()),
]
inspect(
@debug.debug_inspect(
colors,
content=(
#|[("red", {r: 1, g: 0, b: 0, a: 1}), ("green", {r: 0, g: 1, b: 0, a: 1}), ("blue", {r: 0, g: 0, b: 1, a: 1}), ("white", {r: 1, g: 1, b: 1, a: 1}), ("black", {r: 0, g: 0, b: 0, a: 1}), ("cyan", {r: 0, g: 1, b: 1, a: 1}), ("magenta", {r: 1, g: 0, b: 1, a: 1}), ("yellow", {r: 1, g: 1, b: 0, a: 1}), ("orange", {r: 1, g: 0.647, b: 0, a: 1}), ("purple", {r: 0.5, g: 0, b: 0.5, a: 1}), ("gold", {r: 1, g: 0.843, b: 0, a: 1})]
#|[
#| ("red", { r: 1, g: 0, b: 0, a: 1 }),
#| ("green", { r: 0, g: 1, b: 0, a: 1 }),
#| ("blue", { r: 0, g: 0, b: 1, a: 1 }),
#| ("white", { r: 1, g: 1, b: 1, a: 1 }),
#| ("black", { r: 0, g: 0, b: 0, a: 1 }),
#| ("cyan", { r: 0, g: 1, b: 1, a: 1 }),
#| ("magenta", { r: 1, g: 0, b: 1, a: 1 }),
#| ("yellow", { r: 1, g: 1, b: 0, a: 1 }),
#| ("orange", { r: 1, g: 0.647, b: 0, a: 1 }),
#| ("purple", { r: 0.5, g: 0, b: 0.5, a: 1 }),
#| ("gold", { r: 1, g: 0.843, b: 0, a: 1 }),
#|]
),
)
}
Expand All @@ -52,17 +84,24 @@ test "color blending" {
let c1 = @color.rgba(1.0, 0.0, 0.0, 0.5) // Semi-transparent red
let c2 = @color.rgba(0.0, 1.0, 0.0, 0.5) // Semi-transparent green
let blended = @color.blend(c1, c2)
inspect(
@debug.debug_inspect(
blended,
content="{r: 0.6666666666666666, g: 0.3333333333333333, b: 0, a: 0.75}",
content=(
#|{ r: 0.6666666666666666, g: 0.3333333333333333, b: 0, a: 0.75 }
),
)
}

///|
test "color scaling" {
let c = @color.rgb(0.8, 0.6, 0.4)
let scaled = @color.scale(c, 0.5)
inspect(scaled, content="{r: 0.4, g: 0.3, b: 0.2, a: 1}")
@debug.debug_inspect(
scaled,
content=(
#|{ r: 0.4, g: 0.3, b: 0.2, a: 1 }
),
)
}

///|
Expand Down Expand Up @@ -90,10 +129,16 @@ test "color to hex conversion" {
),
("gray", @color.gray(0.5), @color.to_hex(@color.gray(0.5))),
]
inspect(
@debug.debug_inspect(
colors_and_hex,
content=(
#|[("red", {r: 1, g: 0, b: 0, a: 1}, "#FF0000"), ("green", {r: 0, g: 1, b: 0, a: 1}, "#00FF00"), ("blue", {r: 0, g: 0, b: 1, a: 1}, "#0000FF"), ("orange", {r: 1, g: 0.5, b: 0, a: 1}, "#FF7F00"), ("gray", {r: 0.5, g: 0.5, b: 0.5, a: 1}, "#7F7F7F")]
#|[
#| ("red", { r: 1, g: 0, b: 0, a: 1 }, "#FF0000"),
#| ("green", { r: 0, g: 1, b: 0, a: 1 }, "#00FF00"),
#| ("blue", { r: 0, g: 0, b: 1, a: 1 }, "#0000FF"),
#| ("orange", { r: 1, g: 0.5, b: 0, a: 1 }, "#FF7F00"),
#| ("gray", { r: 0.5, g: 0.5, b: 0.5, a: 1 }, "#7F7F7F"),
#|]
),
)
}
Expand All @@ -110,10 +155,19 @@ test "hsv color space" {
("gray_hsv", @color.hsv(0.0, 0.0, 0.5)), // Gray (no saturation)
("dark_red", @color.hsv(0.0, 1.0, 0.5)), // Dark red (low value)
]
inspect(
@debug.debug_inspect(
hsv_colors,
content=(
#|[("red_hsv", {r: 1, g: 0, b: 0, a: 1}), ("green_hsv", {r: 0, g: 1, b: 0, a: 1}), ("blue_hsv", {r: 0, g: 0, b: 1, a: 1}), ("yellow_hsv", {r: 1, g: 1, b: 0, a: 1}), ("orange_hsv", {r: 1, g: 0.5, b: 0, a: 1}), ("purple_hsv", {r: 1, g: 0, b: 1, a: 1}), ("gray_hsv", {r: 0.5, g: 0.5, b: 0.5, a: 1}), ("dark_red", {r: 0.5, g: 0, b: 0, a: 1})]
#|[
#| ("red_hsv", { r: 1, g: 0, b: 0, a: 1 }),
#| ("green_hsv", { r: 0, g: 1, b: 0, a: 1 }),
#| ("blue_hsv", { r: 0, g: 0, b: 1, a: 1 }),
#| ("yellow_hsv", { r: 1, g: 1, b: 0, a: 1 }),
#| ("orange_hsv", { r: 1, g: 0.5, b: 0, a: 1 }),
#| ("purple_hsv", { r: 1, g: 0, b: 1, a: 1 }),
#| ("gray_hsv", { r: 0.5, g: 0.5, b: 0.5, a: 1 }),
#| ("dark_red", { r: 0.5, g: 0, b: 0, a: 1 }),
#|]
),
)
}
Expand All @@ -135,10 +189,18 @@ test "color interpolation" {
@color.lerp_color(@color.transparent(), @color.red(), 0.5),
),
]
inspect(
@debug.debug_inspect(
interpolations,
content=(
#|[("red_to_blue_0", {r: 1, g: 0, b: 0, a: 1}), ("red_to_blue_25", {r: 0.75, g: 0, b: 0.25, a: 1}), ("red_to_blue_50", {r: 0.5, g: 0, b: 0.5, a: 1}), ("red_to_blue_75", {r: 0.25, g: 0, b: 0.75, a: 1}), ("red_to_blue_100", {r: 0, g: 0, b: 1, a: 1}), ("white_to_black_50", {r: 0.5, g: 0.5, b: 0.5, a: 1}), ("transparent_to_opaque", {r: 0.5, g: 0, b: 0, a: 0.5})]
#|[
#| ("red_to_blue_0", { r: 1, g: 0, b: 0, a: 1 }),
#| ("red_to_blue_25", { r: 0.75, g: 0, b: 0.25, a: 1 }),
#| ("red_to_blue_50", { r: 0.5, g: 0, b: 0.5, a: 1 }),
#| ("red_to_blue_75", { r: 0.25, g: 0, b: 0.75, a: 1 }),
#| ("red_to_blue_100", { r: 0, g: 0, b: 1, a: 1 }),
#| ("white_to_black_50", { r: 0.5, g: 0.5, b: 0.5, a: 1 }),
#| ("transparent_to_opaque", { r: 0.5, g: 0, b: 0, a: 0.5 }),
#|]
),
)
}
6 changes: 5 additions & 1 deletion color/moon.pkg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
"moonbitlang/core/debug",
}

options(
"is-main": false,
)
)
2 changes: 1 addition & 1 deletion color/types.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub struct Color {
g : Double // Green component [0.0, 1.0]
b : Double // Blue component [0.0, 1.0]
a : Double // Alpha component [0.0, 1.0]
} derive(Eq, Show)
} derive(Eq, Debug)
Loading
Loading