Display 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 getting the complete collection of lines drawn? I tried doing a time.sleep() before the for loop but that doesn’t seem to work
LS.py (871 Bytes)

If you’re asking for rendering each line as soon as it’s created, you could add

base.graphics_engine.renderFrame()

to your inner for loop after the render.attachNewNode( f ).

Yea it doesn’t seem to work, thanks tho

what exactly doesn’t work? Do you get an error message or does it simply not draw the lines as soon as they are created? As I tested it, mind sharing your changed code again and tell us which version of p3d you use, so we can check if this is a bug in the code or the engine?

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.graphicsEngine.renderFrame()
		
base.setBackgroundColor(0, 0, 0)
base.disableMouse( )
base.camera.setPos( 0, 0, 90)
base.camera.lookAt( 0, 0, 0 )
base.run()

I just added base.graphisEngine.renderFrame() and when the window pops up one line is shown drawn then it just stays like that for about 15 seconds then it shows all the sudden all the lines are shown drawn in one single frame. But yea the window mainly stays empty for those 15 seconds…I use p3d 1.9.4

Make sure to call

base.setBackgroundColor(0, 0, 0)
base.disableMouse( )
base.camera.setPos( 0, 0, 90)
base.camera.lookAt( 0, 0, 0 )

before the for loops, otherwise the lines get drawn one after the other but you will only see them from the default camera position (from the side). If you move the camera placement before the first for loop or right after your imports, you should see each line being created.

Wow can’t believe I missed that, you can tell I’m new to panda. And yea the renderFrame works good I wish there was a way to control the speed of it

There are a few ways to control the speed of it. One for example would be to use a task in which you can check how much time has passed or directly call the task each n seconds. Alternatively you can also use intervals which might be better suited and simpler to use dependent on what you want to do. Just make sure to create, store and render the objects before you’re going to use them as the time to render them will vary greatly from machine to machine. You can simply call .hide() on a created nodepath to make it invisible to the user and in the task or interval you’d then call .show on the nodepath to make it instantly visible again.

I’ll look ino that, thanks for your help!