p5-style creative coding for MoUI: sketch lifecycle, color, math, paths, images, and surfaces drawn through MoUI command streams
type ImageFetcher = (String, (Bytes?) -> Unit) -> Unitpub(open) trait ImageSource {
fn image_size(Self) -> (Double, Double)
fn draw_as_image(Self, Sketch, Double, Double, Double, Double) -> Unit
}pub(open) trait Num {
fn to_num(Self) -> Double
}pub(open) trait Surface {
fn set_transform(Self, Matrix) -> Unit
fn save(Self) -> Unit
fn restore(Self) -> Unit
fn fill_path(Self, Path, Color) -> Unit
fn stroke_path(Self, Path, Color, Double, StrokeCap, StrokeJoin) -> Unit
fn fill_rect(Self, Double, Double, Double, Double, Color) -> Unit
fn fill_rounded_rect(Self, Double, Double, Double, Double, Double, Color) -> Unit
fn stroke_rounded_rect(Self, Double, Double, Double, Double, Double, Color, Double) -> Unit
fn clear_rect(Self, Double, Double, Double, Double) -> Unit
fn draw_image(Self, Image, Double, Double, Double, Double, Double, Color?) -> Unit
fn clip_path(Self, Path) -> Unit
fn clip_end(Self) -> Unit
fn fill_text(Self, String, Double, Double, Color, Color?, Double, FontSpec, HAlign, VAlign) -> Unit
fn measure_width(Self, String, FontSpec) -> Double
fn text_metrics(Self, FontSpec) -> TextMetrics
fn set_blend_mode(Self, BlendMode) -> Unit
fn set_smoothing(Self, Bool) -> Unit
}pub(all) enum BlendMode {
Blend
Multiply
Screen
Overlay
Darken
Lighten
Add
Difference
Exclusion
HardLight
SoftLight
Dodge
Burn
} derive(Eq)pub struct FilePorts {
load : (String) -> Bytes?
save : (String, Bytes) -> Bool
}pub(all) enum Filter {
Threshold(Double)
Gray
Opaque
Invert
Posterize(Int)
Blur(Double)
Erode
Dilate
} derive(Eq)pub(all) struct FontSpec {
family : String
size : Double
weight : Int
italic : Bool
leading : Double
} derive(Eq)pub struct Image {
pixels : FixedArray[Byte]
// private fields
}impl ImageSource for Imagepub(all) struct Matrix {
a : Double
b : Double
c : Double
d : Double
tx : Double
ty : Double
} derive(Eq)pub struct Noise {
// private fields
}pub(all) struct NullSurface {
marker : Bool
}impl Surface for NullSurfacefn draw_image(_ : NullSurface, _ : Image, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color?) -> Unitfn fill_rounded_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color) -> Unitfn stroke_path(_ : NullSurface, _ : Path, _ : Color, _ : Double, _ : StrokeCap, _ : StrokeJoin) -> Unitfn stroke_rounded_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color, _ : Double) -> Unitfn NullSurface::draw_image(_ : NullSurface, _ : Image, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color?) -> Unitfn NullSurface::fill_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color) -> Unitfn NullSurface::fill_rounded_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color) -> Unitfn NullSurface::fill_text(_ : NullSurface, _ : String, _ : Double, _ : Double, _ : Color, _ : Color?, _ : Double, _ : FontSpec, _ : HAlign, _ : VAlign) -> Unitfn NullSurface::stroke_path(_ : NullSurface, _ : Path, _ : Color, _ : Double, _ : StrokeCap, _ : StrokeJoin) -> Unitfn NullSurface::stroke_rounded_rect(_ : NullSurface, _ : Double, _ : Double, _ : Double, _ : Double, _ : Double, _ : Color, _ : Double) -> Unitpub(all) enum PathCmd {
MoveTo(Double, Double)
LineTo(Double, Double)
QuadTo(Double, Double, Double, Double)
CubicTo(Double, Double, Double, Double, Double, Double)
Close
} derive(Eq)pub struct Random {
// private fields
}fn stroke_path(self : Recorder, path : Path, color : Color, width : Double, _cap : StrokeCap, _join : StrokeJoin) -> Unitpub struct Sketch {
width : Double
height : Double
frame_count : Int
delta_time : Double
elapsed_ms : Double
mouse_x : Double
mouse_y : Double
pmouse_x : Double
pmouse_y : Double
moved_x : Double
moved_y : Double
mouse_is_pressed : Bool
mouse_button : Int
touches : Array[Touch]
composing : Bool
composition_text : String
last_input_text : String
key : String
code : String
key_is_pressed : Bool
key_code : Int
focused : Bool
// private fields
}impl ImageSource for Sketchfn[T : ImageSource] Sketch::image(self : Sketch, source : T, x : Double, y : Double, width? : Double, height? : Double) -> Unitpub(all) struct TextMetrics {
width : Double
height : Double
ascent : Double
descent : Double
} derive(Eq)fn TextMetrics::new(width~ : Double, height~ : Double, ascent~ : Double, descent~ : Double) -> TextMetricspub(all) struct Touch {
x : Double
y : Double
win_x : Double
win_y : Double
id : Int
pressure : Double
} derive(Eq)pub struct Vector {
x : Double
y : Double
z : Double
}fn clear_default_file_ports() -> Unitfn dist3(x1 : Double, y1 : Double, z1 : Double, x2 : Double, y2 : Double, z2 : Double) -> Doublefn fract(value : Double) -> Doublefn js_round(value : Double) -> Doublefn map(value : Double, start1 : Double, stop1 : Double, start2 : Double, stop2 : Double, within_bounds? : Bool) -> Doublefn set_default_image_fetcher(fetcher : (String, (Bytes?) -> Unit) -> Unit?) -> UnitInstall
Download zipp5-style creative coding for MoUI: sketch lifecycle, color, math, paths, images, and surfaces drawn through MoUI command streams