Pattern request. Two moving colors

@KanyonKris I’m so glad you were able to grok the Palette code! Thanks for showing another solution.

One thing I readily admit about the palette code is that it can slow things down a lot. I wanted to follow up on what I mentioned earlier about a faster, specific math approach to mapping a 0…1 hue into a yellowish range and a bluish range.

Input hue Output hue
0 yellow - something
0.25 yellow
0.499 yellow + something
0.5 blue - something
0.75 blue
0.999 blue + something

Centered around yellow and blue

Here's some math I worked out (really just a y = mx + b kind of thing) to map to ranges centered on opposite colors.

  // Manually "wrap" any input hues outside 0..1.
  h = h % 1 + (h < 0)

  // Map a 0..1 hue into 2 ranges, color1 ± width, and it's compliment
  color1 = 0.166 // Yellow (compliment is blue)
  width = 0.06
  h = color1 + width * (4 * (h % 0.5) - 1) + (h >= 0.5) / 2
  
  hsv(h, 1, v)

How to also fade-through-black

  // Manually "wrap" any input hues outside 0..1.
  h = h % 1 + (h < 0)
  
  // Fade through black for 2 output hues.
  // Multiply this by existing v values.
  fadeThroughBlack = triangle(2 * h)
  
  // Map a 0..1 hue into 2 ranges, color1 ± width, and it's compliment
  color1 = 0.166 // Yellow (compliment is blue)
  width = 0.06
  h = color1 + width * (4 * (h % 0.5) - 1) + (h >= 0.5) / 2
  
  hsv(h, 1, v * fadeThroughBlack)

Or fade through white

  // Manually "wrap" any input hues outside 0..1.
  h = h % 1 + (h < 0)
  
  // Fade through white for 2 output hues.
  // Multiply this by existing v values.
  fadeThroughWhite = triangle(2 * h)
  // Personal preference: less white
  fadeThroughWhite = sqrt(sqrt(fadeThroughWhite))
  
  // Map a 0..1 hue into 2 ranges, color1 ± width, and it's compliment
  color1 = 0.166 // Yellow (compliment is blue)
  width = 0.06
  h = color1 + width * (4 * (h % 0.5) - 1) + (h >= 0.5) / 2
  
  hsv(h, fadeThroughWhite, v)

Since KanyonKris mentioned the “rainbow melt” pattern, I tried it on that one.

Hopefully by choosing one of these approaches, you’ll be able to turn most example patterns into a 2-color one!

3 Likes