Skip to content

Instantly share code, notes, and snippets.

@ShabbirHasan1
Forked from fasterthanlime/marine_line.rs
Created August 23, 2024 09:41
Show Gist options
  • Save ShabbirHasan1/7e6684bad6d693bb0b6a1946d14bcfbf to your computer and use it in GitHub Desktop.
Save ShabbirHasan1/7e6684bad6d693bb0b6a1946d14bcfbf to your computer and use it in GitHub Desktop.
fn marine_line() -> String {
use rand::{seq::SliceRandom, Rng};
let marine_life = ["🐳", "🐠", "🦈", "πŸ™", "🐑", "🐬", "🐟", "πŸ¦€", "πŸ‹"];
let water = [
"\x1B[38;2;0;100;200mβ‰ˆ\x1B[0m",
"\x1B[38;2;10;110;210mβ‰ˆ\x1B[0m",
"\x1B[38;2;20;120;220mβ‰ˆ\x1B[0m",
"\x1B[38;2;30;130;230mβ‰ˆ\x1B[0m",
"\x1B[38;2;40;140;240mβ‰ˆ\x1B[0m",
"\x1B[38;2;50;150;250mβ‰ˆ\x1B[0m",
"\x1B[38;2;60;160;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;70;170;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;80;180;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;90;190;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;100;200;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;110;210;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;120;220;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;130;230;255mβ‰ˆ\x1B[0m",
"\x1B[38;2;140;240;255mβ‰ˆ\x1B[0m",
];
let mut buffer = String::new();
let mut last_generated = "";
for i in 0..80 {
let position = i as f32 / 80.0;
let middle_weight = 1.0 - (position - 0.5).abs() * 2.0;
let chance = 0.125 + middle_weight * 0.125; // Ranges from 0.125 to 0.25
let set = if rand::thread_rng().gen::<f32>() < (chance * 0.5) {
&marine_life[..]
} else {
&water[..]
};
let generated = *set.choose(&mut rand::thread_rng()).unwrap();
if generated == last_generated {
buffer.push_str(water.choose(&mut rand::thread_rng()).unwrap());
} else {
buffer.push_str(generated);
last_generated = generated;
}
}
buffer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment