I work on a project where we aim at drawing shape based on csv reading. Code is working (basically, it opens csvfile then read data line by line and update size and color of an ellipse for each line). However, when I check for duration consistancy of my code, I can see that :
- duration is not accurate : I’m reading a 1000 lines csv sheet, with frameRate set at 100, so my code in draw() loop is supposed to last for 10 sec --> when I test with time.time() function, I can see my draw() loop is around 11.4 sec
- duration is not consistant : sometimes, my draw() loop is around 11.4 sec, sometimes 11.7 sec, and so on…
Can someone tell me how to optimize my code to be accurate on reading and update, and consistant please ?
Here is my code :
import csv import time global reader global data global i i=0 # path for data to read filename = '/Users/yannickdaviaux/Desktop/essais' # open data file to read with open(filename) as csvfile: data = csvfile.readlines() # define vizualisation window setup def setup(): size(640, 360) noSmooth() frameRate(100) background(0) start_time = time.time() # draw processing animation def draw(): global i global data global c global d if i < 1000: c = map(float(data[i]),float(min(data)),float(max(data)),0,175) d = map(float(data[i]),float(min(data)),float(max(data)), 40, 300) fill(255,c,0) ellipse(width/2,height/2,d,d) i = i+1 if i == 1000: end_time = time.time() elapsed = end_time - start_time print(elapsed)