Zebra Color Sequence Implementation Plan #
Current Rainbow Implementation Analysis #
Overview #
The rainbow color theme in Aesthetic Computer is a special dynamic color sequence that cycles through rainbow colors. It's implemented across multiple layers of the system with special handling in both the color system and KidLisp interpreter.
Current Rainbow Implementation #
1. Core Rainbow Function (num.mjs) #
- Location:
/system/public/aesthetic.computer/lib/num.mjslines 735-751 - Implementation:
let currentRainbowIndex = 0; const rainbowColors = [ cssColors.red, cssColors.orange, cssColors.yellow, cssColors.green, cssColors.blue, cssColors.indigo, cssColors.violet, ]; export function rainbow() { const color = rainbowColors[currentRainbowIndex]; currentRainbowIndex = (currentRainbowIndex + 1) % rainbowColors.length; return color.slice(); }
2. Color Parsing Support (num.mjs) #
- Location: Lines 522-523
- Special case handling: When parsing color names,
"rainbow"returns["rainbow", alpha]instead of RGB values - Integration: Exported to disk.mjs as
rainbow: num.rainbow(line 1896)
3. Graphics System Integration (graph.mjs) #
- Rainbow caching: Uses
currentRainbowColorto cache rainbow value per drawing operation - Fade support: Rainbow colors work within fade sequences (lines 278-299)
- Special markers: Uses
["rainbow", alpha]as special markers that get resolved at render time
4. KidLisp Integration (kidlisp.mjs) #
- Function binding:
rainbow: (api) => api.num?.rainbow() || [255, 0, 0](lines 3525-3526) - Color validation: Special validation for rainbow colors (line 918)
- Syntax highlighting: Rainbow text gets colored character-by-character with rainbow colors (lines 977-987)
- Optimization handling: Special cases for rainbow in optimization routines (lines 1104-1131)
5. Palette System #
- P0 mapping:
p0palette maps to"rainbow"(num.mjs line 837) - Palette resolution: Special handling in
intToPalette()function (lines 1015-1016)
Syntax Highlighting Implementation #
The syntax highlighting for rainbow in KidLisp uses this pattern:
if (colorValue === "RAINBOW") {
const rainbowColors = ["red", "orange", "yellow", "lime", "blue", "purple", "magenta"];
for (let charIndex = 0; charIndex < colorName.length; charIndex++) {
const charColor = rainbowColors[charIndex % rainbowColors.length];
result += `\\${charColor}\\${colorName[charIndex]}`;
}
}
Proposed Zebra Implementation #
1. Core Zebra Function (num.mjs) #
Add alongside the rainbow function:
// ๐ฆ Zebra color cycling (black/white alternating)
let currentZebraIndex = 0;
const zebraColors = [
cssColors.black, // [0, 0, 0]
cssColors.white, // [255, 255, 255]
];
export function zebra() {
const color = zebraColors[currentZebraIndex];
currentZebraIndex = (currentZebraIndex + 1) % zebraColors.length;
return color.slice();
}
2. Color Parsing Support (num.mjs) #
Add to the parseColor function around line 523:
} else if (name === "rainbow") {
return ["rainbow", alpha];
} else if (name === "zebra") {
return ["zebra", alpha];
} else {
3. Export to Disk System (disk.mjs) #
Add to the num exports around line 1896:
rainbow: num.rainbow,
zebra: num.zebra,
4. Graphics System Support (graph.mjs) #
Update the rainbow handling to support zebra:
// Update rainbow color once per drawing operation if needed
if (currentRainbowColor === null && fadeColors.some(color =>
color[0] === "rainbow" || color[0] === "zebra")) {
currentRainbowColor = rainbow();
}
// Add zebra caching
let currentZebraColor = null;
if (currentZebraColor === null && fadeColors.some(color => color[0] === "zebra")) {
currentZebraColor = zebra();
}
// Handle dynamic colors
if (startColor[0] === "rainbow") {
startColor = [...currentRainbowColor, startColor[1] || 255];
} else if (startColor[0] === "zebra") {
startColor = [...currentZebraColor, startColor[1] || 255];
}
5. KidLisp Integration (kidlisp.mjs) #
Function Binding #
Add around line 3526:
rainbow: (api) => {
return api.num?.rainbow() || [255, 0, 0];
},
zebra: (api) => {
return api.num?.zebra() || [0, 0, 0];
},
Syntax Highlighting #
Update the color highlighting code around lines 977-987:
} else if (colorName === "rainbow") {
colorValue = "RAINBOW";
} else if (colorName === "zebra") {
colorValue = "ZEBRA";
// Later in the highlighting section:
if (colorValue === "RAINBOW") {
const rainbowColors = ["red", "orange", "yellow", "lime", "blue", "purple", "magenta"];
for (let charIndex = 0; charIndex < colorName.length; charIndex++) {
const charColor = rainbowColors[charIndex % rainbowColors.length];
result += `\\${charColor}\\${colorName[charIndex]}`;
}
} else if (colorValue === "ZEBRA") {
const zebraColors = ["black", "white"];
for (let charIndex = 0; charIndex < colorName.length; charIndex++) {
const charColor = zebraColors[charIndex % zebraColors.length];
result += `\\${charColor}\\${colorName[charIndex]}`;
}
}
Color Validation #
Update validation around line 918:
typeof result === "string" && (result.startsWith("fade:") ||
result === "rainbow" || result === "zebra");
6. Palette System Extension #
Could optionally add zebra as a palette:
// In paletteColorMap
1: "zebra", // p1 = zebra
Implementation Steps #
โ
1. Add zebra function to num.mjs - Core cycling function
โ
2. Update color parsing in num.mjs - Handle "zebra" string
โ
3. Export zebra to disk.mjs - Make available to pieces
โ
4. Add KidLisp function binding - (zebra) function
โ
5. Add syntax highlighting support - Alternating black/white characters (Fixed: Added missing token recognition in 2 locations)
โ
6. Update graphics system - Handle zebra in fades and caching
โ
7. Add validation support - Include zebra in color validation
โ
8. Add palette mapping - p1 = zebra
โ
9. Add fade support - zebra works in fade sequences
โ
10. Add disk validation - bare "zebra" recognized as KidLisp
โ
11. Update colors.mjs index - Add zebra to color listing piece (Fixed: Added directional fade preview support)
IMPLEMENTATION COMPLETED! ๐ #
The zebra color sequence has been successfully implemented across all layers of the Aesthetic Computer system. Here's what's now available:
(ink zebra)- Sets ink to alternating black/white(zebra)- Function that returns current zebra colorp1- Palette shorthand for zebra (p1 is zebra)zebra- Bare color name works as piece content- Syntax highlighting - "zebra" displays with alternating black/white letters
- Fade support - Works in sequences like
fade:black-zebra-white - Graphics integration - Works with all drawing primitives (line, rect, circle, etc.)
๐ง Additional Fixes Made: #
- Fixed fade direction previews in colors.mjs - Now correctly shows vertical, diagonal, and angled fades in thumbnails
- Added animated dynamic colors in fades -
fade:zebra-rainbownow shows animated zebra and rainbow colors - Added comprehensive fade examples including
fade:red-blue:verticaland directional fade support - Enhanced colors.mjs with proper p0/p1 palette support and zebra animations
- Fixed missing color names - Added
darkbrown,darkerbrown,darksiennato CSS colors for c124, c125, c126 - Updated section labels - "PALETTE COLORS" โ "SEQUENCES", "SPECIAL COLORS" โ "FADES"
- Removed unwanted built-in fades - Removed 'ocean', 'sunset', and 'fire' from both implementation and documentation
- Fixed fade:zebra-rainbow thumbnail - Now shows proper animated gradient between current zebra and rainbow colors
- Added continuous repainting logic - Thumbnails with dynamic colors now animate properly by returning appropriate paint state
Future Extensibility #
This pattern can be extended to support additional color sequences:
gradient- smooth color transitionsneon- bright electric colorspastel- soft muted colors
Each would follow the same pattern:
- Core cycling function in
num.mjs - Color parsing support
- Export to disk system
- KidLisp integration
- Graphics system support
- Syntax highlighting (optional)
Files to Modify #
/system/public/aesthetic.computer/lib/num.mjs- Core implementation/system/public/aesthetic.computer/lib/disk.mjs- Export zebra function/system/public/aesthetic.computer/lib/kidlisp.mjs- KidLisp integration/system/public/aesthetic.computer/lib/graph.mjs- Graphics support/system/public/aesthetic.computer/disks/colors.mjs- Color index listing piece
Testing Considerations #
- Test
(ink zebra)in KidLisp pieces - Test zebra in fade sequences:
fade:black-zebra-white - Test zebra syntax highlighting in KidLisp editor
- Test zebra with various graphics primitives (line, rect, circle)
- Test zebra persistence across frame boundaries