Sequential Execution
This execution order is different from dataflow-only systems like Grasshopper or Max/MSP, where execution order depends solely on wire connections. In b5, position matters.Execution Order Example
Given blocks arranged on the grid:The execution follows the grid coordinates: blocks are sorted by row (y-coordinate) first, then by column (x-coordinate) within each row.
Playground vs Factory
The b5 editor has two distinct execution environments:Playground
60 FPS Loop
The Playground canvas runs 60 times per second by default, similar to the
draw() function in p5.js.- Executes left-to-right, top-to-bottom
- Runs on every frame (60 FPS)
- Can access variables and functions defined in Factory
- Updates the canvas in real-time
Factory
The Factory section has three subsections with different execution behaviors:Variables
Variables
Similar to the
setup() function in p5.js, the Variable section:- Executes once before the Playground starts
- Runs left-to-right, top-to-bottom within the section
- Creates reusable values accessible in Playground
- Triggers a sketch reset when modified
- No input nodes
- Static output values
- A preview that shows in the Factory sidebar
Functions
Functions
Function definitions in Factory:
- Don’t execute until called from Playground
- Define reusable logic with inputs and outputs
- Execute left-to-right, top-to-bottom when called
- Can be used multiple times in Playground
Objects
Objects
Position Constraints
The position-based execution model creates important constraints:Wire Direction Rules
Wires can only flow downward in terms of row position. This ensures execution order stays predictable.
- Input connections must come from blocks in previous rows (smaller y-index)
- Output connections must go to blocks in later rows (larger y-index)
- Blocks cannot connect to other blocks on the same row through input/output wires
Same-Line Restrictions
From the source code (codeBlocks.js:363-374):- It has input connections from blocks at or below that row
- It has output connections to blocks at or above that row
Real-Time Execution
Live Coding
b5 features live coding - changes to your visual code are reflected immediately without restarting the sketch.
- The sketch continues running at 60 FPS
- Changes take effect on the next frame
- The canvas updates in real-time
- No need to restart or recompile
- Variables trigger a sketch reset
- Functions update their definition for future calls
- The Playground restarts with new definitions
Grid System
The execution order is determined by the grid coordinate system:Each block occupies a grid cell defined by:
- x-coordinate (column): determines left-right order
- y-coordinate (row/line): determines top-bottom order
roomWidth: horizontal spacing between columnslineHeight: vertical spacing between rows
Execution Flow Diagram
Why Position-Based?
The position-based execution model provides several benefits:Readable
Code reads like text: left-to-right, top-to-bottom - a familiar mental model
Predictable
Execution order is always visible from block positions
Structured
The grid naturally organizes code into logical sections
Sequential
Perfect for animation and drawing operations that need specific ordering