Skip to content

Commit

Permalink
basic user defined draw() and setup()
Browse files Browse the repository at this point in the history
  • Loading branch information
abhikpal committed Jun 22, 2017
1 parent 0915ab7 commit e776861
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion p5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from . import sketch
from .sketch import *
from .core import *
from .pmath import *
14 changes: 3 additions & 11 deletions p5/sketch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

#
# This should only have the relevant sketch constants.
# __all__ = []
#
# HEIGHT WIDTH FOCUSED FRAMECOUNT FRAMERATE PIXEL_HEIGHT PIXEL_WIDTH
# MOUSE_BUTTON MOUSE_PRESSED MOUSE_X MOUSE_Y PMOUSE_X PMOUSE_Y KEY
# KEYCODE KEY_PRESSED
#


from .base import initialize, run, artist, test_run
from .base import run, artist, test_run
from .events import *

__all__ = ['run']
23 changes: 16 additions & 7 deletions p5/sketch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,27 @@ def initialize(*args, **kwargs):
renderer.initialize(width, height, gl_version)
window.set_visible()

def run(*args, **kwargs):
def _default_draw():
renderer.clear()

def _default_setup():
pass

def run(draw=_default_draw, setup=_default_setup):
# set up required handlers depending on how the sketch is being
# run (i.e., are we running from a standalone script, or are we
# running inside the REPL?)

def update(dt):
renderer.pre_render()
draw()
renderer.post_render()

initialize()
setup()
pyglet.clock.schedule(update)
pyglet.app.run()

def artist(f):
# a decorator that will wrap around the the "artists" in the
# sketch -- these are functions that draw stuff on the screen like
Expand All @@ -74,8 +88,3 @@ def tester(dt):
renderer.post_render()
pyglet.clock.schedule(tester)
pyglet.app.run()

def update(dt):
renderer.pre_render()
renderer.post_render()

0 comments on commit e776861

Please sign in to comment.