We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm attempting to do Dan Shiffman's Pixel Array in Python but get the error after just a few iterations. Here's the code:
inc = 0.01
def setup():
size(6, 5)
def draw():
# background(50)
global inc
yoff = 0
loadPixels()
for y in range(height-1):
xoff = 0
for x in range(width):
idx = (x + y * width) * 4
r = noise(xoff, yoff) * 255
pixels[idx+0] = r
pixels[idx+1] = r
pixels[idx+2] = r
pixels[idx+3] = 255
xoff += inc
yoff += inc
updatePixels()
The error appears here: pixels[idx+2] = r
Thanks for any help!
~dallas_borealis
Answers
pixels[] in Processing is made outta 32-bit (4-byte) aRGB
color
values: L-)Huh. You can't address the individual RGB values for a specific pixel in the Pixel Array. Good to know. Thanks.
But how does his work?
In order to get the individual aRGB values, we use bitshifting operator
>>
:http://py.Processing.org/reference/rightshift.html
Plus bitwise operator
&
in order to mask off the left-side remaining bits from the originalcolor
value: http://py.Processing.org/reference/bitwiseAND.htmlIn the reference, you should check:
Kf