mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-20 19:24:53 +00:00
Add animation framework
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const Animation = @import("../tui/Animation.zig");
|
||||
const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
|
||||
const utils = @import("../tui/utils.zig");
|
||||
|
||||
@@ -43,7 +44,15 @@ pub fn init(terminal_buffer: *TerminalBuffer, col1: u32, col2: u32, col3: u32) C
|
||||
};
|
||||
}
|
||||
|
||||
pub fn draw(self: *ColorMix) void {
|
||||
pub fn animation(self: *ColorMix) Animation {
|
||||
return Animation.init(self, deinit, realloc, draw);
|
||||
}
|
||||
|
||||
fn deinit(_: *ColorMix) void {}
|
||||
|
||||
fn realloc(_: *ColorMix) anyerror!void {}
|
||||
|
||||
fn draw(self: *ColorMix) void {
|
||||
self.frames +%= 1;
|
||||
const time: f32 = @as(f32, @floatFromInt(self.frames)) * time_scale;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Animation = @import("../tui/Animation.zig");
|
||||
const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
|
||||
const utils = @import("../tui/utils.zig");
|
||||
|
||||
@@ -38,17 +39,21 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, top_color: u
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: Doom) void {
|
||||
pub fn animation(self: *Doom) Animation {
|
||||
return Animation.init(self, deinit, realloc, draw);
|
||||
}
|
||||
|
||||
fn deinit(self: *Doom) void {
|
||||
self.allocator.free(self.buffer);
|
||||
}
|
||||
|
||||
pub fn realloc(self: *Doom) !void {
|
||||
fn realloc(self: *Doom) anyerror!void {
|
||||
const buffer = try self.allocator.realloc(self.buffer, self.terminal_buffer.width * self.terminal_buffer.height);
|
||||
initBuffer(buffer, self.terminal_buffer.width);
|
||||
self.buffer = buffer;
|
||||
}
|
||||
|
||||
pub fn draw(self: Doom) void {
|
||||
fn draw(self: *Doom) void {
|
||||
for (0..self.terminal_buffer.width) |x| {
|
||||
for (1..self.terminal_buffer.height) |y| {
|
||||
const source = y * self.terminal_buffer.width + x;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Random = std.Random;
|
||||
const Animation = @import("../tui/Animation.zig");
|
||||
const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
|
||||
const utils = @import("../tui/utils.zig");
|
||||
|
||||
@@ -54,12 +55,16 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, fg_ini: u32,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: Matrix) void {
|
||||
pub fn animation(self: *Matrix) Animation {
|
||||
return Animation.init(self, deinit, realloc, draw);
|
||||
}
|
||||
|
||||
fn deinit(self: *Matrix) void {
|
||||
self.allocator.free(self.dots);
|
||||
self.allocator.free(self.lines);
|
||||
}
|
||||
|
||||
pub fn realloc(self: *Matrix) !void {
|
||||
fn realloc(self: *Matrix) anyerror!void {
|
||||
const dots = try self.allocator.realloc(self.dots, self.terminal_buffer.width * (self.terminal_buffer.height + 1));
|
||||
const lines = try self.allocator.realloc(self.lines, self.terminal_buffer.width);
|
||||
|
||||
@@ -69,7 +74,7 @@ pub fn realloc(self: *Matrix) !void {
|
||||
self.lines = lines;
|
||||
}
|
||||
|
||||
pub fn draw(self: *Matrix) void {
|
||||
fn draw(self: *Matrix) void {
|
||||
const buf_height = self.terminal_buffer.height;
|
||||
const buf_width = self.terminal_buffer.width;
|
||||
self.count += 1;
|
||||
|
||||
Reference in New Issue
Block a user