WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-11-2021, 11:24 PM
turinlife turinlife is offline
Registered User
 
Join Date: Jul 2021
Posts: 2
Smile Create Two sequential tasks for images in Vizard

I'm new in Vizard. I'm trying to create a simple code to perform two tasks sequentially for a specific time set:

A black image for 0.8 seconds
A sequence of images (from a folder) taken randomly, for 1.5 seconds. I can perform these task separately, but I can't merge together. Suggestions are very appreciated, thank you

Code:
import viz
import vizact
import vizinfo
import random


viz.setMultiSample(4)
viz.fov(60)
viz.go()

vizinfo.InfoPanel()
viz.clearcolor(viz.BLACK)

FRAME_RATE  = 0.667       # in Hertz

r = list(range(7))
random.shuffle(r)
movieImages = viz.cycle( [ viz.addTexture('sequence_IMG/img%d.jpg' % i) for i in r ] )
screen = viz.addTexQuad()
screen.setPosition([0, 1.82, 1.5])
screen.setScale([4.0/3, 1, 1])

def executeExperiment():
    for trialNumber in range(3):
        yield Dark() #wait for doTrial to finish
        yield vizact.ontimer(1.0/FRAME_RATE, NextMovieFrame)
        print('Trial Done: ', trialNumber)

    print('done with experiment')

#Setup timer to swap texture at specified frame rate
def NextMovieFrame():
    screen.texture(movieImages.next())
    
def Dark():
    yield viztask.waitTime(1) #wait for 1 second
    viz.clearcolor(viz.BLACK)
    
vizact.ontimer(1.0/FRAME_RATE, NextMovieFrame)
viztask.schedule(executeExperiment())
Reply With Quote
  #2  
Old 07-12-2021, 07:05 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Use viztask.waitTime instead of vizact.ontimer to wait inside of a task function. It seems like you can place the sequential actions in a single task function:
Code:
blankTexture = viz.addBlankTexture(size=(100,100))

def executeExperiment():
    for trialNumber in range(3):
        # Show blank texture for one second
        screen.texture(blankTexture)
        yield viztask.waitTime(1)

        # Show movie texture for 1.5 seconds
        screen.texture(movieImages.next())
        yield viztask.waitTime(1.5)

        print('Trial Done: ', trialNumber)
    print('done with experiment')
Reply With Quote
  #3  
Old 07-27-2021, 01:00 PM
turinlife turinlife is offline
Registered User
 
Join Date: Jul 2021
Posts: 2
Display random images from a folder

Thank you so much!
It is also possible to display the image from a folder randomly without rename all the images in the folder?
an alternative solution for this 3 lines
Code:
r = list(range(7))
random.shuffle(r)
movieImages = viz.cycle( [ viz.addTexture('sequence_IMG/img%d.jpg' % i) for i in r ] )
Reply With Quote
Reply

Tags
images, tasks, vizard 7


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vizard 4 Beta Testing farshizzo Announcements 0 02-01-2011 11:46 AM
Vizard 4 Beta Testing farshizzo Vizard 0 02-01-2011 11:46 AM
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 12:13 PM
Vizard Tip of the Month: Use Tasks to Simplify your Code Gladsomebeast Vizard 5 05-02-2008 05:30 PM


All times are GMT -7. The time now is 12:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC