Animating progression of Lines Drawn




from pandac.PandaModules import Vec4
from pandac.PandaModules import LineSegs
import direct.directbase.DirectStart
import math
import time
cos=math.cos
sin=math.sin
pi=math.pi
for x in range(1,3):
	if x==1:
		Px=-15
		Py=0
		red=0
		g=0
		b=1
		num=700
		Factor=103
		r=15
	if x==2:
		Px=15
		Py=0
		red=.5
		g=0
		b=0
		num=250
		Factor=220
		r=15
	for i in range(0,num):
		P=i*Factor;
		while P>num:
			P=P-num
		x1=r*cos(i*2*pi/num)+Px
		y1=r*sin(i*2*pi/num)+Py
		x2=r*cos(P*2*pi/num)+Px
		y2=r*sin(P*2*pi/num)+Py
		segs = LineSegs( )
		segs.setThickness( 0.0001 )
		segs.setColor(red,g,b)
		segs.moveTo(x1,y1,0 )
		segs.drawTo( x2,y2,0 )
		f=segs.create( )
		render.attachNewNode( f )
base.setBackgroundColor(0, 0, 0)
base.disableMouse( )
base.camera.setPos( 0, 0, 90)
base.camera.lookAt( 0, 0, 0 )
base.run()
		

Hello,
Is there a way to display the progression as each line is drawn as opposed to rendering the output in the attached program? I tried doing a time.sleep() before the for loop but that doesn’t seem to work
LS.py (871 Bytes)

Instead of generating your line segments in a loop, as above, perhaps place them in a task. On each run of the task, add a new line, until all have been drawn. That should result in one line being drawn per frame. To control the speed, you might either set the task to fire after a set interval (perhaps via “doMethodLater”), or implement a timed “count-down” in your own code.

For information on tasks, see this manual page.

Thanks for the reply, I’ll look into to tasks