#1
|
|||
|
|||
playing sound and displaying picture - condition within loop
Dear all,
I am a programming beginner and I started using Vizard because I am trying to design a little experiment for my studies. Here is what is supposed to happen and below is what I have so far: The screen should show an upper and a lower window. Each window will receive a simple texture (.png or .jpeg) to display two different pictures. In the upper window, there would be the task instruction and in the lower window, there would be a "default" picture. At the same time, a beep sound will play 10 times at random intervals (from 1 to 4 seconds). What I want: 7 out of ten random times, just as a sound cue plays, the lower screen should change from the default picture to Picture A and 3 out of 10 random times to Picture B. Code:
#Set background colour to white: viz.clearcolor(viz.WHITE) taskpic = 'instruction.jpg' pictureA = 'picA.jpg' pictureB = 'picB.jpg' picturedefault = 'default.png' cue = viz.addAudio('dong.wav') SoundDuration = cue.getDuration() import viz import time import viztask import random viz.go() def exp(): #this is the function that triggers my experiment screen2 = viz.addTexQuad(size=0.5) #upper screen window screen2.setPosition([0,2.1,1.3]) screen2.setSize([0.4, 0.4]) screen3 = viz.addTexQuad(size=0.5) #lower screen window screen3.setPosition([0,1.6,1.3]) screen3.setSize([0.4, 0.4]) picture_task = viz.add(taskpic) defaultpic = viz.add(default) screen2.texture(picture_task) #picture with instruction is added as a texture to upper screen screen3.texture(defaultpic) #default picture is added as a texture to upper screen def playCueLoop(): count = 0 while count < 10: count += 1 for x in count: if x <= 7: cue.play() yield viztask.waitTime(SoundDuration+random.randrange(1,4)) cue.stop() PicA = viz.add(PictureA) screen3.texture(PicA) yield viztask.waitTime() elif x <= 3: cue.play() yield viztask.waitTime(SoundDuration+random.randrange(1,4)) cue.stop() PicB = viz.add(PictureB) screen3.texture(PicB) yield viztask.waitTime() #viztask.schedule(playCueLoop) viztask.schedule(exp) I would be happy to receive some pointers in the right direction! At the moment there are probably a lot of things to improve and it is impossible for me to isolate one aspect to test it around. Thank you very much in advance for your help! |
Tags |
condition, loop, picture, sound |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
playing a sound multiple times at different timings | jelly | Vizard | 3 | 02-04-2016 03:39 AM |