Fail to update shape setup from csv data reading

Hi all Processing.org lovers out there,

I’m working on a project were we would like to dynamically represent physiological data through artistic visual representation, with data being measured and streamed in real-time.

To build the project step-by-step, I here only aim at update the color of background of my window (i.e., simple artistic visual representation). Since this color can by defined using a float value, I thought to update this value by reading a csv file line-by-line with physiological data (i.e., to simulate streaming of data).

I know my for-loop to work, since ‘print(color)’ is updated on each for-loop (I can see it in the console). However, can you tell me why my background color is not updated on each for-loop please ?

Thanks a lot !

Here is my code :

import csv

# call for data to read
filename = '/Users/yannickdaviaux/Desktop/001ZRON_PROJ_EDA'

# define vizualistion window setup
def setup():
    size(640, 360)
    noSmooth()
    fill(126)
    frameRate(1000)
    global reader
    reader = csv.reader(open(filename),quoting=csv.QUOTE_NONNUMERIC)
    
# update setup of my window
def draw():
    for row in reader:
         color = row[0]*(-10e7) # basic data transform so I have a float between 100 and 200 --> more advanced data processing will be write later on
         print(color) # so I can test if loop iteration is effective in console
         background(color) # don't understand why color background is not update on each loop iteration

draw does only update the screen once at its end and not throughout.

This is why your for loop won’t work.

Instead of using a for loop, please use the fact that draw in itself loops automatically

Increase the row number you read every time

Welcome to the forum!

3 Likes

Hi Chrisir,

thanks for your help, it is working now. I now have an issue about code optimisation (the duration of the process is not consistant with data length and frameRate, but I’ll open another topic on it).

Thank again for your help

Yannick

1 Like