Skip to content

Commit 2dde5a7

Browse files
author
Tom De Smedt
committed
Live coding example in examples/12-experimental/
1 parent feb5c08 commit 2dde5a7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
4+
from nodebox.graphics import *
5+
6+
# Live coding example.
7+
# The actual drawing code is in 04-live2.py.
8+
# This script starts the canvas and executes the commands from 04-live2.py.
9+
# You can then edit and save the code there, changes will be reflected automatically.
10+
11+
SCRIPT = "04-live2.py"
12+
source = open(SCRIPT).read()
13+
modified = os.path.getmtime(SCRIPT)
14+
15+
def draw(canvas):
16+
global source
17+
global modified
18+
exec(source)
19+
if os.path.getmtime(SCRIPT) > modified:
20+
source = open(SCRIPT).read()
21+
modified = os.path.getmtime(SCRIPT)
22+
23+
canvas.size = 500, 500
24+
canvas.fps = 30
25+
canvas.run(draw)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# See 04-live1.py.
2+
# The commands below are read and executed in a canvas there.
3+
# If you edit and save this file, changes are automatically reflected.
4+
5+
#canvas.clear()
6+
for i in range(10):
7+
x = random(canvas.width)
8+
y = random(canvas.height)
9+
r = random(20) + 50
10+
fill(random(), 0.0, random(0.25), random(0.25))
11+
stroke(0, 0.2)
12+
ellipse(x, y, r, r)

0 commit comments

Comments
 (0)