User Tools

Site Tools


part_8-_editing_the_pixels_array

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
part_8-_editing_the_pixels_array [2007/08/30 13:53]
127.0.0.1 external edit
part_8-_editing_the_pixels_array [2007/09/13 07:27] (current)
scarl Fixed misunderstanding colors as objects, not ints
Line 2: Line 2:
 === Part 8: Editing the pixels[] array === === Part 8: Editing the pixels[] array ===
  
-When using the global ​pixels[] array: +''​pixels[]''​ holds a color value for every pixel currently drawn in the system display window. ​ It can be read and modified to change the display. ​ To use this array to modify the display
-  * You have to call ''​loadPixels()''​ to populate the array (otherwise it will be null). +  * First call ''​loadPixels()''​ to populate the array (otherwise it will be null). 
-  * You can access and change the array directly. +  * Now you can access and change the array directly. 
-  * When you have finished editing, ​you have to call ''​updatePixels()''​ to commit the changes. This will redraw the screen.+  * When finished editing, call ''​updatePixels()''​ to commit the changes. This will redraw the screen.
  
-The global ​''​pixels[]'' ​array contains every pixel in the window in the form of color objects. +//By default//, the color values stored in ''​pixels[]'' ​are made up of Red, Green and Blue (RGB) values.  This is called RGB mode.  Each of the RedGreen, and Blue values are 8-bit numbers ​from 0 to 255:
- +
-A color object is made or Red, Green and Blue (RGB) values, ​which go from 0 to 255:+
   color c = color(125,​125,​125);​   color c = color(125,​125,​125);​
 You can read these values back with the red(), green() and blue() functions. To modify a pixel, you would use something like: You can read these values back with the red(), green() and blue() functions. To modify a pixel, you would use something like:
   pixels[x] = color(125, green(pixels[x]),​ blue(pixels[x]));​   pixels[x] = color(125, green(pixels[x]),​ blue(pixels[x]));​
 +
 +Note:  a common error is to treat a color value as an object. ​  Color values are just 32-bit integers (8 bits for each RGB value plus alpha channel information stored in the extra 8 bits - we'll talk about alpha channels later on), so any code which treats a color as an object will cause a syntax error. ​ Treat color values as the type color in Processing code, and as type ''​int''​ in Java code.
  
 \\ \\
-Next: [[Part 9- A Few Functions for Creating and Manipulating Basic Shapes]] 
  
-Last: [[Part 7- A Few Useful Global Variables]]+Prev: [[Part 7- A Few Useful Global Variables]] | Next: [[Part 9- A Few Functions for Creating and Manipulating Basic Shapes]]
part_8-_editing_the_pixels_array.txt · Last modified: 2007/09/13 07:27 by scarl