Skip to main content

Chromatic Illusion Weaponizer

An experimental visual effects tool powered by Google AI Studio that creates dynamic color transformations, optical illusions, and generative art using AI-driven algorithms.

Overview

Chromatic Illusion explores the intersection of artificial intelligence and visual perception, using Google’s Gemini AI to generate color palettes, create optical illusions, and manipulate images in ways that challenge how we perceive color and form.

AI Color Generation

Gemini AI generates harmonious and contrasting color schemes

Optical Illusions

Create perception-bending visual effects

Real-Time Processing

Live preview of transformations as you adjust parameters

Export Options

Save as images, CSS, or JSON color data

Features

AI-Powered Color Generation

Ask Gemini to generate color palettes based on:
  • Mood or emotion (“energetic”, “calm”, “mysterious”)
  • Natural phenomena (“sunset”, “ocean”, “forest”)
  • Cultural references (“cyberpunk”, “vaporwave”, “Art Deco”)
  • Abstract concepts (“velocity”, “transformation”, “depth”)
const prompt = `Generate a color palette for: ${userInput}`;
const result = await model.generateContent(prompt);
const colors = parseColorResponse(result.response.text());

Optical Illusion Effects

Built-in effects that trick perception:

Chromatic Aberration

Simulate lens distortion with color channel separation

Color Constancy

Same color appears different based on surrounding context

Motion Illusions

Static patterns that appear to move

Depth Perception

2D patterns that create 3D depth illusions

Afterimage Effects

Complementary color persistence

Simultaneous Contrast

Colors appear different when placed next to each other

Visual Transformations

1

Upload Image

Start with any image or use a blank canvas
2

Apply AI Effects

Let Gemini analyze and suggest transformations
3

Real-Time Preview

See changes instantly as you adjust parameters
4

Export

Download as PNG, or export color data as JSON/CSS

Technical Implementation

Google AI Studio Integration

Built on Google’s Gemini API:
import { GoogleGenerativeAI } from '@google/generative-ai';

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY!);
const model = genAI.getGenerativeModel({ model: 'gemini-pro' });

// Generate color palette
const generatePalette = async (description: string) => {
  const prompt = `
    Generate a harmonious color palette based on: "${description}"
    
    Return 5 colors in this JSON format:
    {
      "colors": [
        {"hex": "#RRGGBB", "name": "descriptive name"},
        ...
      ],
      "reasoning": "why this palette works"
    }
  `;
  
  const result = await model.generateContent(prompt);
  const text = result.response.text();
  return JSON.parse(extractJSON(text));
};

// Analyze color harmony
const analyzeHarmony = async (colors: string[]) => {
  const prompt = `
    Analyze this color palette: ${colors.join(', ')}
    
    Provide:
    1. Harmony type (complementary, analogous, etc.)
    2. Mood/emotion conveyed
    3. Suggested use cases
    4. Potential improvements
  `;
  
  const result = await model.generateContent(prompt);
  return result.response.text();
};

Color Math

Core color manipulation functions:
function rgbToHsl(r: number, g: number, b: number): [number, number, number] {
  r /= 255;
  g /= 255;
  b /= 255;
  
  const max = Math.max(r, g, b);
  const min = Math.min(r, g, b);
  const diff = max - min;
  
  let h = 0;
  let s = 0;
  const l = (max + min) / 2;
  
  if (diff !== 0) {
    s = l > 0.5 ? diff / (2 - max - min) : diff / (max + min);
    
    switch (max) {
      case r:
        h = ((g - b) / diff + (g < b ? 6 : 0)) / 6;
        break;
      case g:
        h = ((b - r) / diff + 2) / 6;
        break;
      case b:
        h = ((r - g) / diff + 4) / 6;
        break;
    }
  }
  
  return [h * 360, s * 100, l * 100];
}

Canvas Rendering

Effects rendered using HTML5 Canvas:
const applyChromaticAberration = (
  ctx: CanvasRenderingContext2D,
  imageData: ImageData,
  offset: number
) => {
  const { data, width, height } = imageData;
  const output = ctx.createImageData(width, height);
  
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      const i = (y * width + x) * 4;
      
      // Red channel: shift right
      const redX = Math.min(x + offset, width - 1);
      const redI = (y * width + redX) * 4;
      output.data[i] = data[redI];
      
      // Green channel: no shift
      output.data[i + 1] = data[i + 1];
      
      // Blue channel: shift left
      const blueX = Math.max(x - offset, 0);
      const blueI = (y * width + blueX) * 4;
      output.data[i + 2] = data[blueI + 2];
      
      // Alpha: unchanged
      output.data[i + 3] = data[i + 3];
    }
  }
  
  ctx.putImageData(output, 0, 0);
};

Use Cases

Design Exploration

Rapidly explore color directions for branding or UI design

Art Generation

Create unique generative art pieces

Visual Effects

Add eye-catching effects to graphics and videos

Color Theory Learning

Interactive way to understand color relationships

Accessibility Testing

Test color combinations for contrast and visibility

Mood Boards

Generate inspiring color palettes for creative projects

Installation

1

Get API Key

Sign up for Google AI Studio: https://ai.google.devGet your Gemini API key
2

Clone Repository

cd source/Experiments/Chromatic\ Illusion\ Weaponizer
3

Install Dependencies

npm install
4

Configure Environment

Create .env.local:
GEMINI_API_KEY=your_api_key_here
5

Run Development Server

npm run dev

Interface

Control Panel

  • Text input for palette descriptions
  • Generate button
  • Generated palette display
  • Color harmony analysis

Keyboard Shortcuts

ShortcutAction
SpaceToggle effect on/off
GGenerate new palette
EExport current view
RReset to original
1-9Quick switch between effects
↑/↓Adjust primary parameter
Shift + ↑/↓Fine adjustment

Example Prompts

  • “Energetic and vibrant for a fitness app”
  • “Calm and professional for a law firm”
  • “Mysterious and dark for a thriller novel”
  • “Playful and friendly for a kids’ game”
  • “Desert sunset with warm oranges and purples”
  • “Deep ocean with blues and teals”
  • “Autumn forest with reds and golds”
  • “Northern lights with greens and purples”
  • “1980s synthwave aesthetic”
  • “Art Deco elegance”
  • “Cyberpunk neon”
  • “Scandinavian minimalism”
  • “Speed and motion”
  • “Growth and transformation”
  • “Tension and release”
  • “Chaos and order”

Learnings

Key insights from this experiment:

Technical

  • AI understanding of color is surprisingly sophisticated
  • Canvas performance matters - use requestAnimationFrame
  • Color space choice affects perception (LAB is more perceptually uniform)
  • Caching AI responses dramatically improves UX

Design

  • Users prefer seeing reasoning behind AI choices
  • Real-time feedback is crucial for creative tools
  • Undo/redo is non-negotiable
  • Presets help users get started quickly

AI Prompting

  • Structured output (JSON) is more reliable than free-form
  • Examples in prompt improve consistency
  • Explaining constraints gets better results
  • Iterative refinement works better than one-shot generation

Future Directions

Animation

Generate color-shifting animations and transitions

Image Analysis

Upload images and extract dominant palettes

3D Effects

Extend to 3D space with WebGL

Collaboration

Multi-user real-time palette generation
This is an experimental project. Some effects may cause discomfort for users with photosensitivity. Always include warnings when sharing.

Example Output

Prompt: “Cyberpunk Tokyo night scene”
{
  "colors": [
    {"hex": "#FF006E", "name": "Neon Pink"},
    {"hex": "#8338EC", "name": "Electric Purple"},
    {"hex": "#00F5FF", "name": "Cyan Glow"},
    {"hex": "#0A0E27", "name": "Deep Night"},
    {"hex": "#FFBE0B", "name": "Golden Accent"}
  ],
  "reasoning": "This palette captures the essence of cyberpunk Tokyo with high-contrast neon colors (pink, purple, cyan) against a dark base. The golden accent represents street lights and signage, creating depth and visual interest."
}

Try It Live

Experience Chromatic Illusion Weaponizer in your browser

Build docs developers (and LLMs) love