Skip to content

Commit 62d0b62

Browse files
committed
update processing mode code with comments
1 parent f194452 commit 62d0b62

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

processing-mode/example1/example1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def alter_image(msg: str, img: py5.Py5Image):
1515
return img
1616

1717

18+
# register processing mode keys so the Java `callPython()` method can find them
1819
py5_tools.register_processing_mode_key('test_transfer', alter_image)
1920
py5_tools.register_processing_mode_key('np', np)
2021

22+
# run the sketch in processing mode, specifying the Java class to instantiate
2123
py5.run_sketch(jclassname='test.Example1Sketch')

processing-mode/example1/java/src/main/java/test/Example1Sketch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public void settings() {
1010
}
1111

1212
public void setup() {
13-
rectMode(CENTER);
14-
1513
String msg = "Hello from Java!";
1614
PImage img = createImage(200, 200, RGB);
1715

16+
// call Python function `alter_image(msg, img)` and get back a PImage
1817
PImage imgResponse = (PImage) callPython("test_transfer", msg, img);
1918
image(imgResponse, 100, 100);
2019

20+
// call numpy `random.randint()` function
2121
long randomNumber = (long) callPython("np.random.randint", 0, 100);
2222
py5Println("JAVA: Random number from numpy: " + randomNumber);
2323
}

processing-mode/example2/example2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def passImage(self, message, pimage):
3838
return JClass('java.lang.RuntimeException')(str(e))
3939

4040

41+
# register processing mode keys so the Java `callPython()` method can find them
4142
py5_tools.register_processing_mode_key('setup_test_interface', lambda: Test())
4243

44+
# run the sketch in processing mode, specifying the Java class to instantiate
4345
py5.run_sketch(jclassname='test.Example2Sketch')

processing-mode/example2/java/src/main/java/test/Example2Sketch.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ public void settings() {
1212
}
1313

1414
public void setup() {
15-
rectMode(CENTER);
16-
15+
// call Python to obtain a Python object that implements the Java
16+
// Interface `TestInterface`
1717
test = (TestInterface) callPython("setup_test_interface");
1818

1919
String message = "Hello from Java!";
2020
PImage pimage = createImage(150, 150, RGB);
21+
22+
// make calls to Python through the Java interface `TestInterface`
2123
PImage imageResponse = test.passImage(message, pimage);
24+
2225
if (imageResponse != null) {
2326
image(imageResponse, 100, 100);
2427
}
25-
2628
}
2729

2830
public void draw() {

0 commit comments

Comments
 (0)