Importing a "Java Processing" library into py5

Found out how to convert Python’s int values greater than MAX_INT to Java’s 32-bit signed int using “jpype”'s JInt() function:

import py5

from jpype import JInt
from peasy import PeasyCam

BG = JInt(0xff_C8_00_32) # medium-dark pink-red
FG = JInt(0xff_FF_FF_00) # yellow

ROT_STEP = .05 # rotation speed
FILENAME = 'cube_####.png'

this = py5._instance

def settings(): this.size(400, 400, this.P3D)

def setup():
    this.fill(FG)
    this.strokeWeight(2)

    PeasyCam(this, 500)


def draw():
    this.background(BG)
    this.rotateY(this.frameCount * ROT_STEP)
    this.box(50)


def key_pressed():
    this.key == ' ' and this.saveFrame(this.dataPath(FILENAME))


__name__ == '__main__' and py5.run_sketch()

Now we can pass big values like 0xff_C8_00_32 or 0xff_FF_FF_00 to Java methods in Processing, such as fill() and background() via py5._instance. :star_struck:

2 Likes