209209 }
210210 } ;
211211 }
212- // Generate random coefficients for Random Mix theme
212+ // Generate random coefficients for Random Mix theme
213213 generateRandomCoefficients ( ) {
214- const randomCoef = ( ) => ( Math . random ( ) * 2 - 1 ) ; // -1 to 1
214+ const randRange = ( min , max ) => Math . random ( ) * ( max - min ) + min ;
215215 const randomArchParam = ( min , max ) => Math . random ( ) * ( max - min ) + min ;
216-
217- const generateCoefficients = ( ) => ( {
218- primary : { r : randomCoef ( ) , g : randomCoef ( ) , b : randomCoef ( ) } ,
219- secondary : { r : randomCoef ( ) , g : randomCoef ( ) , b : randomCoef ( ) } ,
220- tertiary : { r : randomCoef ( ) , g : randomCoef ( ) , b : randomCoef ( ) } ,
221- error : { r : randomCoef ( ) * 0.5 + 0.5 , g : randomCoef ( ) * 0.5 - 0.5 , b : randomCoef ( ) * 0.5 - 0.5 } , // Tend towards red
222- warning : { r : randomCoef ( ) * 0.5 + 0.5 , g : randomCoef ( ) * 0.5 , b : randomCoef ( ) * 0.5 - 0.5 } , // Tend towards orange
223- info : { r : randomCoef ( ) * 0.5 - 0.5 , g : randomCoef ( ) * 0.5 , b : randomCoef ( ) * 0.5 + 0.5 } , // Tend towards blue
224- bgPrimary : { r : randomCoef ( ) * 0.3 , g : randomCoef ( ) * 0.3 , b : randomCoef ( ) * 0.3 } , // Keep backgrounds subtle
225- bgSecondary : { r : randomCoef ( ) * 0.2 , g : randomCoef ( ) * 0.2 , b : randomCoef ( ) * 0.2 } ,
226- bgAccent : { r : randomCoef ( ) * 0.25 , g : randomCoef ( ) * 0.25 , b : randomCoef ( ) * 0.25 } ,
227- // Architecture parameters
228- glowIntensity : randomArchParam ( 0.2 , 2.0 ) ,
229- animationSpeed : randomArchParam ( 0.5 , 2.0 ) ,
230- glitchIntensity : Math . floor ( randomArchParam ( 0 , 4 ) ) ,
231- borderWidth : Math . floor ( randomArchParam ( 1 , 3 ) ) ,
232- borderRadius : Math . floor ( randomArchParam ( 0 , 10 ) ) ,
233- containerWidth : Math . floor ( randomArchParam ( 750 , 900 ) ) ,
234- spacingUnit : Math . floor ( randomArchParam ( 16 , 26 ) )
235- } ) ;
216+
217+ const generateCoefficients = ( ) => {
218+ const isDark = Math . random ( ) > 0.5 ;
219+ let bgBase , textBase ;
220+
221+ if ( isDark ) {
222+ // Dark background: coefs -1.9 to -1.5 (Base 240 -> ~0 to ~50)
223+ bgBase = ( ) => randRange ( - 1.9 , - 1.5 ) ;
224+ // Light text: coefs 0.5 to 1.0 (Base 128 -> ~190 to ~255)
225+ textBase = ( ) => randRange ( 0.5 , 1.0 ) ;
226+ } else {
227+ // Light background: coefs -0.2 to 0.1 (Base 240 -> ~215 to ~255)
228+ bgBase = ( ) => randRange ( - 0.2 , 0.1 ) ;
229+ // Dark text: coefs -1.0 to -0.5 (Base 128 -> ~0 to ~65)
230+ textBase = ( ) => randRange ( - 1.0 , - 0.5 ) ;
231+ }
232+
233+ return {
234+ primary : { r : textBase ( ) , g : textBase ( ) , b : textBase ( ) } ,
235+ secondary : { r : textBase ( ) , g : textBase ( ) , b : textBase ( ) } ,
236+ tertiary : { r : textBase ( ) , g : textBase ( ) , b : textBase ( ) } ,
237+ error : { r : randRange ( 0.5 , 1.0 ) , g : randRange ( - 1.0 , - 0.5 ) , b : randRange ( - 1.0 , - 0.5 ) } ,
238+ warning : { r : randRange ( 0.5 , 1.0 ) , g : randRange ( 0.0 , 0.5 ) , b : randRange ( - 1.0 , - 0.5 ) } ,
239+ info : { r : randRange ( - 1.0 , - 0.5 ) , g : randRange ( 0.0 , 0.5 ) , b : randRange ( 0.5 , 1.0 ) } ,
240+ bgPrimary : { r : bgBase ( ) , g : bgBase ( ) , b : bgBase ( ) } ,
241+ bgSecondary : { r : bgBase ( ) + ( isDark ? 0.1 : - 0.1 ) , g : bgBase ( ) + ( isDark ? 0.1 : - 0.1 ) , b : bgBase ( ) + ( isDark ? 0.1 : - 0.1 ) } ,
242+ bgAccent : { r : bgBase ( ) + ( isDark ? 0.2 : - 0.2 ) , g : bgBase ( ) + ( isDark ? 0.2 : - 0.2 ) , b : bgBase ( ) + ( isDark ? 0.2 : - 0.2 ) } ,
243+ // Architecture parameters
244+ glowIntensity : randomArchParam ( 0.2 , 2.0 ) ,
245+ animationSpeed : randomArchParam ( 0.5 , 2.0 ) ,
246+ glitchIntensity : Math . floor ( randomArchParam ( 0 , 4 ) ) ,
247+ borderWidth : Math . floor ( randomArchParam ( 1 , 3 ) ) ,
248+ borderRadius : Math . floor ( randomArchParam ( 0 , 10 ) ) ,
249+ containerWidth : Math . floor ( randomArchParam ( 750 , 900 ) ) ,
250+ spacingUnit : Math . floor ( randomArchParam ( 16 , 26 ) )
251+ } ;
252+ } ;
236253
237254 // Generate coefficients and check contrast
238255 let attempts = 0 ;
304321 const primarySecondaryContrast = getContrastRatio ( colors . primary , colors . bgSecondary ) ;
305322
306323 // WCAG AA standard requires 4.5:1 for normal text, 3:1 for large text
307- // We'll use 3 .5:1 as a reasonable middle ground for our cyberpunk theme
308- const minContrast = 3 .5;
324+ // We'll use 4 .5:1 to ensure readability
325+ const minContrast = 4 .5;
309326
310327 return (
311328 primaryBgContrast >= minContrast &&
317334
318335 // Generate safe random coefficients as fallback
319336 getSafeRandomCoefficients ( ) {
320- const randomCoef = ( ) => ( Math . random ( ) * 2 - 1 ) ;
337+ const randRange = ( min , max ) => Math . random ( ) * ( max - min ) + min ;
321338 const randomArchParam = ( min , max ) => Math . random ( ) * ( max - min ) + min ;
322339
323- // Use more conservative ranges to ensure contrast
324340 return {
325- primary : { r : randomCoef ( ) * 0.8 , g : randomCoef ( ) * 0.8 , b : randomCoef ( ) * 0.8 + 0.2 } , // Bias towards lighter
326- secondary : { r : randomCoef ( ) * 0.8 + 0.2 , g : randomCoef ( ) * 0.8 , b : randomCoef ( ) * 0.8 } , // Different bias
327- tertiary : { r : randomCoef ( ) * 0.6 + 0.4 , g : randomCoef ( ) * 0.6 + 0.4 , b : randomCoef ( ) * 0.6 + 0.4 } , // Ensure lightness
328- error : { r : 0.8 , g : - 0.6 , b : - 0.6 } , // Safe red
329- warning : { r : 0.8 , g : 0.2 , b : - 0.8 } , // Safe orange
330- info : { r : - 0.6 , g : - 0.2 , b : 0.8 } , // Safe blue
331- bgPrimary : { r : randomCoef ( ) * 0.4 - 0.6 , g : randomCoef ( ) * 0.4 - 0.6 , b : randomCoef ( ) * 0.4 - 0.6 } , // Ensure darkness
332- bgSecondary : { r : randomCoef ( ) * 0.3 - 0.5 , g : randomCoef ( ) * 0.3 - 0.5 , b : randomCoef ( ) * 0.3 - 0.5 } , // Darker
333- bgAccent : { r : randomCoef ( ) * 0.35 - 0.45 , g : randomCoef ( ) * 0.35 - 0.45 , b : randomCoef ( ) * 0.35 - 0.45 } , // Medium dark
334341 // Architecture parameters
335342 glowIntensity : randomArchParam ( 0.2 , 2.0 ) ,
336343 animationSpeed : randomArchParam ( 0.5 , 2.0 ) ,
474481 } ) ;
475482 }
476483 } ) ;
477- </ script >
484+ </ script >
0 commit comments