Skip to content

Commit

Permalink
make harmonies work with negative hues
Browse files Browse the repository at this point in the history
  • Loading branch information
meodai committed Dec 31, 2023
1 parent 1527b64 commit 3aaa5ff
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 83 deletions.
46 changes: 30 additions & 16 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,39 @@ function shuffleArray(array, rndFn = Math.random) {
return array;
}
var colorHarmonies = {
complementary: (h) => [h, (h + 180) % 360],
splitComplementary: (h) => [h, (h + 150) % 360, (h + 210) % 360],
triadic: (h) => [h, (h + 120) % 360, (h + 240) % 360],
tetradic: (h) => [h, (h + 90) % 360, (h + 180) % 360, (h + 270) % 360],
monochromatic: (h) => [h],
complementary: (h) => [(h + 360) % 360, (h + 540) % 360],
splitComplementary: (h) => [
(h + 360) % 360,
(h + 510) % 360,
(h + 570) % 360
],
triadic: (h) => [(h + 360) % 360, (h + 480) % 360, (h + 600) % 360],
tetradic: (h) => [
(h + 360) % 360,
(h + 450) % 360,
(h + 540) % 360,
(h + 630) % 360
],
monochromatic: (h) => [(h + 360) % 360],
doubleComplementary: (h) => [
h,
(h + 180) % 360,
(h + 30) % 360,
(h + 210) % 360
(h + 360) % 360,
(h + 540) % 360,
(h + 390) % 360,
(h + 630) % 360
],
compound: (h) => [
(h + 360) % 360,
(h + 540) % 360,
(h + 420) % 360,
(h + 600) % 360
],
compound: (h) => [h, (h + 180) % 360, (h + 60) % 360, (h + 240) % 360],
analogous: (h) => [
h,
(h + 30) % 360,
(h + 60) % 360,
(h + 90) % 360,
(h + 120) % 360,
(h + 150) % 360
(h + 360) % 360,
(h + 390) % 360,
(h + 420) % 360,
(h + 450) % 360,
(h + 480) % 360,
(h + 510) % 360
]
};
function uniqueRandomHues({
Expand Down
46 changes: 30 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,39 @@ var rampensau = (() => {
return array;
}
var colorHarmonies = {
complementary: (h) => [h, (h + 180) % 360],
splitComplementary: (h) => [h, (h + 150) % 360, (h + 210) % 360],
triadic: (h) => [h, (h + 120) % 360, (h + 240) % 360],
tetradic: (h) => [h, (h + 90) % 360, (h + 180) % 360, (h + 270) % 360],
monochromatic: (h) => [h],
complementary: (h) => [(h + 360) % 360, (h + 540) % 360],
splitComplementary: (h) => [
(h + 360) % 360,
(h + 510) % 360,
(h + 570) % 360
],
triadic: (h) => [(h + 360) % 360, (h + 480) % 360, (h + 600) % 360],
tetradic: (h) => [
(h + 360) % 360,
(h + 450) % 360,
(h + 540) % 360,
(h + 630) % 360
],
monochromatic: (h) => [(h + 360) % 360],
doubleComplementary: (h) => [
h,
(h + 180) % 360,
(h + 30) % 360,
(h + 210) % 360
(h + 360) % 360,
(h + 540) % 360,
(h + 390) % 360,
(h + 630) % 360
],
compound: (h) => [
(h + 360) % 360,
(h + 540) % 360,
(h + 420) % 360,
(h + 600) % 360
],
compound: (h) => [h, (h + 180) % 360, (h + 60) % 360, (h + 240) % 360],
analogous: (h) => [
h,
(h + 30) % 360,
(h + 60) % 360,
(h + 90) % 360,
(h + 120) % 360,
(h + 150) % 360
(h + 360) % 360,
(h + 390) % 360,
(h + 420) % 360,
(h + 450) % 360,
(h + 480) % 360,
(h + 510) % 360
]
};
function uniqueRandomHues({
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var x=Object.defineProperty;var T=e=>x(e,"__esModule",{value:!0});var f=(e,t)=>{T(e);for(var n in t)x(e,n,{get:t[n],enumerable:!0})};f(exports,{colorHarmonies:()=>M,colorToCSS:()=>H,generateColorRamp:()=>C,generateColorRampParams:()=>k,lerp:()=>y,scaleSpreadArray:()=>S,shuffleArray:()=>b,uniqueRandomHues:()=>A});function C({total:e=9,hStart:t=Math.random()*360,hStartCenter:n=.5,hEasing:m=o=>o,hCycles:s=1,sRange:r=[.4,.35],sEasing:a=o=>Math.pow(o,2),lRange:p=[Math.random()*.1,.9],lEasing:l=o=>Math.pow(o,1.5),hueList:u}={}){let o=p[1]-p[0],c=r[1]-r[0],i=u&&u.length>0?u.length:e;return Array.from({length:i},(w,g)=>{let d=g/(i-1),h=1/i;return[u?u[g]:(360+t+(1-m(d,h)-n)*(360*s))%360,r[0]+c*a(d,h),p[0]+o*l(d,h)]})}function b(e,t=Math.random){let n=e.length,m;for(;n!=0;)m=Math.floor(t()*n),n--,[e[n],e[m]]=[e[m],e[n]];return e}var M={complementary:e=>[e,(e+180)%360],splitComplementary:e=>[e,(e+150)%360,(e+210)%360],triadic:e=>[e,(e+120)%360,(e+240)%360],tetradic:e=>[e,(e+90)%360,(e+180)%360,(e+270)%360],monochromatic:e=>[e],doubleComplementary:e=>[e,(e+180)%360,(e+30)%360,(e+210)%360],compound:e=>[e,(e+180)%360,(e+60)%360,(e+240)%360],analogous:e=>[e,(e+30)%360,(e+60)%360,(e+90)%360,(e+120)%360,(e+150)%360]};function A({startHue:e=0,total:t=9,minHueDiffAngle:n=60,rndFn:m=Math.random}={}){n=Math.min(n,360/t);let s=e||m()*360,r=Array.from({length:Math.round(360/n)},(p,l)=>(s+l*n)%360),a=b(r,m);return a.length>t&&(a=a.slice(0,t)),a}var F={oklch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],lch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],hsl:e=>[e[0],e[1]*100+"%",e[2]*100+"%"]},H=(e,t="oklch")=>`${t}(${F[t](e).join(" ")})`,y=(e,t,n)=>t+e*(n-t),S=(e,t,n=y)=>{if(e.length===0)throw new Error("Initial array must not be empty.");if(t<e.length)throw new Error("Target size must be greater than or equal to the initial array length.");let m=t-e.length,s=e.map(r=>[r]);for(let r=0;r<m;r++)s[r%(e.length-1)].push(null);for(let r=0;r<s.length-1;r++){let a=s[r],p=s[r+1],l=a[0],u=p[0];for(let o=1;o<a.length;o++){let c=o/a.length;a[o]=n(c,l,u)}}return s.flat()},k={total:{default:5,props:{min:4,max:50,step:1}},hStart:{default:0,props:{min:0,max:360,step:.1}},hCycles:{default:1,props:{min:-2,max:2,step:.001}},hStartCenter:{default:.5,props:{min:0,max:1,step:.001}},minLight:{default:Math.random()*.2,props:{min:0,max:1,step:.001}},maxLight:{default:.89+Math.random()*.11,props:{min:0,max:1,step:.001}},minSaturation:{default:Math.random()<.5?.4:.8+Math.random()*.2,props:{min:0,max:1,step:.001}},maxSaturation:{default:Math.random()<.5?.35:.9+Math.random()*.1,props:{min:0,max:1,step:.001}}};
var x=Object.defineProperty;var T=e=>x(e,"__esModule",{value:!0});var f=(e,t)=>{T(e);for(var n in t)x(e,n,{get:t[n],enumerable:!0})};f(exports,{colorHarmonies:()=>M,colorToCSS:()=>H,generateColorRamp:()=>C,generateColorRampParams:()=>k,lerp:()=>y,scaleSpreadArray:()=>S,shuffleArray:()=>b,uniqueRandomHues:()=>A});function C({total:e=9,hStart:t=Math.random()*360,hStartCenter:n=.5,hEasing:m=o=>o,hCycles:s=1,sRange:r=[.4,.35],sEasing:a=o=>Math.pow(o,2),lRange:p=[Math.random()*.1,.9],lEasing:l=o=>Math.pow(o,1.5),hueList:u}={}){let o=p[1]-p[0],c=r[1]-r[0],i=u&&u.length>0?u.length:e;return Array.from({length:i},(w,g)=>{let d=g/(i-1),h=1/i;return[u?u[g]:(360+t+(1-m(d,h)-n)*(360*s))%360,r[0]+c*a(d,h),p[0]+o*l(d,h)]})}function b(e,t=Math.random){let n=e.length,m;for(;n!=0;)m=Math.floor(t()*n),n--,[e[n],e[m]]=[e[m],e[n]];return e}var M={complementary:e=>[(e+360)%360,(e+540)%360],splitComplementary:e=>[(e+360)%360,(e+510)%360,(e+570)%360],triadic:e=>[(e+360)%360,(e+480)%360,(e+600)%360],tetradic:e=>[(e+360)%360,(e+450)%360,(e+540)%360,(e+630)%360],monochromatic:e=>[(e+360)%360],doubleComplementary:e=>[(e+360)%360,(e+540)%360,(e+390)%360,(e+630)%360],compound:e=>[(e+360)%360,(e+540)%360,(e+420)%360,(e+600)%360],analogous:e=>[(e+360)%360,(e+390)%360,(e+420)%360,(e+450)%360,(e+480)%360,(e+510)%360]};function A({startHue:e=0,total:t=9,minHueDiffAngle:n=60,rndFn:m=Math.random}={}){n=Math.min(n,360/t);let s=e||m()*360,r=Array.from({length:Math.round(360/n)},(p,l)=>(s+l*n)%360),a=b(r,m);return a.length>t&&(a=a.slice(0,t)),a}var F={oklch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],lch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],hsl:e=>[e[0],e[1]*100+"%",e[2]*100+"%"]},H=(e,t="oklch")=>`${t}(${F[t](e).join(" ")})`,y=(e,t,n)=>t+e*(n-t),S=(e,t,n=y)=>{if(e.length===0)throw new Error("Initial array must not be empty.");if(t<e.length)throw new Error("Target size must be greater than or equal to the initial array length.");let m=t-e.length,s=e.map(r=>[r]);for(let r=0;r<m;r++)s[r%(e.length-1)].push(null);for(let r=0;r<s.length-1;r++){let a=s[r],p=s[r+1],l=a[0],u=p[0];for(let o=1;o<a.length;o++){let c=o/a.length;a[o]=n(c,l,u)}}return s.flat()},k={total:{default:5,props:{min:4,max:50,step:1}},hStart:{default:0,props:{min:0,max:360,step:.1}},hCycles:{default:1,props:{min:-2,max:2,step:.001}},hStartCenter:{default:.5,props:{min:0,max:1,step:.001}},minLight:{default:Math.random()*.2,props:{min:0,max:1,step:.001}},maxLight:{default:.89+Math.random()*.11,props:{min:0,max:1,step:.001}},minSaturation:{default:Math.random()<.5?.4:.8+Math.random()*.2,props:{min:0,max:1,step:.001}},maxSaturation:{default:Math.random()<.5?.35:.9+Math.random()*.1,props:{min:0,max:1,step:.001}}};
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.min.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
function f({total:e=9,hStart:t=Math.random()*360,hStartCenter:n=.5,hEasing:m=o=>o,hCycles:s=1,sRange:r=[.4,.35],sEasing:a=o=>Math.pow(o,2),lRange:p=[Math.random()*.1,.9],lEasing:l=o=>Math.pow(o,1.5),hueList:u}={}){let o=p[1]-p[0],c=r[1]-r[0],i=u&&u.length>0?u.length:e;return Array.from({length:i},(T,g)=>{let d=g/(i-1),h=1/i;return[u?u[g]:(360+t+(1-m(d,h)-n)*(360*s))%360,r[0]+c*a(d,h),p[0]+o*l(d,h)]})}function x(e,t=Math.random){let n=e.length,m;for(;n!=0;)m=Math.floor(t()*n),n--,[e[n],e[m]]=[e[m],e[n]];return e}var C={complementary:e=>[e,(e+180)%360],splitComplementary:e=>[e,(e+150)%360,(e+210)%360],triadic:e=>[e,(e+120)%360,(e+240)%360],tetradic:e=>[e,(e+90)%360,(e+180)%360,(e+270)%360],monochromatic:e=>[e],doubleComplementary:e=>[e,(e+180)%360,(e+30)%360,(e+210)%360],compound:e=>[e,(e+180)%360,(e+60)%360,(e+240)%360],analogous:e=>[e,(e+30)%360,(e+60)%360,(e+90)%360,(e+120)%360,(e+150)%360]};function M({startHue:e=0,total:t=9,minHueDiffAngle:n=60,rndFn:m=Math.random}={}){n=Math.min(n,360/t);let s=e||m()*360,r=Array.from({length:Math.round(360/n)},(p,l)=>(s+l*n)%360),a=x(r,m);return a.length>t&&(a=a.slice(0,t)),a}var b={oklch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],lch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],hsl:e=>[e[0],e[1]*100+"%",e[2]*100+"%"]},A=(e,t="oklch")=>`${t}(${b[t](e).join(" ")})`,y=(e,t,n)=>t+e*(n-t),F=(e,t,n=y)=>{if(e.length===0)throw new Error("Initial array must not be empty.");if(t<e.length)throw new Error("Target size must be greater than or equal to the initial array length.");let m=t-e.length,s=e.map(r=>[r]);for(let r=0;r<m;r++)s[r%(e.length-1)].push(null);for(let r=0;r<s.length-1;r++){let a=s[r],p=s[r+1],l=a[0],u=p[0];for(let o=1;o<a.length;o++){let c=o/a.length;a[o]=n(c,l,u)}}return s.flat()},H={total:{default:5,props:{min:4,max:50,step:1}},hStart:{default:0,props:{min:0,max:360,step:.1}},hCycles:{default:1,props:{min:-2,max:2,step:.001}},hStartCenter:{default:.5,props:{min:0,max:1,step:.001}},minLight:{default:Math.random()*.2,props:{min:0,max:1,step:.001}},maxLight:{default:.89+Math.random()*.11,props:{min:0,max:1,step:.001}},minSaturation:{default:Math.random()<.5?.4:.8+Math.random()*.2,props:{min:0,max:1,step:.001}},maxSaturation:{default:Math.random()<.5?.35:.9+Math.random()*.1,props:{min:0,max:1,step:.001}}};export{C as colorHarmonies,A as colorToCSS,f as generateColorRamp,H as generateColorRampParams,y as lerp,F as scaleSpreadArray,x as shuffleArray,M as uniqueRandomHues};
function f({total:e=9,hStart:t=Math.random()*360,hStartCenter:n=.5,hEasing:m=o=>o,hCycles:s=1,sRange:r=[.4,.35],sEasing:a=o=>Math.pow(o,2),lRange:p=[Math.random()*.1,.9],lEasing:l=o=>Math.pow(o,1.5),hueList:u}={}){let o=p[1]-p[0],c=r[1]-r[0],i=u&&u.length>0?u.length:e;return Array.from({length:i},(T,g)=>{let d=g/(i-1),h=1/i;return[u?u[g]:(360+t+(1-m(d,h)-n)*(360*s))%360,r[0]+c*a(d,h),p[0]+o*l(d,h)]})}function x(e,t=Math.random){let n=e.length,m;for(;n!=0;)m=Math.floor(t()*n),n--,[e[n],e[m]]=[e[m],e[n]];return e}var C={complementary:e=>[(e+360)%360,(e+540)%360],splitComplementary:e=>[(e+360)%360,(e+510)%360,(e+570)%360],triadic:e=>[(e+360)%360,(e+480)%360,(e+600)%360],tetradic:e=>[(e+360)%360,(e+450)%360,(e+540)%360,(e+630)%360],monochromatic:e=>[(e+360)%360],doubleComplementary:e=>[(e+360)%360,(e+540)%360,(e+390)%360,(e+630)%360],compound:e=>[(e+360)%360,(e+540)%360,(e+420)%360,(e+600)%360],analogous:e=>[(e+360)%360,(e+390)%360,(e+420)%360,(e+450)%360,(e+480)%360,(e+510)%360]};function M({startHue:e=0,total:t=9,minHueDiffAngle:n=60,rndFn:m=Math.random}={}){n=Math.min(n,360/t);let s=e||m()*360,r=Array.from({length:Math.round(360/n)},(p,l)=>(s+l*n)%360),a=x(r,m);return a.length>t&&(a=a.slice(0,t)),a}var b={oklch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],lch:e=>[e[2]*100+"%",e[1]*100+"%",e[0]],hsl:e=>[e[0],e[1]*100+"%",e[2]*100+"%"]},A=(e,t="oklch")=>`${t}(${b[t](e).join(" ")})`,y=(e,t,n)=>t+e*(n-t),F=(e,t,n=y)=>{if(e.length===0)throw new Error("Initial array must not be empty.");if(t<e.length)throw new Error("Target size must be greater than or equal to the initial array length.");let m=t-e.length,s=e.map(r=>[r]);for(let r=0;r<m;r++)s[r%(e.length-1)].push(null);for(let r=0;r<s.length-1;r++){let a=s[r],p=s[r+1],l=a[0],u=p[0];for(let o=1;o<a.length;o++){let c=o/a.length;a[o]=n(c,l,u)}}return s.flat()},H={total:{default:5,props:{min:4,max:50,step:1}},hStart:{default:0,props:{min:0,max:360,step:.1}},hCycles:{default:1,props:{min:-2,max:2,step:.001}},hStartCenter:{default:.5,props:{min:0,max:1,step:.001}},minLight:{default:Math.random()*.2,props:{min:0,max:1,step:.001}},maxLight:{default:.89+Math.random()*.11,props:{min:0,max:1,step:.001}},minSaturation:{default:Math.random()<.5?.4:.8+Math.random()*.2,props:{min:0,max:1,step:.001}},maxSaturation:{default:Math.random()<.5?.35:.9+Math.random()*.1,props:{min:0,max:1,step:.001}}};export{C as colorHarmonies,A as colorToCSS,f as generateColorRamp,H as generateColorRampParams,y as lerp,F as scaleSpreadArray,x as shuffleArray,M as uniqueRandomHues};
46 changes: 30 additions & 16 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,39 @@ function shuffleArray(array, rndFn = Math.random) {
return array;
}
var colorHarmonies = {
complementary: (h) => [h, (h + 180) % 360],
splitComplementary: (h) => [h, (h + 150) % 360, (h + 210) % 360],
triadic: (h) => [h, (h + 120) % 360, (h + 240) % 360],
tetradic: (h) => [h, (h + 90) % 360, (h + 180) % 360, (h + 270) % 360],
monochromatic: (h) => [h],
complementary: (h) => [(h + 360) % 360, (h + 540) % 360],
splitComplementary: (h) => [
(h + 360) % 360,
(h + 510) % 360,
(h + 570) % 360
],
triadic: (h) => [(h + 360) % 360, (h + 480) % 360, (h + 600) % 360],
tetradic: (h) => [
(h + 360) % 360,
(h + 450) % 360,
(h + 540) % 360,
(h + 630) % 360
],
monochromatic: (h) => [(h + 360) % 360],
doubleComplementary: (h) => [
h,
(h + 180) % 360,
(h + 30) % 360,
(h + 210) % 360
(h + 360) % 360,
(h + 540) % 360,
(h + 390) % 360,
(h + 630) % 360
],
compound: (h) => [
(h + 360) % 360,
(h + 540) % 360,
(h + 420) % 360,
(h + 600) % 360
],
compound: (h) => [h, (h + 180) % 360, (h + 60) % 360, (h + 240) % 360],
analogous: (h) => [
h,
(h + 30) % 360,
(h + 60) % 360,
(h + 90) % 360,
(h + 120) % 360,
(h + 150) % 360
(h + 360) % 360,
(h + 390) % 360,
(h + 420) % 360,
(h + 450) % 360,
(h + 480) % 360,
(h + 510) % 360
]
};
function uniqueRandomHues({
Expand Down
Loading

0 comments on commit 3aaa5ff

Please sign in to comment.