This prototype demonstrates how to generate deterministic color palettes from seed strings in Julia and reproduce the same palettes in JavaScript. The Julia implementation uses Gay.jl, a lightweight wrapper around the Colors.jl ecosystem, to seed a random number generator from a string and then produce an array of RGB colors. By seeding the PRNG with a stable integer derived from the seed text, you can obtain consistent palettes across runs and across languages. The JavaScript snippet replicates the same algorithm, ensuring that identical seeds produce identical palettes in the browser.
Julia’s Colors.jl library provides rich tools for creating colour maps. For example, sequential_palette in Colors.jl can build a sequential palette given a hue and several parameters (Colormaps and Colorscales · Colors - julia), and you can use the ColorScheme constructor to create custom colour schemes from an array of colours (I have custom color palettes and I want to make a nice ...). Gay.jl in this prototype wraps a simple deterministic palette generator rather than using these built‑in schemes. A seed string is hashed into a 32‑bit integer; this integer is used to seed a simple PRNG (Mulberry32) that outputs pseudo‑random numbers in [0,1). These numbers are scaled to RGB channels (0–255) to build the palette. Because the algorithm is purely arithmetic, it can be implemented in any language.
- palettes.json – A sample JSON file mapping five seed names to their generated palettes. Each palette is an array of five six‑digit hexadecimal colour strings.
- generate_palette.jl – A Julia script that reads seeds from
palettes.json, usesGay.jlto compute a palette for each seed, and prints them to STDOUT. - generate_palette.js – A JavaScript snippet that exports a
generatePalette(seed, n)function replicating the same algorithm used in the Julia script. - README.md – This document.
-
In Julia, install the required package (Gay.jl wraps the algorithm and has no external dependencies):
using Pkg Pkg.add(url="https://github.com/your-user/Gay.jl") # hypothetical package for this prototypeThen run
generate_palette.jl:julia generate_palette.jlThis reads
palettes.jsonand prints the palette for each seed. -
In JavaScript, import
generatePaletteand call it with a seed string:import { generatePalette } from './generate_palette.js'; const palette = generatePalette('rainbow', 5); console.log(palette); // ["#e6dbc2", "#451d97", ...]
Because both implementations derive their random sequences from the same hashing and PRNG steps, they produce identical palettes for the same seed.