Skip to content

Commit

Permalink
use random lightness for random color
Browse files Browse the repository at this point in the history
  • Loading branch information
vcanales authored and Vicente Canales committed May 26, 2022
1 parent 13f90a6 commit cc5ed9f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/edit-site/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ export function useRandomizer( name ) {
);

function randomizeColors() {
/*
Randomizing lightness — changing the limits of the color range — allows for a wider range of
color combinations.
*/
/* eslint-disable no-restricted-syntax */
const minLightness = Math.random() * ( 0.3 - 0.01 ) + 0.1; // Generate a random number between 0.1 and 0.3
const maxLightneess = Math.random() * ( 0.99 - 0.8 ) + 0.8; // Generate a random numbet between 0.8 and 0.99
/* eslint-enable no-restricted-syntax */

/*
Generates a color scale based on hue scale rotations in the Cubehelix color scheme,
from lightest to darkest.
Expand All @@ -326,7 +335,7 @@ export function useRandomizer( name ) {
/* eslint-disable-next-line no-restricted-syntax */
.start( Math.floor( Math.random() * 360 ) ) // Generate a random start point for the hue scale.
.rotations( 0.75 )
.lightness( [ 0.3, 0.8 ] ) // Defines minimum and maximum lightness of first and last colors,
.lightness( [ minLightness, maxLightneess ] ) // Defines minimum and maximum lightness of first and last colors,
// respectively. By default, the ends of scales are black and white.
.scale() // convert to chroma.scale
.correctLightness()
Expand Down

0 comments on commit cc5ed9f

Please sign in to comment.