From 4b176baabfcf6012a861307e56affa015f6152ac Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 6 Oct 2021 11:30:53 +0200 Subject: [PATCH] optimize fading of trails --- src/main.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 283197b..02b361f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,15 +26,11 @@ async fn main() { loop { // fade trails (doesnt really work) let frame_time = get_frame_time(); - for x in 0..MAP_WIDTH { - for y in 0..MAP_HEIGHT { - let mut current_pixel = trail_map.get_pixel(x, y); - current_pixel.r -= 0.1 * frame_time; - current_pixel.g -= 0.1 * frame_time; - current_pixel.b -= 0.1 * frame_time; - trail_map.set_pixel(x, y, current_pixel); + trail_map.bytes.iter_mut().for_each(|b| { + if *b > 0 { + *b -= 1; } - } + }); // actions ants.iter_mut().for_each(|ant| { ant.walk(frame_time, &mut trail_map);