Thread: Updating object color View Single Post
#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 :