Overview
Drawing shapes is fundamental to creating graphics in b5. This guide covers:- Using basic drawing blocks like
circleandlineXY - Styling shapes with stroke and fill colors
- Working with effect blocks for visual styling
- Understanding the drawing context
All shape drawing happens in the Playground section, which runs at 60 FPS by default.
Basic Shape Blocks
Circle
Thecircle block draws a circle at specified coordinates:
X coordinate of the circle’s center
Y coordinate of the circle’s center
Radius of the circle
Line
ThelineXY block draws a line between two points. From the line drawing example:
Styling Shapes
Stroke Color
UsestrokePicker for quick color selection or strokeRGBA for dynamic colors:
Fill Color
Similarly, usefillPicker or fillRGBA for fill colors:
Line Drawing Example Analysis
The line drawing example demonstrates interactive graphics with dynamic styling:Setup Black Background
The example uses a custom This function implementation:The low alpha value (20) creates a trailing effect as previous frames slowly fade.
blackBG function to create a semi-transparent background:Get Canvas Corners
A custom This outputs:
canvasCorners variable provides the corner coordinates:- Output 0: (0, 0) - top-left corner
- Output 1: (width, 0) - top-right corner
- Output 2: (width, height) - bottom-right corner
Random Color on Click
The The function uses three
randomRGB custom function generates random colors when the mouse is pressed:random blocks to generate R, G, B values between 170 and 220:Effect Block Behavior
Understanding Effect Blocks
Understanding Effect Blocks
Effect blocks set the drawing context for subsequent shapes. In b5:
- Sequential Execution: Blocks execute left-to-right, top-to-bottom
- Context Persistence: Effect blocks remain active until changed
- Visual Feedback: Selected effect blocks highlight their effective range in the grid
Common Patterns
Gradient Effects
Gradient Effects
Map position to color values for gradient effects:
Motion Trails
Motion Trails
Use semi-transparent backgrounds to create trailing effects:
Conditional Drawing
Conditional Drawing
Use blocks like
stopDraw to conditionally halt drawing:Canvas Coordinates
Understanding the coordinate system:- Origin (0, 0) is at the top-left corner
- X increases to the right
- Y increases downward
- Use
canvasSizeto get width and height
Next Steps
Interactive Graphics
Add mouse and keyboard interactions to your drawings
Animations
Create animated graphics and motion effects
Drawing Blocks Reference
Complete reference for all drawing blocks
Color Blocks Reference
Learn about all color and styling options