BOB
BOB

Reputation: 1

how to randomly change the color of every pixel on the screen

I want each pixel on the screen to flash between red, blue, green, white, and black but independently of each other. Is this possible? I have been searching everywhere with out any luck. Any help on where to start would be greatly appreciated.

Upvotes: 0

Views: 1956

Answers (1)

user346443
user346443

Reputation: 4862

You can do it using images. For example in a 32 bit RGBA image each pixel is made up from 4 parts

red = 8 bits
green = 8 bits
blue = 8 bits
alpha = 8 bits

Each can be set to a value between 0 and 255;

So you and just treat the image as an array of bytes and change each pixels color values.

Image image = CreateImage();

for(int i = 0; i < image.size(); i++)
    image[i] = RandomNumberBetween(0, 255);

Or create the image from an array of bytes

int byteArray[width * height * 4];

for(int i = 0; i < width * height * 4; i++)
       image[i] = RandomNumberBetween(0, 255);

Image image = createImageFromByteArray(byteArray);

You could also create a simple opengl scene and do it in a shader.

float rand(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void main(void){
     gl_FragColor = rand(gl_TexCoord[0].xy);
}

Upvotes: 6

Related Questions