cargo-color-gen

Crates.iocargo-color-gen
lib.rscargo-color-gen
version0.2.1
created_at2025-04-07 14:35:06.431027+00
updated_at2025-04-09 12:25:32.720743+00
descriptionNOT MAINTAINED: A tool for generating color schemes
homepage
repositoryhttps://github.com/dsgallups/color-gen
max_upload_size
id1624251
size84,741
Daniel Gallups (dsgallups)

documentation

README

⚠️ This repository is no longer maintained ⚠️

This project has been moved to bevygen.

If you would like to own this crate's name, please contact me!

Cargo Color Generator

github crates.io

Generate constant color palettes (for bevy via color schemes)

Get Started

install via cargo install cargo-color-gen

Then, with a tailwind scheme and output file: cargo color-gen -i examples/example.json -o example_output/coloors_output.rs

Input Schema

A schema that looks something like this.

{
    "sandy_brown": {
        "100": "#462001",
        "600": "#fdbc87",
        "900": "#feeee1"
    },
    "redwood": {
        "700": "#d58a8792", // alpha channel included
        "800": "#e3b1af",
        "900": "#f1d8d7",
        "NO_WORK": "#GGGGGG" // generated file will state this has failed
    }
}

Additionally, it can be a JS object and this cli will attempt to reformat it as a JSON.

You can specify a JSON file with the -i parameter, or paste your json as a single line.

Pretty-printed JSONs through -stdin will fail. This may need some work.

How to generate an input schema

This CLI was built with the intention of supporting the - Tailwind Export of coolors.co.

This is a good starting point for working with your palettes!

If there is a need for quickly switching between palettes (as opposed to the current constant colors generated), please let me know!

Output

The above input will generate the following:

/// Generated using `color-gen` v0.2
use bevy::color::Color;
///Original hex: #462001
pub const SANDY_BROWN_100: Color = Color::srgb(
    0.27450982f32,
    0.1254902f32,
    0.003921569f32,
);
///Original hex: #fdbc87
pub const SANDY_BROWN_600: Color = Color::srgb(
    0.99215686f32,
    0.7372549f32,
    0.5294118f32,
);
///Original hex: #feeee1
pub const SANDY_BROWN_900: Color = Color::srgb(
    0.99607843f32,
    0.93333334f32,
    0.88235295f32,
);
///Original hex: #e3b1af
pub const REDWOOD_800: Color = Color::srgb(0.8901961f32, 0.69411767f32, 0.6862745f32);
///Original hex: #f1d8d7
pub const REDWOOD_900: Color = Color::srgb(0.94509804f32, 0.84705883f32, 0.84313726f32);
///Original hex: #d58a8792
pub const REDWOOD_700: Color = Color::srgba(
    0.8352941f32,
    0.5411765f32,
    0.5294118f32,
    0.57254905f32,
);
/**Error parsing hex #GGGGGG
r: Err(ParseIntError { kind: InvalidDigit })
g: Err(ParseIntError { kind: InvalidDigit })
b: Err(ParseIntError { kind: InvalidDigit })*/
pub const REDWOOD_NO_WORK: () = ();

If you specify an output -o, the output will save to that file. Otherwise, it will be printed to stdout.

Help/Suggestions wanted!

Please let me know what formats should be supported. Additionally, I've got some thoughts:

  • it could be nice to make strongly typed palettes with enumerations
  • Other schema types
  • correct parsing of JS Objects (most scheme generators return this, not JSON)
Commit count: 18

cargo fmt