WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-20-2011, 06:21 AM
sxu04 sxu04 is offline
Member
 
Join Date: Dec 2011
Posts: 4
Updating object color

I’m really hoping that someone could kindly steer me in the right direction……

I have 12 balls positioned in an environment and (using the ‘Experiment’ example in the Vizard Help) these balls only show their colour when the subject is near them. On approach, the balls will either turn red or green based on a predetermined sequence. However, in addition I need the red balls to have a 1 in 10 chance of turning orange and for this to update every 3 seconds. I am however having issues updating the colour of the balls once the colour has been assigned.

Any help would be very much appreciated!


a1=-37.5
a2=-12.5
a3=12.5
a4=37.5
x=2.75
y=3.85
z=1.1
b1=34.5
b2=16.5
b3=8.5
b4=-8.5
b5=-16.5
b6=-34.5

positions = [[a1,x,b1],[a1,x,b2],[a1,x,b3],[a1,x,b4],[a1,x,b5],[a1,x,b6],[a1,z,b1],[a1,z,b2],[a1,z,b3],[a1,z,b4],[a1,z,b5],[a1,z,b6]]

R=viz.RED
G=viz.GREEN

colors=[R,R,R,R,R,R,G,G,G,G,G,G]


balls=[]

def col():
while True:
yield viztask.waitTime(1)

for i in range(0,12):
model=vizshape.addSphere(1,10,10)
model.setPosition(positions[i])
ball = viz.Data()
ball.model = model

x=random.randint(1,10)

if x == 1:
if colors[i]==R:
#ball.model.clearAttribute(viz.ATTR_COLOR)
#model=vizshape.addSphere(1,10,10)
#model.setPosition(positions[i])
#model.setScale(1.1,1.1,1.1)

ball.color=(viz.ORANGE)

ball.colorShowing = False


balls.append(ball)
#print 'red'
if colors[i]==G:


ball.color=(colors[i])
ball.colorShowing = False
balls.append(ball)


else:
ball.color=(colors[i])
#print 'green'
ball.colorShowing = False
balls.append(ball)


viztask.schedule( col() )

def changeColor():
viewPos = viz.MainView.getPosition()
for ball in balls:
ballPos = ball.model.getPosition()
distance = vizmat.Distance(viewPos, ballPos)

if ball.colorShowing is False:
if distance < 11 :
showColor=vizact.sequence(vizact.waittime(0.1),viz act.fadeTo(ball.color,time=0.7))
ball.model.runAction(showColor)
ball.colorShowing = True
else:
if distance > 11 :
showWhite = vizact.fadeTo(viz.WHITE,time=4)
ball.model.runAction(showWhite)
ball.colorShowing = False

vizact.ontimer(0,changeColor)
Reply With Quote
  #2  
Old 12-20-2011, 11:04 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Please use the code tags when posting code so the indentation is preserved.
Reply With Quote
  #3  
Old 12-21-2011, 02:27 AM
sxu04 sxu04 is offline
Member
 
Join Date: Dec 2011
Posts: 4
Sorry this is the first time I've posted on a forum


Code:
a1=-37.5
a2=-12.5
a3=12.5
a4=37.5
x=2.75
y=3.85
z=1.1
b1=34.5
b2=16.5
b3=8.5
b4=-8.5
b5=-16.5
b6=-34.5

positions = [[a1,x,b1],[a1,x,b2],[a1,x,b3],[a1,x,b4],[a1,x,b5],[a1,x,b6],[a1,z,b1],[a1,z,b2],[a1,z,b3],[a1,z,b4],[a1,z,b5],[a1,z,b6]]

R=viz.RED
G=viz.GREEN

colors=[R,R,R,R,R,R,G,G,G,G,G,G]

balls=[]

def col():					
	while True:
		yield viztask.waitTime(3)

		for i in range(0,12):
			model=vizshape.addSphere(1,10,10)
			model.setPosition(positions[i])
			ball = viz.Data()
			ball.model = model
					
			x=random.randint(1,10)
			
			if x == 1:
	
				if colors[i]==R:
															
					ball.color=(viz.ORANGE)
						
				if colors[i]==G:
					ball.color=(colors[i])
			else:				

					ball.color=(colors[i])
					
			ball.colorShowing = False
			balls.append(ball)

		

viztask.schedule( col() ) 

def changeColor():
		viewPos = viz.MainView.getPosition()
		for ball in balls:  
			ballPos = ball.model.getPosition()
			distance = vizmat.Distance(viewPos, ballPos)

			if ball.colorShowing is False: 
				if distance < 10 :
					showColor=vizact.sequence(vizact.waittime(0.1),vizact.fadeTo(ball.color,time=0.7))
					ball.model.runAction(showColor)
					ball.colorShowing = True
			else:
				if distance > 10 :
					showWhite = vizact.fadeTo(viz.WHITE,time=4)																 			
					ball.model.runAction(showWhite)
					ball.colorShowing = False

vizact.ontimer(0,changeColor)
Reply With Quote
  #4  
Old 12-21-2011, 03:33 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Each time the code in the while loop is run you're adding balls in the positions where old ones already are. I think the issue you see is related to that. Try adding the shapes once outside of the while loop and just update their colors within.
Reply With Quote
  #5  
Old 01-04-2012, 07:47 AM
sxu04 sxu04 is offline
Member
 
Join Date: Dec 2011
Posts: 4
Great, thanks for your help
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
How to render a texture of the transparent object and then blur it whj Vizard 1 09-25-2012 04:15 PM
retrieve Object names Geoffrey Vizard 11 12-11-2009 05:26 AM
Trouble with listener updating position? GiudiceLab Vizard 7 11-05-2009 12:40 PM
imported 3DModel - Color Write - Problem Boerske Vizard 4 10-09-2009 11:18 AM
rotate to object jargon Vizard 1 08-08-2005 01:20 PM


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


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