art
generative
fxhash
Crafting Digital Masterpieces with CyPollock: A Dance of Code and Colors

Crafting Digital Masterpieces with CyPollock: A Dance of Code and Colors

written by reyrove

06 Oct 2024100 EDITIONS
1 TEZ

The Setup: Laying the Foundation

The first part of the code initializes the environment and sets up the essential parameters, such as colors and the number of tree-like branches, which are splattered across the canvas.

const ratio = 1 / 1;
const prefix = 'cyPollock';
const features = {}; 
let resizeTmr = null; 
let thumbnailTaken = false;

The Color Scheme: Embracing the Abstract

Next, we dive into the random selection of background and branch colors that will set the tone of the artwork.

const backgroundColours = ['#2F0909', '#2B1B17', '#040720', '#151B54', ...];
const branch1colors = ['#DADBDD', '#EEEEEE', '#98AFC7', '#1589FF', ...];
const backgroundIndex = Math.floor($fx.rand() * backgroundColours.length);
features.backgroundColour = backgroundColours[backgroundIndex];

The Structure: Building Trees with Recursive Algorithms

Now, the magic begins with the recursive drawTree function, which mimics the fractal-like growth of branches.

function drawTree(ctx, w, h, color, x , y, depth) {
    ctx.strokeStyle = color;
    ctx.lineWidth = $fx.rand() * w / 100 + w / 200;
  
    if (depth < 13) {
        ctx.beginPath();
        ctx.moveTo(x, y);
        ctx.lineTo(x, y - h / 50);
        ctx.stroke();

        const newX = x;
        const newY = y - h / 10;
        angle = Random(-Math.Pi, Math.Pi);
        ctx.save();
        ctx.translate(newX, newY);
        ctx.rotate(angle);

        if ($fx.rand() < 0.3) {
            ctx.rotate(0.6);
            drawTree(ctx, w, h, color, 0, 0, depth + 1);
        } else {
            drawTree(ctx, w, h, color, 0, 0, depth);
        }
        ctx.restore();
    }
}

Painting the Canvas: Drawing the Trees

The drawCanvas function is the heart of our visual creation, controlling how each tree is drawn across the canvas with varying sizes and positions.

const drawCanvas = async () => {
    window.cancelAnimationFrame(nextFrame);
    const canvas = document.getElementById('target');
    const ctx = canvas.getContext('2d');
    const w = canvas.width;
    const h = canvas.height;

    ctx.fillStyle = features.backgroundColour;
    ctx.fillRect(0, 0, w, h);

    for (let i = 0; i < features.numofBranches; i++) {
        const color1 = features.Branchcolor[i];
        const W1 = $fx.rand() * w;
        const H1 = $fx.rand() * h;
        const x = $fx.rand() * w / 2 + w / 2;
        const y = $fx.rand() * h / 2 + h / 2;
        const depth = 0;

        drawTree(ctx, W1, H1, color1, x, y, depth);
    }
};

User Interaction: Making It Dynamic

The code responds to events like resizing or pressing certain keys to trigger canvas downloads or adjustments in the layout.

document.addEventListener('keypress', async (e) => {
    if (e.key === 's' || 'S') autoDownloadCanvas();
});

Animation Ready: Keeping It Fluid

For those who wish to animate their creations, the nextFrame logic keeps the canvas updated dynamically:

if (animated) {
    nextFrame = window.requestAnimationFrame(drawCanvas);
}

This ensures the visuals can continuously evolve, creating an even more mesmerizing experience.

Bringing It All Together

CyPollock blends randomness with structure, creating abstract generative art that captures the unpredictability of nature in a digital form. By utilizing recursive algorithms, random color palettes, and interactive features, this code crafts unique, ever-changing visuals reminiscent of Pollock’s iconic works.

To try this yourself, simply click here to see the full code in action and craft your own digital masterpiece. Let the canvas come alive with color and creativity! 🎨

With love, chaos, and endless inspiration, ✨🌿

_Frostbond Coders

stay ahead with our newsletter

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

feedback