optimize fading of trails

This commit is contained in:
Felix Ableitner 2021-10-06 11:30:53 +02:00
parent 8b49ae2792
commit 4b176baabf

View file

@ -26,15 +26,11 @@ async fn main() {
loop { loop {
// fade trails (doesnt really work) // fade trails (doesnt really work)
let frame_time = get_frame_time(); let frame_time = get_frame_time();
for x in 0..MAP_WIDTH { trail_map.bytes.iter_mut().for_each(|b| {
for y in 0..MAP_HEIGHT { if *b > 0 {
let mut current_pixel = trail_map.get_pixel(x, y); *b -= 1;
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);
}
} }
});
// actions // actions
ants.iter_mut().for_each(|ant| { ants.iter_mut().for_each(|ant| {
ant.walk(frame_time, &mut trail_map); ant.walk(frame_time, &mut trail_map);