35 lines
1.2 KiB
Zig
35 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const grome = @import("root.zig");
|
|
|
|
const Io = std.Io;
|
|
const Rect = grome.matrix.Rect;
|
|
const DoubleBuffer = grome.draw.DoubleBuffer;
|
|
const Duration = Io.Duration;
|
|
const Clock = Io.Clock;
|
|
|
|
pub fn main(init: std.process.Init) !void {
|
|
// This is appropriate for anything that lives as long as the process.
|
|
const arena: std.mem.Allocator = init.arena.allocator();
|
|
|
|
// Initialize the stdout writer
|
|
var stdout_buffer: [1024]u8 = undefined;
|
|
var stdout_file_writer: Io.File.Writer = .init(.stdout(), init.io, &stdout_buffer);
|
|
|
|
// alright lets play with the matrix
|
|
const size = Rect{ .height = 20, .width = 50 };
|
|
var double_buf = try DoubleBuffer.init(arena, size);
|
|
|
|
const density = size.area() / 100;
|
|
while (true) {
|
|
var frame = double_buf.frame(.{ .x = 0, .y = 0 }, size);
|
|
for (0..density) |_| {
|
|
var buf: [3]u8 = undefined;
|
|
init.io.random(&buf);
|
|
try frame.set(.{ .x = @intCast(buf[0] % size.width), .y = @intCast(buf[1] % size.height) }, .{ .char = [_]u8{@intCast((buf[2] % 50) + 93)} ** 8, .width = 1 });
|
|
}
|
|
|
|
_ = try double_buf.render(&stdout_file_writer.interface);
|
|
try init.io.sleep(Duration.fromMilliseconds(100), Clock.real);
|
|
}
|
|
}
|