@@ -611,7 +611,6 @@ def triangle(x1, y1, x2, y2, x3, y3, **kwargs):
611611 glVertex2f (x1 , y1 )
612612 glVertex2f (x2 , y2 )
613613 glVertex2f (x3 , y3 )
614- #glVertex2f(x, y+height)
615614 glEnd ()
616615
617616_ellipses = {}
@@ -1361,6 +1360,7 @@ def directed(points):
13611360 pt0 = points .point (0.999 )
13621361 angle = geometry .angle (pt0 .x , pt0 .y , pt .x , pt .y )
13631362 elif i == n - 1 and isinstance (pt , bezier .DynamicPathElement ) and pt .ctrl1 .x != pt .x or pt .ctrl1 .y != pt .y :
1363+ # For the last point in BezierPath.points(), use incoming handle (ctrl1) for curves.
13641364 angle = geometry .angle (pt .ctrl1 .x , pt .ctrl1 .y , pt .x , pt .y )
13651365 elif 0 < i :
13661366 # For any point, look back gives a good result, if enough points are given.
@@ -3472,15 +3472,15 @@ def __init__(self, width=640, height=480, name="NodeBox for OpenGL", resizable=F
34723472 height = height ,
34733473 resizable = resizable ,
34743474 style = border is False and WINDOW_BORDERLESS or WINDOW_DEFAULT ,
3475- config = _configure (settings ),
3475+ config = _configure (settings ),
34763476 vsync = vsync
34773477 )
34783478 Prototype .__init__ (self )
34793479 EventHandler .__init__ (self )
34803480 self .profiler = Profiler (self )
34813481 self ._window = pyglet .window .Window (** window )
34823482 self ._fps = None # Frames per second.
3483- self ._frame = 0 # The current frame.
3483+ self ._frame = 60 # The current frame.
34843484 self ._elapsed = 0 # dt = time elapsed since last frame.
34853485 self ._active = False # Application is running?
34863486 self .paused = False # Pause animation?
@@ -3766,17 +3766,17 @@ def _on_resize(self, width, height):
37663766 self .on_resize ()
37673767
37683768 # Event methods are meant to be overridden or patched with Prototype.set_method().
3769- def on_key_press (self , key ):
3769+ def on_key_press (self , keys ):
37703770 """ The default behavior of the canvas:
37713771 - ESC exits the application,
37723772 - CTRL-P pauses the animation,
37733773 - CTRL-S saves a screenshot.
37743774 """
3775- if key .code == ESCAPE :
3775+ if keys .code == ESCAPE :
37763776 self .stop ()
3777- if key .code == "p" and CTRL in key .modifiers :
3777+ if keys .code == "p" and CTRL in keys .modifiers :
37783778 self .paused = not self .paused
3779- if key .code == "s" and CTRL in key .modifiers :
3779+ if keys .code == "s" and CTRL in keys .modifiers :
37803780 self .save ("nodebox-%s.png" % str (datetime .now ()).split ("." )[0 ].replace (" " ,"-" ).replace (":" ,"-" ))
37813781
37823782 def on_move (self ):
@@ -3832,9 +3832,9 @@ def _draw(self, lapse=0):
38323832 """ Draws the canvas and its layers.
38333833 This method gives the same result each time it gets drawn; only _update() advances state.
38343834 """
3835- self ._frame += 1
38363835 if self .paused :
38373836 return
3837+ self ._window .switch_to ()
38383838 glPushMatrix ()
38393839 self .draw ()
38403840 glPopMatrix ()
@@ -3856,6 +3856,7 @@ def _update(self, lapse=0):
38563856 # This is only done when the canvas is not paused.
38573857 # Events will still be propagated during pause.
38583858 global TIME ; TIME = time ()
3859+ self ._frame += 1
38593860 self .update ()
38603861 for layer in self :
38613862 layer ._update ()
@@ -3904,6 +3905,7 @@ def run(self, draw=None, setup=None, update=None, stop=None):
39043905 self .set_method (update , name = "update" )
39053906 if isinstance (stop , FunctionType ):
39063907 self .set_method (stop , name = "stop" )
3908+ self ._frame += 1
39073909 self ._setup ()
39083910 self .fps = self ._fps # Schedule the _update and _draw events.
39093911 pyglet .app .run ()
@@ -3928,7 +3930,7 @@ def _set_fps(self, v):
39283930 pyglet .clock .schedule_interval (f , 1.0 / v )
39293931 self ._fps = v
39303932
3931- fps = property (_get_fps , _set_fps )
3933+ fps = property (_get_fps , _set_fps )
39323934
39333935 #--- Frame export -----------------------------------
39343936
@@ -4059,30 +4061,3 @@ def ximport(library):
40594061# Linear interpolation math for BezierPath.point() etc.
40604062
40614063import bezier
4062-
4063- #-----------------------------------------------------------------------------------------------------
4064- # Expose the canvas and some common canvas properties on global level.
4065- # Some magic constants from NodeBox are commands here:
4066- # - WIDTH => width()
4067- # - HEIGHT => height()
4068- # - FRAME => frame()
4069-
4070- canvas = Canvas ()
4071-
4072- def size (width = None , height = None ):
4073- if width is not None :
4074- canvas .width = width
4075- if height is not None :
4076- canvas .height = height
4077- return canvas .size
4078-
4079- def speed (fps = None ):
4080- if fps is not None :
4081- canvas .fps = fps
4082- return canvas .fps
4083-
4084- def frame ():
4085- return canvas .frame
4086-
4087- def clear ():
4088- canvas .clear ()
0 commit comments