Author Topic: Looking for White noise / tv static algorithms  (Read 987 times)

0 Members and 1 Guest are viewing this topic.

Offline rootuid

  • C= 64
  • **
  • Posts: 97
  • Karma: 2
    • View Profile


Wondering if anyone has any pseudo code or theories for coding white noise aka. tv static.
- Black background.
- random White/grey pixels?

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Looking for White noise / tv static algorithms
« Reply #1 on: October 09, 2006 »
I only know the famous tiny ptc test code by gaffer.

Code: [Select]
//
// TinyPTC by Gaffer
// www.gaffer.org/tinyptc
//

#include "tinyptc.h"

#define WIDTH 320
#define HEIGHT 200
#define SIZE WIDTH*HEIGHT
   
static int noise;
static int carry;
static int index;
static int seed = 0x12345;
static int pixel[SIZE];

int main()
{
    if (!ptc_open("test",WIDTH,HEIGHT)) return 1;
    while (1)
    {
        for (index=0; index<SIZE; index++)
        {
            noise = seed;
            noise >>= 3;
            noise ^= seed;
            carry = noise & 1;
            noise >>= 1;
            seed >>= 1;
            seed |= (carry << 30);
            noise &= 0xFF;
            pixel[index] = (noise<<16) | (noise<<8) | noise;
        }
        ptc_update(pixel);
    }
}

And btw. If you want this fx as a screensaver you can dl it from my page :

http://www.weltenkonstrukteur.de/?site=works&prd=TVNoise
« Last Edit: October 09, 2006 by benny! »
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17294
  • Karma: 489
  • evil/good
    • View Profile
    • My Homepage
Re: Looking for White noise / tv static algorithms
« Reply #2 on: October 09, 2006 »
I've found that the effect works best with only a few different colours, say 3 greys and black.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rootuid

  • C= 64
  • **
  • Posts: 97
  • Karma: 2
    • View Profile
Re: Looking for White noise / tv static algorithms
« Reply #3 on: October 09, 2006 »
Thanks for the feedback. I'm try to convert the code above to BlitzMax but am stuck on 1 or two lines:
            noise >>= 3;

            noise ^= seed;


What is >>= and ^= ? Is this c++ ?

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5243
  • Karma: 393
    • View Profile
Re: Looking for White noise / tv static algorithms
« Reply #4 on: October 09, 2006 »
It's C.

>> is Shr
^ is Xor

So
noise>>=3 is
noise = noise Shr 3
and
noise^=seed is
noise=noise Xor seed

Basically though what's being done here is a random number generator.
Both Blitz and C have one built in so it's not really necessary to write your own.
In Blitz use
noise=Rand(255)
in C use
#include <stdio.h>
noise=rand()&0xff
and in freebasic do
#include "crt.bi"
noise=rand() and &hff

You might want to make sure it's totally random too.  You need to seed the random number generator.
In the sample posted that means change 'seed' to be something else.
In Blitz you do
SeedRnd MilliSecs()
In C you do
#include <time.h>
srand(time(NULL));

Jim
Challenge Trophies Won: