topical media & game development
graphic-processing-learning-15-example-15-5-example-15-5.pde / pde
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 15-5: Setting pixels
size(200,200);
// Before we deal with pixels
loadPixels();
// Loop through every pixel
for (int i = 0; i < pixels.length; i++ ) { // We can get the length of the pixels array just like with any array.
// Pick a random number, 0 to 255
float rand = random(255);
// Create a grayscale color based on random number
color c = color(rand);
// Set pixel at that location to random color
pixels[i] = c; // We can access individual elements of the pixels array via an index, just like with any other array.
}
// When we are finished dealing with pixels
updatePixels();
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.