[+] Draw title

This commit is contained in:
Azalea Gui
2023-03-08 12:06:30 -05:00
parent 079354af9c
commit 728f2a3081
+17 -5
View File
@@ -93,6 +93,7 @@ struct Consts {
asc_cat: AsciiArt, asc_cat: AsciiArt,
asc_tree: AsciiArt, asc_tree: AsciiArt,
asc_house: AsciiArt, asc_house: AsciiArt,
asc_title: AsciiArt,
} }
struct Mutes { struct Mutes {
@@ -142,10 +143,20 @@ impl Consts {
| ,--, ,--, | ,| | ,--, ,--, | ,|
,%| '--'._.'--' |,o%o ,%| '--'._.'--' |,o%o
.*%|_,%%_| |_%%,_|#%%%*"#, "Modified from hjw from ascii.co.uk/art/house"); .*%|_,%%_| |_%%,_|#%%%*"#, "Modified from hjw from ascii.co.uk/art/house");
let asc_title = AsciiArt::new(
r#"
. *
_.__. _.| _ _. ' __
(_] /_(_]|(/,(_] _)
.
__._ _ . , . |_ _ ._ _ _
_) [ )(_) \/\/ \_| [ )(_)[ | )(/,
._| "#, "Generated by patorjk.com/software/taag");
Self { Self {
asc_cat, asc_cat,
asc_tree, asc_tree,
asc_house, asc_house,
asc_title,
} }
} }
} }
@@ -303,6 +314,10 @@ fn draw_ascii_frame(mt: &mut Mutes, cn: &Consts) {
mt.print_ascii(&cn.asc_house, (mt.w + cn.asc_house.w) / 2, mt.h - cn.asc_house.h, mt.print_ascii(&cn.asc_house, (mt.w + cn.asc_house.w) / 2, mt.h - cn.asc_house.h,
"\x1b[38;2;251;194;110m"); "\x1b[38;2;251;194;110m");
// Draw title at the center of the screen
mt.print_ascii(&cn.asc_title, (mt.w - cn.asc_title.w) / 2, (mt.h - cn.asc_title.h) / 2,
"\x1b[38;2;255;231;151m");
// Draw chat bubble // Draw chat bubble
let bubble = gen_bubble_ascii("I wish I could\nlive on that tree."); let bubble = gen_bubble_ascii("I wish I could\nlive on that tree.");
mt.print_ascii(&bubble, mt.x + 5, mt.h - cn.asc_cat.h - bubble.h, "\x1b[38;2;255;231;151m"); mt.print_ascii(&bubble, mt.x + 5, mt.h - cn.asc_cat.h - bubble.h, "\x1b[38;2;255;231;151m");
@@ -321,23 +336,20 @@ fn start_loop(mt: &mut Mutes, cn: &Consts) {
// Calculate the delta time // Calculate the delta time
let dt = (now - mt.last_update).as_secs_f32(); let dt = (now - mt.last_update).as_secs_f32();
mt.last_update = now; mt.last_update = now;
let start = Instant::now();
// Update the snow // Update the snow
mt.update_snow(dt); mt.update_snow(dt);
draw_ascii_frame(mt, cn); draw_ascii_frame(mt, cn);
// Draw the buffer, time it, and print it // Draw the buffer, time it, and print it
let start = Instant::now();
let txt = mt.draw_buf().unwrap(); let txt = mt.draw_buf().unwrap();
let end = Instant::now(); let end = Instant::now();
let draw_time = (end - start).as_secs_f32(); let draw_time = (end - start).as_secs_f32();
print!("\rDraw time: {:.2}ms", draw_time * 1000.0); print!("\rDraw time: {:.2}ms", draw_time * 1000.0);
print!("{}", txt); print!("{}", txt);
// Set cursor to the bottom of the screen
print!("\x1b[9999;9999H");
// Sleep for 1/20th of a second // Sleep for 1/20th of a second
thread::sleep(Duration::from_millis(1000 / 20)); thread::sleep(Duration::from_millis(1000 / 20));
} }