What Are Effect Blocks?
Effect blocks affect other blocks based on their contextual relationship - their position on the grid - rather than through wire connections.
fill(), stroke(), and scale() that set the drawing context for subsequent shapes, b5’s effect blocks work the same way but make their scope visually explicit.
Visual Scope Indication
Grid Highlighting
When you select an effect block, the background grid cells change color to show exactly which blocks are affected by that effect.
When an effect block is selected, the background grid cells will also change color to reflect its effective range, unlike when working with text-based languages, the underlying status of the drawing context always remains hidden to the users and needs to be inferred from the actual behavior of the program.This visual feedback makes the “hidden state” of drawing context visible and explicit.
Types of Effect Blocks
The source code defines effect blocks inmagicalIndex.js:14-32:
Color Effect Blocks
Fill Effects
Fill Effects
Control the fill color for shapes drawn after them:
fillPicker- Visual color picker for fillfillRGBA- Set fill using RGBA valuesnoFill- Disable fill for subsequent shapes
Stroke Effects
Stroke Effects
Control the stroke (outline) for shapes:
strokePicker- Visual color picker for strokestrokeRGBA- Set stroke using RGBA valuesnoStroke- Disable stroke for subsequent shapesstrokeWeight- Set stroke thicknessstrokeWeightSlider- Interactive slider for stroke weight
Draw Control
Draw Control
Control whether shapes are drawn:
stopDraw- Stop rendering shapes after this pointstartDraw- Resume rendering shapes
Transformation Effects
translate- Move the origin pointrotate- Rotate the coordinate system
Effect Types
FrommagicalIndex.js:5-12, effect blocks have different scope types:
The
quadratic block is Type 2 (Surroundings), meaning it has a different scope pattern than standard effect blocks.Example: Bounce Ball
From the example1.b5.json file, here’s how effect blocks work in practice:Setting Stroke Color
strokePicker effect block. This sets the stroke color to blue.
Setting Fill Color
Drawing with Effects
circle block at Row 5, Column 3 is drawn after both the strokePicker and fillRGBA effect blocks (reading left-to-right), so it uses:
- Blue stroke (from strokePicker)
- Dynamic RGB fill (from fillRGBA)
Effect vs. Data Flow
Data Flow (Wires)
Explicit connections that pass specific values from output nodes to input nodes.Used for: Numbers, colors, positions, calculations
Effect Flow (Position)
Implicit context that affects blocks based on execution order.Used for: Drawing styles, transformations, global state
When to Use Each
Use wired data flow when:- You need to pass a specific value to a specific input
- The relationship should be explicit
- Different blocks need different values
- You want to set a style for multiple shapes
- The effect should apply to a sequence of operations
- You’re managing drawing context or global state
Combining Effects and Data
Many effect blocks can both receive wired inputs and affect subsequent blocks:fillRGBA block:
- Receives color values through wires (data flow)
- Sets the fill context for blocks after it (effect flow)
Visibility of State
In text-based p5.js code:Effect Block Best Practices
Position Effects Before Use
Place effect blocks in earlier rows (higher up) than the blocks they should affect.
Group Related Effects
Keep effect blocks that work together (fill, stroke, strokeWeight) on the same row, left of the shapes they affect.
Use Visual Feedback
Click on effect blocks to see their scope - the grid highlighting helps you verify which blocks are affected.
Technical Implementation
Effect blocks are identified in the codebase through the_colorEffectIndex in magicalIndex.js. When rendering, the system:
- Tracks which effect blocks have been executed
- Applies their context to the drawing state
- Maintains that context for subsequent blocks
- Highlights grid cells when an effect block is selected