I tried to write a programm that generates black/white noise (a bit like a TV-set).
The pixels shall flicker from black to white at different speeds, based on the grey values of a b/w image. Seems to work so far, but:
white areas tend to become white instead of true random noisethank you for helping me :)
screenshots:
http://q-garden.de/screens/tmp_51_19693.pngcode:
http://pastie.org/490935 (with nice colours) or:
Code:void setup() {//runs once
//vars for setup
int wid = 400; //width
int hig = 400; //higth
PImage akt_bild;
//setup
size(wid, hig);// Set the window size in pixels
frameRate(30);//per second
//one-time presedures
akt_bild = loadImage("image.jpg"); //load image to add
image(akt_bild, 0, 0); //screen image
loadPixels(); //get pixels from screen to pixel[] array
for (int pixel=0; pixel < wid*hig; ++pixel) { //do this with each pixel
if(round(random(1)) == 1) { //with random: black or white
pixels[pixel] = color (255, 255, 255);
}
else{
pixels[pixel] = color (0, 0, 0);
}
lastframe[pixel] = pixels[pixel];
}
}
//vars
int wid = 400; //width
int hig = 400; //higth
int[] lastframe = new int[wid*hig];
int off = 0;
int count = 0;
int maxi = 30;
void draw() { //frame by frame
if(count < (maxi-1)) { //stoper part1
count = count + 1;
}
else {
off = 1;
}
PImage akt_bild;
akt_bild = loadImage("data/image.jpg"); //load image to add
image(akt_bild, 0, 0); //screen image
loadPixels(); //get pixels from screen to pixel[] array
for (int stufen=1; stufen < 31; ++stufen) {//splitting the image into 30 grey values that are overdrawn by different chances
for (int pixel=0; pixel < wid*hig; ++pixel) { //do this with each pixel
if ((pixels[pixel] & 0xFF) > (256-9*stufen) && (pixels[pixel] & 0xFF) <= (256-9*(stufen-1))){ //bitshift gives color value (brightnes since it's b/w) and if it's in the dark are (beneath 8 of 256) do this
if(random(256) > (256-stufen)) { //for a chance of 256/256 overwrite the color
if(round(random(1)) == 1) { //with random: black or white
pixels[pixel] = color (0, 0, 0);
}
else{
pixels[pixel] = color (255, 255, 255);
}
lastframe[pixel] = pixels[pixel];
}
else{
pixels[pixel] = lastframe[pixel];
}
}
}
}
updatePixels(); //write pixels[] to screen
println("loops " + (pixels[80000] & 0xFF)); //yes it loops, but does not change pixels any more
//saveFrame("data/merge_1#####.tif");//output a snapshot
if(off == 1){//stoper part2
// noLoop();
}
}
P.S.:btw, load/updatePixels() seems to work only if I reload my image.jpg too, why?