dynamic
generative
color
Symphonies of Sine and Fibonacci – A Visual Code Journey

Symphonies of Sine and Fibonacci – A Visual Code Journey

written by reyrove

07 Oct 2024100 EDITIONS
1 TEZ

Setting the Stage: Defining the Canvas

const e = Math.min(innerWidth, innerHeight);
const canvas = {};
canvas.w = e;
canvas.h = e;

Features and Fibonacci: Crafting Our Palette

var features = {};
const fibonacciSequence = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765];

Choosing Colors: A Palette in Motion

const Backgroundcolors = ['#34282C', '#3B3131', '#0C090A', ...];
const BackgroundIndex = Math.floor($fx.rand() * Backgroundcolors.length);
features.backgroundColour = Backgroundcolors[BackgroundIndex];

Lines with a Rhythm: The Line Widths and Colors

features.lineWidth = [];
features.lineColor = [];
numberOfSineFunctions = Math.floor($fx.rand() * 25 + 1);

Color Harmony: The Ever-Changing Palette

let hue = (baseHue + $fx.rand() * 60 - 30) % 360;
features.lineColor.push([hue, saturation, lightness]);

Waves and Motion: The Core of the Visuals

let sumOfSines = 0;
for (let i = 0; i < numberOfSineFunctions; i++) {
  sumOfSines += Math.sin(frequencies[i] * lineX * 2 * Math.PI / e + time);
}

Direction and Translation: Making It Move

const motionStep = 0.5;
const randomDirection = directions[Math.floor($fx.rand() * directions.length)];
translate(randomDirection.x, randomDirection.y);

Lines that Evolve: A Dance of Widths and Colors

features.lineWidth[j] += e / 200 * ($fx.rand() < 0.5 ? -1 : 1);

Color Shift: Harmonious and Smooth

function harmoniousColorChange(color) {
  const changeAmount = 5;
  color[2] += changeAmount * ($fx.rand() < 0.5 ? -1 : 1);
  return color;
}

Bringing it All Together

time += 0.05; // Control speed of animation
$fx.preview(); // Render the preview

Every time you run this code, you create something new—a unique symphony of color and sine waves, influenced by the elegance of Fibonacci. It's a digital dance that mirrors the unpredictable yet harmonious nature of life itself.

For full code click here and play with this code, tweak the settings, adjust the colors, and watch as your canvas comes to life with each keystroke. Share your creations with me on X, Instagram, and Facebook, and let’s revel in this generative wonder together.

Come join us in our digital home, where creativity and code weave the fabric of our existence. You are always welcome as our guest, to learn, to create, and to enjoy the beauty of the world we build.

With all our love,

_Frostbond Coders 🌸💻

stay ahead with our newsletter

receive news on exclusive drops, releases, product updates, and more

feedback