PDA

View Full Version : How to use 'time function' to control the balls appear separately?


znchb
11-02-2008, 07:02 AM
# I want to show balls on the screen one by one, not all the balls appear immediately.
# could you please help me to use the time function to control it. Appreciate.

import viz
viz.go()

OriginalBall = viz.add('ball.wrl')

for x in [0, 0.2, 0.4, 0.6, 0.8]: ## nested loop
for y in [0, 0.3, 0.6, 0.9]:
ball = OriginalBall.copy() ##use the copy() to save cpu resource
ball.translate(2+x, 2+y, 2)
ball.setScale(0.02,0.02,0.02)

Jeff
11-03-2008, 12:01 PM
this code adds the balls to an array and initially makes them invisible.
the timer goes off every half second and calls a function that makes one ball visible each time

import viz
viz.go()

OriginalBall = viz.add('ball.wrl')

viz.MainView.setPosition([-2,2.5,-2])
viz.MainView.setEuler([45,0,0])


balls = []
for x in [0, 0.2, 0.4, 0.6, 0.8]: ## nested loop
for y in [0, 0.3, 0.6, 0.9]:
ball = OriginalBall.copy() ##use the copy() to save cpu resource
ball.translate(2+x, 2+y, 2)
ball.setScale(.2,.2,.2)
ball.visible(viz.OFF)
balls.append(ball)


number = 0
def showBall():
global number
balls[number].visible(viz.ON)
number +=1

vizact.ontimer2(.5,len(balls)-1,showBall)

Is this what you wanted to do?
The next time you post code use the code tags so that the indentation is preserved