Color of a screen pixel: Difference between revisions
Content added Content deleted
(Add SmileBASIC implementation) |
(Add Processing) |
||
Line 552: | Line 552: | ||
<pre>73,61,205 |
<pre>73,61,205 |
||
-> (73 61 205)</pre> |
-> (73 61 205)</pre> |
||
=={{header|Processing}}== |
|||
Access any pixel value on the sketch canvas. A color in Processing is a 32-bit int, organized in four components, alpha red green blue, as AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB. Each component is 8 bits (a number between 0 and 255), and can be accessed with alpha(), red(), green(), blue(). |
|||
<lang processing>void draw(){ |
|||
color c = get(mouseX,mouseY); |
|||
println(c, red(c), green(c), blue(c)); |
|||
}</lang> |
|||
For greater speed, pixels may be looked up by index in the pixels[] array, and color components may be retrieved by bit-shifting. |
|||
<lang processing>void draw(){ |
|||
loadPixels(); |
|||
color c = pixels[mouseY * width + mouseX]; |
|||
println(c, c >> 16 & 0xFF, c >> 8 & 0xFF, c >> 8 & 0xFF); |
|||
}</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |