What could be causing 'array.array assignment index out of range' error?

edited May 2017 in Python Mode

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

Sign In or Register to comment.