Data Flow Fundamentals
Data flows from top to bottom through wires, connecting output nodes (bottom of blocks) to input nodes (top of blocks).
The Flow Direction
- Generated or computed in Block A
- Exits through Block A’s output node
- Travels through the wire
- Enters Block B’s input node
- Used by Block B in its operation
Input and Output Structure
From the source code, blocks store their connections in specific data structures:Input Data Structure
- Has an array
[y, x, nodeIndex]pointing to the source block and output node - Is
nullif not connected
Output Data Structure
- Each output node can connect to multiple input nodes
- Empty array
[]means no connections - Each connection is
[y, x, inputNodeIndex]
Data Flow Example: Bounce Ball
Let’s trace data flow in the example bounce ball program:Step 1: Create the Radius Value
- Generates a number value (40, adjustable 0-50)
- Outputs to two destinations:
- Row 5, Column 3, Input 2 (circle’s radius)
- Row 1, Column 2, Input 0 (boundaries function)
Step 2: Calculate Boundaries
boundaries function:
- Receives radius from Row 0, Column 1
- Calculates boundary values
- Outputs three values:
- Output 0: Lower boundary (used by two bounce blocks)
- Output 1: Upper x boundary
- Output 2: Upper y boundary
Step 3: Bounce Physics
- Receives three inputs (bounds and step)
- Computes bouncing position
- Outputs to circle x-position AND fill red value
Complete Data Flow Diagram
Node Offset and Wire Rendering
The system tracks the visual position of nodes for rendering wires. FromcodeBlocks.js:545-568:
WireRenderer component to draw wires between the actual pixel positions of connected nodes.
Type Information in Data Flow
Node types determine what data can flow through connections. FromblockRenderer.js:333-342:
- Input nodes display the type of data they’re receiving
- Wire color reflects the data type
- Type information comes from the parent block’s output node definition
Type checking helps ensure you’re connecting compatible data. Visual feedback through node colors makes type mismatches obvious.
Data Flow Patterns
Fan-Out Pattern
One output feeding multiple inputs:- The same value is needed in multiple places
- You want to reuse a calculation
- Multiple operations depend on one input
Chain Pattern
Sequential data transformation:- Data needs multiple transformation steps
- Building complex calculations from simple operations
- Creating processing pipelines
Merge Pattern
Multiple inputs to one operation:- Combining multiple values
- Mathematical operations (add, multiply, etc.)
- Functions with multiple parameters
Inline Data vs. Wired Data
Blocks can receive data in two ways:Inline Data
- Set through direct user input
- Visible on the block itself
- No wire connections needed
Wired Data
- Comes from other blocks’ outputs
- Dynamic and recomputed each frame
- Creates dependencies between blocks
Debugging Data Flow
Visual Inspection
- Follow the wires - Visual connections show data paths
- Check node connections - Hover over nodes to see what they expect/provide
- Select blocks - Focus highlights show relationships
Connection Validation
FromcodeBlocks.js:267-276, the system validates connections:
- Data flows in the correct direction (downward)
- Execution order matches data dependencies
- No circular dependencies
Live Data Updates
Real-time Execution
At 60 FPS, data flows through your entire program every frame. Changes to any input immediately propagate through all connected blocks.
- Inline data updates instantly
- Output node generates new value
- Wires carry new value to connected inputs
- Dependent blocks recompute with new value
- Canvas updates on next frame
Data Flow Best Practices
Organize by Flow
Arrange blocks so data flows naturally from top to bottom, matching the visual wire direction.
Reuse Calculations
Use fan-out patterns to avoid duplicating the same calculation in multiple places.
Keep Dependencies Clear
Minimize crossing wires and long-distance connections for easier visual parsing.
Summary
Data flow in b5 is:- Visual - Wires show explicit data paths
- Top-down - Data flows from outputs to inputs, following execution order
- Flexible - Supports fan-out, chains, and merging patterns
- Real-time - Updates 60 times per second for interactive experiences
- Type-aware - Node colors and validation help prevent errors