p5js_gleam
Types
Assets that are loaded in preload
like images and fonts. Can be used later during rendering.
pub opaque type Assets
A reference to the P5js library. Primarily used to access the P5js APIs for drawing.
pub type P5
A reference to a P5js font object. Should be used by passing it to the P5js textFont
function.
pub type P5Font
A reference to a P5js image object. Should be used by passing it to the P5js image
function.
pub type P5Image
Configuration to start a sketch. Requires an init function to create the initial model, and a draw function to draw the model. Other handlers can also be provided to update the model based on different user events. Use the create_sketch
function and the set_*
helpers to initialize your config.
pub opaque type SketchConfig(model, ignored)
Functions
pub fn create_sketch(
init init: fn(P5) -> a,
draw draw: fn(P5, a) -> b,
) -> SketchConfig(a, b)
Creates a minimal sketch configuration.
pub fn create_sketch_with_preloading(
preload preload: fn(P5) -> Assets,
init init: fn(P5) -> a,
draw draw: fn(P5, a, Assets) -> b,
) -> SketchConfig(a, b)
Creates a sketch configuration that supports preloading assets.
pub fn get_font(
assets: Assets,
font_key: String,
) -> Result(P5Font, Nil)
Get a font from the asset set.
pub fn get_image(
assets: Assets,
image_key: String,
) -> Result(P5Image, Nil)
Get an image from the asset set.
pub fn insert_font(
assets: Assets,
font_key: String,
font: P5Font,
) -> Assets
Adds a font to the asset set.
pub fn insert_image(
assets: Assets,
image_key: String,
image: P5Image,
) -> Assets
Adds an image to the asset set.
pub fn set_on_key_pressed(
s: SketchConfig(a, b),
on_key_pressed: fn(String, Int, a) -> a,
) -> SketchConfig(a, b)
Sets the on_key_pressed
function to be called.
pub fn set_on_key_released(
s: SketchConfig(a, b),
on_key_released: fn(String, Int, a) -> a,
) -> SketchConfig(a, b)
Sets the on_key_released
function to be called.
pub fn set_on_mouse_clicked(
s: SketchConfig(a, b),
on_mouse_clicked: fn(Float, Float, a) -> a,
) -> SketchConfig(a, b)
Sets the on_mouse_clicked
function to be called.
pub fn set_on_mouse_moved(
s: SketchConfig(a, b),
on_mouse_moved: fn(Float, Float, a) -> a,
) -> SketchConfig(a, b)
Sets the on_mouse_moved
function to be called.
pub fn set_on_tick(
s: SketchConfig(a, b),
on_tick: fn(a) -> a,
) -> SketchConfig(a, b)
Sets the on_tick
function to be called.