1

So after some trial and error, I think I have my math finally figured out correctly. Initially, I started this as a set of complex lists, but then found out that the array function is more suited to what I need.

Now that I have established the array, I get this new error:

EDIT:

Traceback (most recent call last):
  File "(stdin)", line 1, in (module)
  File "backandforth3.py", line 118, in (module)
    frames.insert((x+f), (archstartred[x]))
TypeError: list index out of range

As I frustratingly yell at the computer that all the data already is an integer, I spare my computer monitor and thought I'd try here. All the help on here so far has been fantastic.

Here's how I generate the array and the data for the array: EDIT: Added the list generator to the program code as it seems to be generating non-integer values.

#List Generator

archstartred = []
archstartgrn = []
archstartblu = []

##Red List
for x in range (0, cursorsize):
    if len(archstartred) < cursorsize:archstartred.insert(0,cursred)

for x in range (0, (archnodes-cursorsize)):
    if len(archstartred) < archnodes:archstartred.append(backred)

##Green List
for x in range (0, cursorsize):
    if len(archstartgrn) < cursorsize:archstartgrn.insert(0,cursgrn)

for x in range (0, (archnodes-cursorsize)):
    if len(archstartgrn) < archnodes:archstartgrn.append(backgrn)

##Blue List
for x in range (0, cursorsize):
    if len(archstartblu) < cursorsize:archstartblu.insert(0,cursblu)

for x in range (0, (archnodes-cursorsize)):
    if len(archstartblu) < archnodes:archstartblu.append(backblu)


archstartred = [int(value) for value in archstartred]
archstartgrn = [int(value) for value in archstartgrn]
archstartblu = [int(value) for value in archstartblu]





#Frame Creation

from array import *

frames=array('i', (0 for i in range (0,workingframes*archnodes*3)))






#Frame Population

for f in range (0, workingframes):

    if f<=(workingframes/2):

        for x in range (0, (archnodes*3)):
            frames.pop(x+f)
            frames.insert((x+f), (archstartred[x]))
            frames.pop((x+f)+workingframes)
            frames.insert((x+f+workingframes), (archstartgrn[x]))
            frames.pop((x+f)+workingframes*2)
            frames.insert((x+f+workingframes*2), (archstartblu[x]))

        for y in range (0, nodesperframe):
            archstartred.pop()
            archstartgrn.pop()
            archstartblu.pop()
            archstartred.insert(0, backred)
            archstartgrn.insert(0, backgrn)
            archstartblu.insert(0, backblu)

    else:
        for y in range (0, nodesperframe):
            archstartred.pop(0)
            archstartgrn.pop(0)
            archstartblu.pop(0)
            archstartred.append(backred)
            archstartgrn.append(backgrn)
            archstartblu.append(backblu)

        for x in range (0, (archnodes*3)):
            frames.pop(x+f)
            frames.insert((x+f), (archstartred[x]))
            frames.pop((x+f)+workingframes)
            frames.insert((x+f+workingframes), (archstartgrn[x]))
            frames.pop((x+f)+workingframes*2)
            frames.insert((x+f+workingframes*2), (archstartblu[x]))

This is the same program I've been dealing with in my other posts. Basically, it's to generate data for use in an RGB lighting system. This "simple" program will generate a back and forth effect using 2 colors. The other variables include length of time the effect takes, frame size (we use "Sequencers" to generate displays and you can vary the frame size in the sequencer), "cursor" size, etc.

Of course, once I figure out this effect, I'll be able to make more complex effects based on mathematical formulas.

14
  • 1
    What line number? Could you post the full traceback message (it would be helpful as it contains more information incl. line numbers) Commented Jul 25, 2012 at 20:09
  • What line is giving you the error? Check the error message. Commented Jul 25, 2012 at 20:10
  • A point of style, the leading 0 in your range calls in redundant. Calling range with a single argument assumes you mean to start from 0. Commented Jul 25, 2012 at 20:12
  • 5
    As the error message indicates, the line that causes the error is this: frames.insert((x+f), (archstartred[x])). Obviously x and f are integers, because they're defined here as such via the for loop, and you never redefine them inside the loop. So archstartred[x] must not be an integer. Show us the definition of archstartred[x]. Commented Jul 25, 2012 at 20:20
  • 1
    What's in your archstartred array? Commented Jul 25, 2012 at 20:20

3 Answers 3

1

To convert your list of integers in quotes ['255', '255', '255', '255', '0'] to int properly use this code (you were close):

archstartred = [int(value) for value in archstartred]

it will yield

[255, 255, 255, 255, 0]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That's what I get for copying and pasting from other programs!
1

You don't seem to be looping x to get all archstartred. Did you write an extra [x]?

I mean, here, this is indented at level 0, outside all loops:

for x in range (0, (archnodes-cursorsize)):
   if len(archstartblu) < archnodes:archstartblu.append(backblu)

archstartred[x] = [int(value) for value in archstartred[x]]
archstartgrn[x] = [int(value) for value in archstartgrn[x]]
archstartblu[x] = [int(value) for value in archstartblu[x]]

So you only "touch" the very last item (if that) of archstartred, grn, blu. I would have expected either

for x in ...
    archstartred[x] = [int(value) for value in archstartred]

or

archstartred = [int(value) for value in archstartred]

Comments

1

Your new error means that you are attempting to access a value outside the length of your array. If you have an array of four items [1, 2, 3, 4] then arr[5] will fail with your error.

So you are most likely looping too many times around. Otherwise you don't have enough elements in your array.

1 Comment

Isn't the array set to the correct size? The loop(s) in the "Frame Population" part of the program is the same as the "Frame Creation" part of the program? (workingframes*archnodes*3). I "pop" the data and then "insert" the new value, so the net change to the info in the array is 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.