bobzhang/p5/math does not have a README file
pub struct Matrix {
dim : Int
// private fields
}| a c e |
| b d f |
| 0 0 1 |pub struct Noise {
// private fields
}test {
let n = @math.Noise::new(42)
let v = n.noise(0.5, y=0.25)
assert_true(v >= 0 && v < 1)
}pub struct Random {
// private fields
}test {
let r = @math.Random::new(99)
// Same as `randomSeed(99); random()` in p5.js
inspect(
r.next(),
content=(
#|0.27443566313013434
),
)
}pub struct Vector {
x : Double
y : Double
z : Double
// private fields
}test {
let v = @math.Vector(3, 4)
inspect(v.mag(), content="5")
inspect(v, content="vector[3, 4, 0]")
}let DEG_TO_RAD : Doublelet RAD_TO_DEG : Doublefn constrain(n : Double, low : Double, high : Double) -> Doubletest {
inspect(@math.constrain(15, 0, 10), content="10")
inspect(@math.constrain(-1, 0, 10), content="0")
}fn dist(x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> Doublefn dist3(x1 : Double, y1 : Double, z1 : Double, x2 : Double, y2 : Double, z2 : Double) -> Doublefn fract(n : Double) -> Doublefn js_rem(a : Double, b : Double) -> Doublefn js_round(n : Double) -> Doublefn lerp(start : Double, stop : Double, amt : Double) -> Doublefn map(n : Double, start1 : Double, stop1 : Double, start2 : Double, stop2 : Double, within_bounds? : Bool) -> Doubletest {
inspect(@math.map(5, 0, 10, 0, 100), content="50")
inspect(@math.map(20, 0, 10, 0, 100, within_bounds=true), content="100")
}fn norm(n : Double, start : Double, stop : Double) -> Doublefn round(n : Double, decimals? : Int) -> Doubletest {
inspect(@math.round(2.5), content="3")
inspect(@math.round(-2.5), content="-2")
inspect(@math.round(3.14159, decimals=2), content="3.14")
}Install
Download zipA port of p5.js 2.x to MoonBit (JS backend): 2D canvas and WEBGL, fonts, SVG, GIF, shaders; pixel-identical with p5.js on its parity suite.