from javax.swing import JFrame from processing.core import * """ HOW TO: ======= prereqs ------- - install the jdk - install jython, I'm using [2.2.1](http://downloads.sourceforge.net/jython/jython_installer-2.2.1.jar) set up path and classpath (on Windows XP) ----------------------------------------- - start -> right click "My Computer" -> properties -> advanced -> environment variables - add to your path `C:\Program Files\Java\jdk1.6.0_12\bin;C:\Program Files\jython` - add to system classpath: `.;C:\Program Files\processing-1.0.3\lib\core.jar;C:\Program Files\jython\jython.jar` - check the version numbers match the jdk ---------------------------------------------------------------------------- run --- when this file is saved as p5thon.py, you can run it by calling "jython p5thon.py" ---------------------------------------------------------------------------- compile ------- to make a .jar: `jythonc -i --core --jar p5thon.jar --compiler javac p5thon.py` then copy p5's core.jar into directory ( Jythonc docs are at http://www.jython.org/Project/jythonc.html ) applet's html: ` ` ---------------------------------------------------------------------------- """ height = 400 width = 400 # make a class that has PApplet as a BaseClass class App(PApplet): def __init__(self): pass def setup(self): self.size(width, height) self.colorMode(self.RGB, 255, 255, 255, 100) self.rectMode(self.CENTER) # things from p5 need "self." we'll be writing it a lot! def draw(self): self.background(0xd6dde9) self.fill(48,80) self.rect(self.mouseX, height/2, self.mouseY/2+10, self.mouseY/2+10) self.fill(48,80) inverseX = width-self.mouseX inverseY = height-self.mouseY self.rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10) # This is how p5 is started up and a window (frame) created. def run(): frame = JFrame( title='P5thon', resizable=0, # can be 1 but we need to use self.width and self.height instead of globals defaultCloseOperation=JFrame.EXIT_ON_CLOSE) thePanel = App() frame.add(thePanel) thePanel.init() frame.pack() frame.visible = 1 return thePanel # Normal python bit: if __name__ == '__main__': run()