UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

46 lines (45 loc) 2.97 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _SplitComplementaryThemeFactory_instances, _SplitComplementaryThemeFactory_validateArgument, _SplitComplementaryThemeFactory_calculateHueOfMainColor; import { ArgumentLimits } from '../enums/ArgumentLimits.js'; import { ColorThemeData } from './ColorThemeData.js'; import { ColorThemes } from '../enums/ColorThemes.js'; import { MultiHueColorThemeFactory } from './MultiHueColorThemeFactory.js'; import { ValidationObject } from './ValidationObject.js'; export class SplitComplementaryThemeFactory extends MultiHueColorThemeFactory { constructor() { super(ArgumentLimits.SplitComplementaryMin); _SplitComplementaryThemeFactory_instances.add(this); this.setCalculateHueFunction(__classPrivateFieldGet(this, _SplitComplementaryThemeFactory_instances, "m", _SplitComplementaryThemeFactory_calculateHueOfMainColor)); } /** * Generates an split complementary color theme. * * @param numberOfColors - The number of colors to include ranging from 3 to 5. * @returns An object containing data about the generated color theme. * @throws Error if the arguments does not pass the validation. */ getColorTheme(numberOfColors) { __classPrivateFieldGet(this, _SplitComplementaryThemeFactory_instances, "m", _SplitComplementaryThemeFactory_validateArgument).call(this, numberOfColors); const colors = this.getColors(numberOfColors); const data = new ColorThemeData(ColorThemes.SplitComplementary, colors); return data; } } _SplitComplementaryThemeFactory_instances = new WeakSet(), _SplitComplementaryThemeFactory_validateArgument = function _SplitComplementaryThemeFactory_validateArgument(numberOfColors) { const validationValues = new ValidationObject(ArgumentLimits.SplitComplementaryMax, ArgumentLimits.SplitComplementaryMin, numberOfColors); this.validator.validateNumberArgumentWithMaxAndMin(validationValues); }, _SplitComplementaryThemeFactory_calculateHueOfMainColor = function _SplitComplementaryThemeFactory_calculateHueOfMainColor(hueIncrementFactor) { const numberOfHues = 360; // Equation made with the help of chatGPT, see @link in comment. const hueIncrement = 30 * (-(3 / 2) * (hueIncrementFactor ** 2) + (13 / 2) * hueIncrementFactor); // ** is "power of" if (((this.hue + hueIncrement) % numberOfHues) === 0) { return this.hue + hueIncrement; } else { return (this.hue + hueIncrement) % numberOfHues; } };