p5_demos

    Demos for p5.mbt (MoonBit's port of p5.js): WEBGL scenes, shaders, particles, generative art and two short films.

    p5
    p5.js
    creative-coding
    demos
    webgl
    generative-art
    Download zip
    Author
    Version
    0.2.0
    License
    LGPL-2.1
    Last updated
    14 hours ago
    Downloads
    10

    #p5_demos

    Demos for p5.mbt, MoonBit's port of p5.js: WEBGL scenes, custom shaders, framebuffers, particles, generative art and two short films. Every demo is an executable package that imports bobzhang/p5 and compiles to JavaScript.

    DemoWhat it shows
    asiaFive Thousand Years of Asia, a two-minute WEBGL film in 13 chapters, with lit 3D scenes and CJK captions
    historyA Short History of Computation, a 104-second 2D film
    galaxy12,000 stars as POINTS with per-vertex colors, orbit_control
    lorenzthe Lorenz attractor as a 3D line colored by speed
    orrerylights, emissive/specular materials, generated textures, font-shader labels
    terrainnoise terrain from triangle strips, fog added to p5's material shader with a hook
    mandelbrota deep zoom in a custom fragment shader (create_shader, uniforms)
    feedbacktwo framebuffers feeding each other for trails
    boidsflocking: separation, alignment, cohesion; the mouse attracts
    particlestext_to_points words made of springy particles
    treea recursive tree swaying in Perlin-noise wind
    chromeimage-based lighting and a 360° background (image_light, panorama) on metal spheres
    type3dextruded 3D letters from font outlines (text_to_model)
    bumpybump and normal maps (bump_texture, normal_texture) generated in graphics buffers
    swarmGPU instancing: 8,000 boxes in one draw call (instances, gl_InstanceID in a shader hook)
    ribbonsa custom per-vertex attribute (vertex_property) read by shader hooks
    crta custom filter shader over a 2D sketch (create_filter_shader, filter_shader)
    materialsan OBJ model with MTL materials, a texture and a normal map (load_model)
    portalsclipping in WEBGL (begin_clip, end_clip, invert)
    accessiblescreen-reader descriptions and generated outputs (describe, text_output, grid_output)

    #Running

    The p5.mbt repository is a moon.work workspace containing both the library and this module, so one build compiles everything. From the repository root:

    moon build --target js --release python3 -m http.server 8765

    Then open http://localhost:8765/p5_demos/ for the gallery. Each page loads _build/js/release/build/bobzhang/p5_demos/<demo>/<demo>.js.

    The films accept ?t=SECONDS&still to show a single moment, and ?record to render frame-exact video with tools/record.py (see the p5.mbt README).

    #Writing your own

    Each demo is a package with a moon.pkg like

    import { "bobzhang/p5", } supported_targets = "js" pkgtype(kind: "executable")

    and a main that calls @p5.run(setup=..., draw=...).