Skip to content

Commit 2a380c7

Browse files
committed
Call draw every frame
1 parent f9a981f commit 2a380c7

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from processing import *
22

3-
# TODO: this should be in a setup function
4-
size(800, 600)
3+
def setup():
4+
size(800, 600)
55

66
def draw():
77
background(220)
@@ -12,4 +12,4 @@ def draw():
1212
rect(100, 100, 200, 150)
1313

1414
# TODO: this should happen implicitly on module load somehow
15-
run(draw)
15+
run()

crates/processing_pyo3/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,30 @@ fn run(module: &Bound<'_, PyModule>) -> PyResult<()> {
4343
Python::attach(|py| {
4444
let builtins = PyModule::import(py, "builtins")?;
4545
let locals = builtins.getattr("locals")?.call0()?;
46+
4647
let setup_fn = locals.get_item("setup")?;
48+
let draw_fn = locals.get_item("draw")?;
49+
50+
// call setup
4751
setup_fn.call0()?;
4852

53+
// start draw loop
54+
loop {
55+
{
56+
let mut graphics = get_graphics_mut(module)?;
57+
if !graphics.surface.poll_events() {
58+
break;
59+
}
60+
graphics.begin_draw()?;
61+
}
62+
63+
draw_fn
64+
.call0()
65+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
66+
67+
get_graphics(module)?.end_draw()?;
68+
}
69+
4970
Ok(())
5071
})
5172
}

rectangle.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)