xiaohongshu
xiaohongshu
k1-architecture
Deep understanding of K1.reinvented's compilation architecture, node system, and extension methodology. Teaches why graphs compile to C++ and how to extend the system without violating minimalism.
Full skill instructions
For three years, every LED project architecture fell into the same trap: flexibility OR performance. You could have creative freedom OR execution speed, never both.
K1.reinvented proves this is a false choice. The insight is simple but profound:
Move the creative work to the computer. Move the execution work to the device.
Don't ask the device to interpret JSON at runtime. Don't ask it to evaluate node graphs in real-time. Don't force a tiny embedded system to be both flexible AND fast.
Instead:
The node graph exists ONLY at development time. It guides code generation. Then it disappears. What runs on the device is pure C++ that looks exactly like what you'd write by hand.
This is the revolution: compilation as creative medium, not optimization trick.
Input: graphs/departure.json - Visual node graph describing the pattern
{
"name": "Departure",
"nodes": [
{"id": "position", "type": "position_gradient"},
{"id": "palette", "type": "palette_interpolate", "parameters": {"palette": "departure"}},
{"id": "output", "type": "output"}
],
"wires": [...],
"palette_data": [[0, 8, 3, 0], [32, 45, 25, 0], ...]
}
Process: TypeScript compiler (codegen/src/index.ts) walks the graph:
firmware/src/generated_effect.hOutput: Pure C++ code with no runtime graph interpretation
void draw_generated_effect() {
static float field_buffer[NUM_LEDS];
static CRGBF color_buffer[NUM_LEDS];
// position_gradient: Map LED index to 0.0-1.0
for (int i = 0; i < NUM_LEDS; i++) {
field_buffer[i] = (float)i / (NUM_LEDS - 1);
}
// palette_interpolate: Interpolate between keyframes
const uint8_t palette_keyframes[] = {0, 8, 3, 0, 32, 45, 25, 0, ...};
for (int i = 0; i < NUM_LEDS; i++) {
// ... interpolation logic ...
}
// output: Write to LED array
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = color_buffer[i];
}
}
Process: PlatformIO + GCC compile the generated C++:
Outcome: 450+ FPS execution with zero overhead. The graph structure has completely disappeared.
Every node has a type that determines what code it generates. Currently supported:
position_gradient
gradient (HSV gradient)
palette_interpolate (CRITICAL NODE)
palette_data from graphhsv_to_rgb
output
The minimalist principle: Only add node types that serve beauty. If it doesn't enable new forms of artistic expression, don't add it.
sine_wave Node1. Define the node type in graph JSON:
{"id": "wave", "type": "sine_wave", "parameters": {"frequency": 3.0, "amplitude": 0.5}}
2. Add case to codegen (codegen/src/index.ts):
case 'sine_wave':
const freq = node.parameters?.frequency ?? 1.0;
const amp = node.parameters?.amplitude ?? 1.0;
return `
// Node: ${node.id} (sine_wave)
for (int i = 0; i < NUM_LEDS; i++) {
float t = field_buffer[i];
field_buffer[i] = ${amp}f * sin(t * ${freq}f * TWO_PI);
}`;
3. Test with all three patterns:
4. Verify it serves beauty:
Bad reason to add a node: "It would be technically elegant to have a full math library"
Good reason to add a node: "This enables expressing emotions that weren't possible before"
codegen/src/index.ts (~280 lines)
Critical Functions:
function generateNodeCode(node: Node, graph: Graph): string
// Takes a node definition, returns C++ code string
// This is where artistic intent becomes executable code
function compileGraph(graph: Graph): string
// Orchestrates entire compilation process
// Returns complete C++ file content
Uses simple string templates, NOT complex C++ metaprogramming:
const effectTemplate = `
void draw_generated_effect() {
{{#each steps}}
{{{this}}}
{{/each}}
}`;
Why Handlebars instead of C++ templates?
Symptom: npm run compile throws error
Check:
Fix: Correct the JSON graph definition
Symptom: PlatformIO build fails with C++ errors
Check:
firmware/src/generated_effect.hFix: Fix the code generation logic in codegen/src/index.ts for that node type
Symptom: Serial.println shows 200-300 FPS
Check:
delay() calls in the main loop?Fix: Profile where cycles are going, optimize the bottleneck
Symptom: Pattern doesn't match expected visual
Check:
Fix: Debug the palette interpolation logic in generated C++
Calculation:
Wait, how is 450 FPS possible?
Answer: Non-blocking transmission via RMT peripheral
Breakdown per frame (180 LEDs):
The RMT transmission is the bottleneck, not the computation.
Ask these questions:
If all four are YES: Add it. If any are NO: Don't.
Examples of GOOD additions:
Examples of BAD additions:
Every architectural decision serves the mission: Prove flexibility and performance aren't opposites.
Compilation philosophy: Flexibility at development time, performance at execution time Node system: Composable primitives that maintain minimalism Code generation: Transparent, debuggable, understandable Performance target: Uncompromising 450+ FPS
If you find yourself adding complexity that doesn't serve this mission, stop. Delete it. Return to clarity.
Phase B: Expand node types (10-15 types total)
Phase C: Visual editor
Phase D: Audio reactivity
But everything must maintain:
This architecture works because it respects both domains completely:
Artistic domain: Visual node graphs, intuitive composition, creative freedom Execution domain: Compiled C++, native speed, zero overhead
The compilation step is the bridge. It's not a convenience—it's the insight that makes the entire system possible.
Understanding this deeply is what separates maintaining the code from owning the vision.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience