Code
extern function malloc(i32): u32; extern function draw(u32, u32, u32); extern function requestAnimationFrame(u32); u32 ax = 0; u32 fillColor = 0; u32 bufferptr = 0; function callback() { clear(bufferptr); fillRect(bufferptr, 0, ax, 0, 16, 16); fillRect(bufferptr, fillColor, ax, 0, 16, 16); ax += 1; draw(bufferptr, 0, 0); requestAnimationFrame(callback); } function clear(u32 buffer) { u32 i = 0; while (i <
buffer[4] *
buffer[8]) {
(
buffer)[i * 4] = 0; i += 1; } } function fillRect(u32 ptr, u32 color, u32 x, u32 y, u32 w, u32 h) { u32 px = x; u32 py = y; while (py < y + h) { px = x; while (px < x + w) {
(
ptr + (px + py *
ptr[4]) * 4) = color; px += 1; } py += 1; } } public function main() { u32 width = 100; u32 height = 100; u32 buffer = malloc((i32)(width * height) * 4); bufferptr = malloc(12);
bufferptr = buffer;
bufferptr[4] = width;
bufferptr[8] = height; fillColor = 255 + (0 << 8) + (0 << 16) + (255 << 24); requestAnimationFrame(callback); }
Wat
Compile
Run
Compile & Run
Output