Skip to content

Commit

Permalink
Added default params for pairedScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
prjctimg committed Nov 23, 2023
1 parent dad288f commit bc00a9f
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/palettes/paired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { toHex } from '../converters/toHex.ts';
import { setChannel } from '../getters_and_setters/set.ts';
import { Color, EarthtoneOptions, Tone } from '../paramTypes.ts';
import { Color, EarthtoneOptions } from '../paramTypes.ts';
import {
interpolate,
samples,
Expand All @@ -29,37 +29,38 @@ import {
*
* import { pairedScheme } from 'huetiful-js'
console.log(pairedScheme("green", 6, 5, "dark"))
console.log(pairedScheme("green",{hueStep:6,iterations:4,tone:'dark'}))
// [ '#008116ff', '#006945ff', '#184b4eff', '#007606ff' ]
*/
const pairedScheme = (
color: Color,
hueStep: number,
iterations: number,
via: Tone,
options: EarthtoneOptions
): Color[] => {
const pairedScheme = (color: Color, options: EarthtoneOptions): Color[] => {
// eslint-disable-next-line prefer-const
options = {
easingFunc: defaultArg(easingSmootherstep),
hueInterpolator: defaultArg(interpolatorSplineBasisClosed),
chromaInterpolator: defaultArg(interpolatorSplineNatural),
hueFixup: defaultArg(fixupHueShorter),
lightnessInterpolator: defaultArg(interpolatorSplineMonotone)
};

options['iterations'] = options['iterations'] || 4;

options['hueStep'] = options['hueStep'] || 5;
options['via'] = options['via'] || 'dark';
options['easingFunc'] = options['easingFunc'] || easingSmootherstep;
options['lightnessInterpolator'] =
options['lightnessInterpolator'] || interpolatorSplineMonotone;
options['chromaInterpolator'] || interpolatorSplineNatural;
options['hueInterpolator'] || interpolatorSplineBasisClosed;
options['hueFixup'] = options['hueFixup'] || fixupHueShorter;
const toLch = useMode(modeLch);
color = toLch(toHex(color));

// get the hue of the passed in color and add it to the step which will result in the final color to pair with
const derivedHue = setChannel('lch.h')(color, color['h'] + hueStep || 12);
const derivedHue = setChannel('lch.h')(
color,
color['h'] + options['hueStep']
);

// Set the tones to color objects with hardcoded hue values and lightness channels clamped at extremes
const tones = {
dark: '#263238',
light: { l: 100, c: 0, h: 0, mode: 'lch' }
light: { l: 100, c: 0.0001, h: 0, mode: 'lch' }
};

const scale = interpolate([color, tones[via || 'dark'], derivedHue], 'lch', {
const scale = interpolate([color, tones[options['via']], derivedHue], 'lch', {
h: {
fixup: options['hueFixup'],
use: options['hueInterpolator']
Expand All @@ -72,20 +73,21 @@ const pairedScheme = (
}
});

const { abs, round } = Math;

// Declare the num of iterations in samples() which will be used as the t value
// Since the interpolation returns half duplicate values we double the sample value
// Guard the num param against negative values and floats
const smp = samples((round(abs(iterations)) || 4) * 2);

//The array to capture the different iterations
const results: Color[] = smp.map((t) =>
formatHex8(scale(easingSmootherstep(t)))
);
if (options['iterations'] <= 1) {
return toHex(scale(0.5));
} else {
// Declare the num of iterations in samples() which will be used as the t value
// Since the interpolation returns half duplicate values we double the sample value
// Guard the num param against negative values and floats
const smp = samples(options['iterations'] * 2);

// Return a slice of the array from the start to the half length of the array
return results.slice(0, results.length / 2);
//The array to capture the different iterations
const results: Color[] = smp.map((t) =>
toHex(scale(options['easingFunc'](t)))
);
// Return a slice of the array from the start to the half length of the array
return results.slice(0, results.length / 2);
}
};

export { pairedScheme };

0 comments on commit bc00a9f

Please sign in to comment.