WorldViz User Forum Updating object color
 Register FAQ Search Today's Posts Mark Forums Read

#1
12-20-2011, 05:21 AM
 sxu04 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:

for i in range(0,12):
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.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)

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 :
ball.model.runAction(showColor)
ball.colorShowing = True
else:
if distance > 11 :
ball.model.runAction(showWhite)
ball.colorShowing = False

vizact.ontimer(0,changeColor)
#2
12-20-2011, 10:04 AM
 Jeff WorldViz Team Member Join Date: Aug 2008 Posts: 2,462
Please use the code tags when posting code so the indentation is preserved.
#3
12-21-2011, 01:27 AM
 sxu04 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:

for i in range(0,12):
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)

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 :
ball.model.runAction(showColor)
ball.colorShowing = True
else:
if distance > 10 :
ball.model.runAction(showWhite)
ball.colorShowing = False

vizact.ontimer(0,changeColor)```
#4
12-21-2011, 02:33 PM
 Jeff WorldViz Team Member Join Date: Aug 2008 Posts: 2,462
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.
#5
01-04-2012, 06:47 AM
 sxu04 Member Join Date: Dec 2011 Posts: 4

 Thread Tools Display Modes Rate This Thread Hybrid Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

 Similar Threads Thread Thread Starter Forum Replies Last Post whj Vizard 1 09-25-2012 03:15 PM Geoffrey Vizard 11 12-11-2009 04:26 AM GiudiceLab Vizard 7 11-05-2009 11:40 AM Boerske Vizard 4 10-09-2009 10:18 AM jargon Vizard 1 08-08-2005 12:20 PM

All times are GMT -7. The time now is 11:24 AM.