Skip to content

Commit

Permalink
add new gradient lolcat
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Sep 5, 2024
1 parent 32ec415 commit 062033c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
use clap::{Parser, ValueEnum};
use std::f32::consts::{FRAC_PI_3, PI};
use std::path;

use clap::{Parser, ValueEnum};
use colorgrad::Color;

const PI2_3: f32 = PI * 2.0 / 3.0;

struct LolcatGradient {}

impl colorgrad::Gradient for LolcatGradient {
fn at(&self, t: f32) -> Color {
let t = (0.5 - t) * PI;
Color::new(
(t + FRAC_PI_3).sin().powi(2).clamp(0.0, 1.0),
t.sin().powi(2).clamp(0.0, 1.0),
(t + PI2_3).sin().powi(2).clamp(0.0, 1.0),
1.0,
)
}
}

#[derive(Debug, Clone, ValueEnum)]
pub enum Mode {
Linear,
Expand All @@ -14,6 +33,7 @@ pub enum Gradient {
Cubehelix,
Fruits,
Inferno,
Lolcat,
Magma,
Plasma,
Rainbow,
Expand All @@ -32,6 +52,7 @@ impl Gradient {
Gradient::Cool => Box::new(colorgrad::preset::cool()),
Gradient::Cubehelix => Box::new(colorgrad::preset::cubehelix_default()),
Gradient::Inferno => Box::new(colorgrad::preset::inferno()),
Gradient::Lolcat => Box::new(LolcatGradient {}),
Gradient::Magma => Box::new(colorgrad::preset::magma()),
Gradient::Plasma => Box::new(colorgrad::preset::plasma()),
Gradient::Rainbow => Box::new(colorgrad::preset::rainbow()),
Expand Down

0 comments on commit 062033c

Please sign in to comment.