开发者

Video Synthesis - Making waves, patterns, gradients

I'm writing a program to generate some wild visuals. So far I can paint ea开发者_如何学Cch 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜