Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Using Parallel plug-in in OpenSesame

edited November 2015 in OpenSesame

I want to display two blocks (say squares) that will blink with two different frequencies, on the screen. How can I achieve this using the 'parallel plug-in' in OpenSesame?

Comments

  • edited 8:49AM

    Hi,

    I have no experience in using the parallel plug-in myself (and I've also heard that it is a bit unstable), but I do think this is achievable without the parallel plug-in in the first place. How well it works depends on the desired frequencies though; very high frequencies may not be displayed properly.
    The idea would be to create 4 canvases in an inlinescript, one for each 'state', i.e., a canvas with two squares on, a canvas with one square on and one square off, etc. In the run phase, you start a timer by means of start_time = self.time(). Next, you keep track of time in a while-loop, and present the canvases accordingly. Say these are the frequencies and states (1 for on, -1 for off):

      square1_freq = 12
      square2_freq = 8
      square1_state = 1
      square2_state = 1 
    

    As an example, you want the second square to go on/off at 1/8*1000 milliseconds and all multiplications of this value. Hence, you get something like this:

      end_reached = False
      stimuli_presentation_duration = 2000
    
      current_multiplication_sq1 = 1
      current_multiplication_sq2 = 1      
      while end_reached == False:
             canvas_change = False
             current_time = self.time() - start_time
             if current_time >= float(1)/square1_freq*1000*current_multiplication_sq1:
                   square1_state = square1_state * -1
                   current_multiplication_sq1 += 1
                   canvas_change = True
             if current_time >= float(1)/square2_freq*1000*current_multiplication_sq2:
                   square2_state = square2_state * -1
                   current_multiplication_sq2 += 1
                   canvas_change = True
    
             if canvas_change == True:
                   if square1_state == 1 and square2_state == 1:
                          canvas1.show()
                   elif square1_state == -1 and square2_state == 1:
                          canvas2.show()
                   elif square1_state == 1 and square2_state == -1:
                          canvas3.show()
                   elif square1_state == -1 and square2_state == -1:
                          canvas4.show()
    
             if current_time >= stimuli_presentation_duration:
                   end_reached = True      
    

    Let me know if this works.

    Cheers,

    Josh

  • edited November 2015

    Hi Josh,

    Thanks for the tip.
    I'm a kinda new to OpenSesame and it took me a while to understand the use of inline code. I compiled the code and run it with 4 sketchpads c1, c2, c3, c4 in the experiment modifying your code as shown below.


    start_time = self.time() square1_freq = 12 square2_freq = 8 square1_state = 1 square2_state = 1 canvas1 = canvas() canvas2 = canvas() canvas3 = canvas() canvas4 = canvas() canvas1.c1() canvas2.c2() canvas3.c3() canvas4.c4() end_reached = False stimuli_presentation_duration = 2000 current_multiplication_sq1 = 1 current_multiplication_sq2 = 1 while end_reached == False: canvas_change = False current_time = self.time() - start_time if current_time >= float(1)/square1_freq*1000*current_multiplication_sq1: square1_state = square1_state * -1 current_multiplication_sq1 += 1 canvas_change = True if current_time >= float(1)/square2_freq*1000*current_multiplication_sq2: square2_state = square2_state * -1 current_multiplication_sq2 += 1 canvas_change = True if canvas_change == True: if square1_state == 1 and square2_state == 1: canvas1.show() elif square1_state == -1 and square2_state == 1: canvas2.show() elif square1_state == 1 and square2_state == -1: canvas3.show() elif square1_state == -1 and square2_state == -1: canvas4.show() if current_time >= stimuli_presentation_duration: end_reached = True

    But it reported me the following error.


    File "dist\libqtopensesame\misc\process.py", line 140, in run File "dist\libopensesame\experiment.py", line 390, in run File "dist\libopensesame\item_store.py", line 94, in execute File "dist\libopensesame\item_store.py", line 126, in prepare File "dist\libopensesame\sequence.py", line 106, in prepare File "dist\libopensesame\item_store.py", line 126, in prepare File "dist\libopensesame\sketchpad.py", line 103, in prepare File "dist\openexp\_canvas\xpyriment.py", line 98, in prepare File "dist\expyriment\stimuli\_visual.py", line 752, in plot File "dist\expyriment\stimuli\_visual.py", line 289, in surface_size File "dist\expyriment\stimuli\_visual.py", line 391, in _get_surface File "dist\expyriment\stimuli\_rectangle.py", line 112, in _create_surface error: Invalid resolution for Surface

    Can you please help me to get out of this?

    Cheers.

    Sachinthana

  • edited 8:49AM

    Hi Sachinthana,

    How did you construct (i.e. place the squares on) your canvases? At first glance it seems to me that something went wrong there. You could try to present your canvases in a simplified manner, like this:

       canvas1.show()
       self.sleep(5000)
       canvas2.show()
       self.sleep(5000)   # et cetera.
    

    and see if that works normally.

    Cheers,

    Josh

  • edited 8:49AM

    Hey Josh,

    It worked. Thank you very much. :)

Sign In or Register to comment.