File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ # Add the upper directory (where the nodebox module is) to the search path.
2+ import os , sys ; sys .path .insert (0 , os .path .join (".." , ".." ))
3+ import warnings
4+
5+ from nodebox .graphics import *
6+
7+ # Live coding example.
8+ # The actual drawing code is in 04-live2.py.
9+ # This script starts the canvas and executes the commands from 04-live2.py.
10+ # You can then edit and save the code there,
11+ # changes will be reflected automatically while the canvas keeps running.
12+
13+ SCRIPT = "04-live2.py"
14+ source = open (SCRIPT ).read ()
15+ modified = os .path .getmtime (SCRIPT )
16+
17+ def draw (canvas ):
18+ global source
19+ global modified
20+ try :
21+ exec (source )
22+ except Exception , e :
23+ warnings .warn (str (e ), Warning )
24+ if os .path .getmtime (SCRIPT ) > modified :
25+ source = open (SCRIPT ).read ()
26+ modified = os .path .getmtime (SCRIPT )
27+
28+ canvas .size = 500 , 500
29+ canvas .fps = 30
30+ canvas .run (draw )
Original file line number Diff line number Diff line change 1+ # Live coding example.
2+ # See 04-live1.py.
3+ # The commands below are read and executed in a canvas there.
4+ # If you edit and save this file, changes are automatically reflected,
5+ # while the canvas started in 04-live1.py keeps on running.
6+
7+ #canvas.clear()
8+ for i in range (10 ):
9+ x = random (canvas .width )
10+ y = random (canvas .height )
11+ r = random (20 ) + 50
12+ fill (random (), 0.0 , random (0.25 ), random (0.25 ))
13+ stroke (0 , 0.2 )
14+ ellipse (x , y , random , r )
You can’t perform that action at this time.
0 commit comments