Overview
The Spiral serializer arranges DMX channels in a spiral pattern starting from the origin (0,0) and moving outward. This creates a distinctive visual pattern useful for debugging video transmission, testing capture systems, and creating visual effects.Class: Spiral
Namespace: GlobalImplements:
IDMXSerializer
Configuration Constants
Size in pixels of each channel block (8×8 pixels). Larger than other serializers for better visibility.
Instance Variables
Current X position in the spiral (in block coordinates, not pixels)
Current Y position in the spiral (in block coordinates, not pixels)
Current direction state:
- 0 = Moving right (+X)
- 1 = Moving up (+Y)
- 2 = Moving left (-X)
- 3 = Moving down (-Y)
Tracks all visited positions to prevent overlap and trigger direction changes
How It Works
Spiral Algorithm
The spiral follows a clockwise pattern:- Start at (0,0) moving right
- Move right until hitting a wall or visited cell → turn up
- Move up until collision → turn left
- Move left until collision → turn down
- Move down until collision → turn right
- Repeat, spiraling inward
Direction States
| State | Direction | Delta |
|---|---|---|
| 0 | Right | (+1, 0) |
| 1 | Up | (0, +1) |
| 2 | Left | (-1, 0) |
| 3 | Down | (0, -1) |
Collision Detection
The spiral changes direction when:- Next position has been visited before (self-collision)
- Next position is out of bounds (< 0 or >= texture size)
Methods
InitFrame
Resets the spiral state at the start of each frame.The list of channel values (not used by this method)
- Resets position to (0, 0)
- Clears the visited positions list
- Resets direction state to 0 (right)
SerializeChannel
Encodes a DMX channel at the current spiral position and advances to the next position.The pixel array to write to
The DMX channel value (0-255) to encode as grayscale
The DMX channel number (not directly used - position determined by spiral)
Width of the output texture in pixels
Height of the output texture in pixels
- Calculates texture dimensions in block coordinates
- Converts current block position (x, y) to pixel position
- Writes an 8×8 grayscale block at the current position
- Calculates the next position based on current direction
- Checks for collisions (visited or out-of-bounds)
- If collision detected, rotates direction clockwise
- Adds current position to visited list
- Updates position to next position
CalculateNextMove
Calculates the next position based on the current direction state.DeserializeChannel
Decoding is not implemented.Usage Example
Visual Pattern Example
For a 64×64 pixel texture (8×8 blocks) with 8 channels:Channel Capacity
Capacity depends on texture size and block size:Capacity by Resolution
| Resolution | Block Grid | Channels |
|---|---|---|
| 128×128 | 16×16 | 256 |
| 256×256 | 32×32 | 1,024 |
| 512×512 | 64×64 | 4,096 |
| 1024×1024 | 128×128 | 16,384 |
| 1920×1080 | 240×135 | 32,400 |
Advantages
Visual Tracking
Easy to track data flow and identify transmission issues
Debugging
Pattern makes it obvious if frames are dropped or corrupted
Large Blocks
8×8 blocks are highly visible and compression-resistant
Deterministic
Same spiral path every frame ensures consistency
Limitations
- Position-Dependent: Channel values are determined by spiral position, not channel number
- Sequential Only: Must encode all channels in order; cannot encode individual channels
- No Random Access: Cannot directly encode channel N without encoding 0 through N-1
- Frame State: Requires
InitFrameto be called before each frame
Use Cases
1. Visual Debugging
Verify video capture is working correctly:2. Transmission Testing
Test video quality by analyzing spiral continuity:3. Visual Effects
Create animated spiral patterns:Best Practices
1. Always Call InitFrame
2. Sequential Encoding
Encode channels in sequential order:3. Verify Capacity
Ensure channel count fits in texture:Comparison with Other Serializers
| Feature | Spiral | Binary | VRSL |
|---|---|---|---|
| Block Size | 8×8 | 4×4 | 16×16 |
| Pattern | Spiral | Grid | Grid |
| Encoding | Grayscale | Binary | Grayscale |
| Channels (256×256) | 1,024 | 416 | 169 |
| Visual | High | Low | Medium |
| Decoding | No | Yes | Yes |
| Use Case | Debug | Data | Production |
Performance
- Encoding: ~0.015ms per channel
- Collision Detection: O(n) where n = visited positions
- Memory: O(n) for visited list (cleared each frame)
- InitFrame: ~0.001ms
The visited list grows with each channel, making later channels slightly slower to encode. For typical frame sizes (< 1000 channels), this is negligible.
Advanced Usage
Custom Spiral Patterns
Modify the direction sequence for different patterns:Spiral from Center
Start from texture center instead of corner:Troubleshooting
Spiral doesn't fill entire texture
Spiral doesn't fill entire texture
The spiral may terminate early if it gets trapped. This happens when:
- All adjacent cells are visited or out of bounds
- Texture dimensions aren’t evenly divisible by block size
Blocks appear in wrong positions
Blocks appear in wrong positions
This occurs if
InitFrame is not called before encoding a frame.Solution: Always call InitFrame at the start of each frame.Spiral pattern looks wrong
Spiral pattern looks wrong
Verify channels are being encoded in sequential order.Solution: Encode channels 0, 1, 2, 3… in order.
When to Use
✅ Good for:- Debugging video transmission systems
- Visual monitoring of data flow
- Testing video capture quality
- Creating animated spiral effects
- Demonstrations and presentations
- Production DMX systems (no decoder)
- Applications requiring random channel access
- Systems needing bidirectional communication
- Maximum channel density requirements