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

0 Members and 1 Guest are viewing this topic.

• Atari ST
• Posts: 105
• Karma: 3
##### Looking for White noise / tv static algorithms
« on: October 09, 2006 »

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

#### benny!

• Senior Member
• Posts: 4372
• Karma: 227
• in this place forever!
##### 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:

#### Shockwave

• good/evil
• Founder Member
• Posts: 17297
• Karma: 489
• evil/good
##### 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:

• Atari ST
• Posts: 105
• Karma: 3
##### 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++ ?

#### Jim

• Founder Member
• Posts: 5257
• Karma: 394
##### 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: