views:

37

answers:

2

I'm writing a program to generate some wild visuals. So far I can paint each pixel with a random blue value:

for (y = 0; y < YMAX; y++) {
    for (x = 0; x < XMAX; x++) {
        b = rand() % 255;
        setPixelColor(x,y,r,g,b);
    }
}

I'd like to do more than just make blue noise, but I'm not sure where to start (Google isn't helping me much today), so it would be great if you could share anything you know on the subject or some links to related resources.

A: 

Waves are usually done with trig functions (sin/cos) or tables that approximate them.

You can also do some cool water ripples with some simple math. See here for code and an online demo.

Marcelo Cantos
Thanks, I completely forgot about trig functions.
Nathan
A: 

I used to do such kind of tricks in the past. Unfortunately, I don't have the code :-/

You'll be amazed of what effects bitwise and integer arithmetic operators can produce:

FRAME_ITERATION++;
for (y = 0; y < YMAX; y++) {
    for (x = 0; x < XMAX; x++) {
        b = (x | y) % FRAME_ITERATION;
        setPixelColor(x,y,r,g,b);
    }
}

Sorry but I don't remember the exact combinations, so b = (x | y) % FRAME_ITERATION;
might actually render nothing beautiful. But, you can try your own combos.

Anyway, with code like the above, you can produce weird patterns and even water-like effects.

Nick D
Bitwise gives some interesting results, and thanks for the FRAME_ITERATION part, that's the crucial bit that my code was missing.
Nathan