[open] other ways to draw items on canvas?
I'm in the process of optimizing my opensesame script for a faster display with a Surface3 tablet (with atom CPU at 2.4Ghz and IntelHD graphics)
What I see is that it's very slow while using the various canvas functions, such as copy() and show() or simply adding a rect() or image() to an already existing canvas.
So I was wondering if there is another way to simply draw rectangles/ellipse/whatever to a sketchpad withouth redrawing the screen.
here is a piece of code I am running using the expyriment backend:
from math import sqrt coordsAge= [(-800,-365),(-800,-282),(-800,-193),(-800,-109),(-800,-22),(-800,63)] coordsAgeErr=[50,20] #pixels massimi di errore rispetto al centro del rettangolo ellipseAge=[(-901,-395,167,52),(-901,-310,167,52),(-901,-225,167,52),(-901,-145,167,52),(-901,-59,167,52),(-901,23,167,52)] colorAge="#eaffff" x=y=w=h=0 previousAgeIndex=-1 sketchpadname = "sketchInfo%s" % exp.get('languageSpoken') # name of the sketchpad in which you present your picture no_click=True print "--before copying sketchpad: %d" % self.experiment.time() cnvs_Info.copy(exp.items[sketchpadname].canvas) #canvas is defined in the PRE section of the script print "--after copying sketchpad: %d," % (self.experiment.time()) while no_click: print "---------------------------------------running WhileLoop time=%d --------------------------------------" % self.experiment.time() # wait for buttonpress click,clickpos,clicktime = my_mouse.get_click(timeout=5000) # if button is clicked... if click != None: print "mouse_CLICKcoord: %d,%d" % (clickpos-xc,clickpos-yc) # now we check if the click was inside a column and later if iw's inside a row # we check if we have clicked into a specific column +/- some jitter # if yes we check if we have clicked inside a specific row +/- some jitter # if no then we have clicked outside and we loop again for another mouseClick if abs(clickpos-xc-coordsAge) <= coordsAgeErr : print "let's check if we are in Age %d" % self.experiment.time() for indexOfAge,(xvar,yvar) in enumerate(coordsAge): #errX= abs(clickpos-xc-xvar) errY= abs(clickpos-yc-yvar) if errY<=coordsAgeErr: print "-----> clicked Age's item #%d <-----------------" % indexOfAge #now we check if we have already selected an item and maybe we want to click to another inside the same column # so let's simply draw another ellipse with the same background to hide the previous one if previousAgeIndex >=0: x,y,w,h=ellipseAge[previousAgeIndex] print "---- time before deleting the previous ellipse %d" % self.experiment.time() cnvs_Info.ellipse(x+xc,y+yc,w,h,color=colorAge,penwidth=5) print "---- time after deleting the previous ellipse %d" % self.experiment.time() previousAgeIndex=indexOfAge x,y,w,h=ellipseAge[indexOfAge] #coords of an ellipse around the Age's item (coords are predefined at beginning of script) print "time before inserting a new ellipse %d" % self.experiment.time() cnvs_Info.ellipse(x+xc,y+yc,w,h,color='red',penwidth=5) print "time before inserting a new ellipse %d" % self.experiment.time() cnvs_Info.show() print "---- time after showing the updated canvas %d" % self.experiment.time() foundAge=True break #let's go out from the FOR loop and maybe to another While loop print "time needed for loop FORAge %d" % self.experiment.time() else: print "we did'nt click inside any columns, let's wait for another click time: %d" % self.experiment.time() else: #no click within a time, so let's set some vars for a timeout popup no_click =False exp.set('timeout_occurred','yes')
So basically I have a sketchpad with many texts inside. When a subject click over a text an ellipse is drawn to select the choice. This step of selecting/drawing takes 700ms on this surface while on PC takes 350ms. The most of the time is taken by the canvas.show().
Disabling openGL the script goes faster a lot, but I don;t know what I am missing. I need precision in other task where the user has to click on image-button over a sketchpad.