fourdjs/colours.js
2026-02-11 11:56:48 +11:00

61 lines
1.5 KiB
JavaScript

import ColorScheme from 'color-scheme';
import Color from 'color';
export const get_colours = (basis, n) => {
const colours = get_colours_spectrum(basis, n);
return colours;
}
const get_colours_tetrade = (basis, n) => {
// this always returns what the scheme has so it ignores n
const basis_c = Color(basis);
const hslb = basis_c.hsl();
const hue = hslb['color'][0];
const saturation = hslb['color'][1];
const luminance = hslb['color'][2];
const scheme = new ColorScheme;
scheme.from_hue(hue).scheme("tetrade").distance(0.75);
const colours = scheme.colors();
//colours.reverse();
const hsl = colours.map((c) => Color("#" + c).hsl());
const resaturated = hsl.map((hslc) => hslc.saturationl(saturation).rgbNumber());
resaturated.unshift(basis);
return resaturated;
}
const get_colours_spectrum = (basis, n) => {
// this returns n colours evenly spaced by hue
const basis_c = Color(basis);
const hslb = basis_c.hsl();
const hue = hslb['color'][0];
const saturation = hslb['color'][1];
const luminance = hslb['color'][2];
const hsl = [];
for( let i = 0; i < n; i++ ) {
const h = (hue + i * 360 / n) % 360;
hsl.push(Color.hsl(h, saturation, luminance));
}
return hsl.map((hslc) => hslc.rgbNumber());
}
// basic colours where 0 = blue
// 1 - dark blue
// 2 - white
// 3 - light cyan
// 4 - light orange
// 5 - dark orange
export const get_plain_colours = (basis) => {
return [
basis,
0xffffff,
0x00ff00,
0xff0000,
0x0000ff,
0xff9900,
0x000000,
]
}