Skip to content

imclab/processing.py

 
 

Repository files navigation

processing.py

Write Processing sketches in Python.

Tested on Mac OS 10.8.3, Windows XP and Ubuntu 12.10.

Quick Start

Download Processing.py 0200

Then, paste this code into a file, e.g., mysketch.py.

def setup():
    size(600, 400)

def draw():
    ellipse(mouseX, mouseY, 10, 10)

Eventually, you can run the code by drag-dropping your sketch onto one of these files according to your platform:

If that does not work for one of your platforms (such as Linux), you can run the sketch either semi-manually (with automated JRE detection) ...

$ ./processing-py.sh mysketch.py

... or fully by hand.

$ java -jar processing-py.jar mysketch.py

Documentation

To learn Processing.py check out these resources:

In addition, we are a great fan of learning by doing, and a number of converted examples outline how to use Processing.py:

$ processing-py.sh examples.py/Basics/Math/noisefield.py
$ processing-py.sh examples.py/Library/OpenGL/SpaceJunk.py
$ processing-py.sh examples.py/3D/Typography/KineticType.py
$ processing-py.sh examples.py/3D/Textures/TextureCube.py

As always, on Windows use processing-py.bat instead, on Mac the processing-py app, or simply drag-drop the example on the launcher / batch.

FAQ

  • Can I use all of the existing Processing libraries?

Yes! Processing.py is implemented in Java, and is meant to be compatible with the whole existing ecosystem of Processing libraries.

* Put processing extension libraries in the `libraries` subdirectory of your processing.py installation.

* Import them in on of the usual Python ways, as in these snippets:


        from peasy import PeasyCam # or
        import peasy.PeasyCam      # or
        import peasy.PeasyCam as PeasyCam

    Unfortunately, `from foo import *` is not supported.

* In your `setup()` method

        cam = PeasyCam(this, 200)


    Use `this` to refer to the PApplet you're in, as in the examples above.
    Many libraries need a reference to "the current PApplet", and that's what
    `this` is for.
  • How can I create a wrapper?

    Add these lines near the top of your script:

    import launcher
    launcher.create()
    
  • How should I load data?

    [Tentative] Along with the launcher, consider using pwd() for file paths. For a given argument it resolves the path for an object relative to the currently running script:

    data = load(pwd("data.txt"))
    

    In that case, processing.py will try to search data.txt always where your script resides.

  • How can I use Ani, or any other library that modifies fields?

    Some libraries such as Ani require you to specify a variable name for animation. Unfortunately they cannot access Python variables directly (and Java's built in classes are immutable).

    To solve this problem we instead create a mutable PrimitiveFloat object. This object has a field .value, which you can use for these purposes.

    import jycessing.primitives.PrimitiveFloat as Float
    x = Float(100.0)
    Ani.to(x, 200, "value", 50);  # "value" is the name of the Float's internal field
    

    In case you need other primitive values, please let us know!

  • I found a bug, what should I do?

    Please report any issue in the bug tracker.

  • Why was this project created?

    I (Jonathan) recently gave a talk about Processing to a group of rather bright 8th-graders, as part of a computer-programming summer camp they were attending at my office. Their curriculum up to that point had been in Python, which is an eminently sensible choice, given the pedagogical roots of the language.

    The kids were really turned on by the demos--I showed them the white glove, and Golan Levin's New Year's cards--but they were bogged down by Processing's C-like syntax, which really seems arcane and unnecessarily complex when you're used to Python.

    I shared my experience with Processing creators Ben Fry and Casey Reas, and they told me that, indeed, the original Processing was a fork of "Design By Numbers", with Python and Scheme support hacked in. Support for a multi-lingual programming environment was always part of the plan, so they were enthusiastic about any new attempt at the problem.

    I was able to hack up a proof of concept in a couple of hours, and have managed to create something worth sharing in a couple of weeks. I was only able to do it at all thanks to the brilliant and beautiful Jython project.

    At the time of Processing's first public release, August of 2001, Jython was too young a project to be used in this way. But now, having done absolutely no work to profile and optimize, I can get hundreds of frames per second of 3D graphics on my linux box. So, kudos to the Processing project, and kudos to Jython!

Credits

Written by Jonathan Feinberg <jdf@pobox.com> Launcher & many improvements by Ralf Biedert <rb@xr.io>

Also, YourKit, LLC was so kind to sponsor a license for their excellent YourKit Java Profiler. Thank you very much!