WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-12-2019, 11:39 PM
Roy Roy is offline
Member
 
Join Date: Dec 2019
Posts: 12
Visual Analog Scale

Hi,

Is there any example program for VAS (visual analog scale) to get participants' data?
Or, any functions for it?

Thanks
Reply With Quote
  #2  
Old 12-13-2019, 05:57 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
There is no built-in VAS GUI object but it's possible to create one. Here is an example that adds a VAS slider to the ortho layer. The user can select a value between 0-10:

Code:
import viz
import viztask

VAS_MOVE_EVENT = viz.getEventID('VAS_MOVE_EVENT')
VAS_CONFIRM_EVENT = viz.getEventID('VAS_CONFIRM_EVENT')

class SliderVAS:
	"""Add a VAS slider to the ortho layer"""
	
	def __init__(self, text, scale=2, left=viz.KEY_LEFT, right=viz.KEY_RIGHT, confirm=viz.KEY_RETURN):
		# parent the slider, slider numbers, and text to a group object
		self._group = viz.addGroup(parent=viz.ORTHO)
		viz.link(viz.CenterCenter,self._group)

		self.slider = viz.addSlider()
		self.slider.setParent(self._group)
		self.slider.setScale([scale,1,1])
		self.slider.setTickSize(.2,1)
		sliderWidth = self.slider.getBoundingBox()[0]
		stepWidth = sliderWidth/11

		self._text = viz.addText(text,parent=self._group)
		self._text.alignment( viz.ALIGN_CENTER_BOTTOM )
		self._text.setPosition(-0,-100)
		self._text.fontSize(45)

		for i in range(0,11):
			slidernum = viz.addText(str(i),parent=self._group)
			slidernum.alignment(viz.TEXT_CENTER_BOTTOM)
			slidernum.setPosition(-sliderWidth/2*0.89 +(i*stepWidth*0.98),75,0)
			slidernum.fontSize(40)
			
		self._waitLeft = viztask.waitKeyDown(left)
		self._waitRight = viztask.waitKeyDown(right)
		self._waitConfirm = viztask.waitKeyDown(confirm)
		self._sliderStep = 0.1
		self._sliderschedule = viztask.schedule( self._moveSlider() )

	# get the slider value as a number between 0 and 10
	def getValue(self):
		value = int(round((self.slider.get() * 10.0)))
		return value

	def _moveSlider(self):
		while True:
			d = yield viztask.waitAny([self._waitLeft,self._waitRight,self._waitConfirm])
			if d.condition is self._waitLeft:
				self.slider.set(self.slider.get()+ self._sliderStep * -1)
				viz.sendEvent(VAS_MOVE_EVENT)
			elif d.condition is self._waitRight:
				self.slider.set(self.slider.get()+ self._sliderStep)
				viz.sendEvent(VAS_MOVE_EVENT)
			else:
				viz.sendEvent(VAS_CONFIRM_EVENT)
				break
		self._group.visible(viz.OFF)


if __name__ == '__main__':
	import vizinfo	
	
	viz.go()
	viz.window.setSize(1280,720)
	viz.clearcolor(viz.SLATE)
	vizinfo.InfoPanel('Use left and right arrow keys to move the slider\ntick and the Enter key to select a value')
	
	questions = ['How much do you like pizza?',
				 'How much do you like chocolate?']
	def surveyTask():		
		for question in questions:
			vas = SliderVAS(question)
			yield viztask.waitEvent(VAS_CONFIRM_EVENT)
			print 'Value:',vas.getValue()
		print 'Survey complete'
		
	viztask.schedule( surveyTask() )
Reply With Quote
Reply


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
Point Cloud and visual field in HTC VIVE brenx Vizard 2 06-01-2017 06:50 AM
Occlude Peripheral Visual Field Qiliang He Vizard 1 03-29-2016 05:18 AM
2nd Analog Stick on Gamepad EnvisMJ Vizard 4 11-10-2012 06:15 PM
avatar scale and link.setpos conflict? sircedric4 Vizard 0 09-29-2009 08:48 AM
scale of image increase over time durf Vizard 1 05-08-2009 10:53 AM


All times are GMT -7. The time now is 03:33 PM.


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