Skip to content

Commit

Permalink
Merge pull request #25 from ralfbiedert/master
Browse files Browse the repository at this point in the history
Jython 2.7, fullscreen, launcher & more
  • Loading branch information
Jonathan Feinberg committed Apr 1, 2013
2 parents bf58232 + 45f6409 commit 6de2184
Show file tree
Hide file tree
Showing 50 changed files with 4,045 additions and 139 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -17,3 +17,8 @@ zamples
libraries/GSVideo
test.py
*/.DS_Store
.DS_Store
runtime/src/.DS_Store
__pycache__
dist.platforms
JREs/jre7.*
8 changes: 8 additions & 0 deletions JREs/README.txt
@@ -0,0 +1,8 @@


If you put Oracle's JRE here as

jre7.mac
jre7.win

it will be used instead of your system's version.
251 changes: 135 additions & 116 deletions README.markdown
@@ -1,147 +1,166 @@
# processing.py #

Write [Processing](http://processing.org) sketches in Python.
[Jonathan Feinberg](http://mrfeinberg.com) <[jdf@pobox.com](mailto:jdf@pobox.com)>
Write Processing sketches in Python.

* Based on [Processing 2.0](http://processing.org/), runtime compatible with most [3rd party libraries](http://www.processing.org/reference/libraries/).
* Source compatible with [Python 2.7.3](http://python.org).

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

## Found a bug? ##

See the [open bugs in the bug tracker](http://github.com/jdf/processing.py/issues).

## Quick Start ##

Download the processing.py distribution.
Download __[Processing.py All-inclusive](http://s.xr.io/processing.py/latest.zip)__ (Windows & Mac, ~170mb).

$ curl -L https://github.com/downloads/jdf/processing.py/processing.py-0021.tgz | tar zx
$ cd processing.py-0021
Download [Processing.py without JRE](http://s.xr.io/processing.py/latest.nojre.zip) (Windows, Mac & Linux, ~70mb.).

Then try some examples.

$ java -jar processing-py.jar examples.py/Basics/Math/noisefield.py
$ java -jar processing-py.jar examples.py/3D/Typography/KineticType.py
$ java -jar processing-py.jar examples.py/Library/OpenGL/SpaceJunk.py
$ java -jar processing-py.jar examples.py/3D/Textures/TextureCube.py
$ cat > mysketch.py
def draw():
background(0)
text(frameRate, 20, 20)
$ java -jar processing-py.jar mysketch.py
Then, paste this code into a file, e.g., `mysketch.py`.

## What is this? ##
def setup():
size(600, 400, P3D)

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

processing.py is a system that lets you write programs in a dialect
of Python that has [all of these keywords](http://processing.org/reference/).

In general, the way you run a processing.py program is to say
Eventually, you can run the code by drag-dropping your sketch onto one of these files according to your platform:

$ java -jar processing-py.jar path/to/your_sketch.py
<img src="http://s.xr.io/processing.py/howtolaunch.jpg"/>

## Can I use all of the existing [Processing libraries](http://processing.org/reference/libraries/)? ##
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

Yes! processing.py is implemented in Java, and is meant to be compatible
with the whole existing ecosystem of
[Processing libraries](http://processing.org/reference/libraries/).
... or fully by hand.

Put processing extension libraries in the "libraries" subdirectory of
your processing.py installation.
$ java -jar processing-py.jar mysketch.py

$ curl -O http://mrfeinberg.com/peasycam/peasycam.zip
$ cd libraries
$ unzip ../peasycam.zip

Import them in the usual Python way, as in these snippets:

import peasy.PeasyCam
## Documentation ##

or
To learn Processing.py check out these resources:

import peasy.PeasyCam as PeasyCam

or
* Built-in [Processing 2.0 functions](http://processing.org/reference/) for rendering and interaction.
* The [Python 2.7.3 library](http://docs.python.org/2/index.html).
* And of course the [Java 6.x / 7.x library](http://docs.oracle.com/javase/6/docs/api/).

from peasy import PeasyCam

and then, in your `setup()` method
In addition, we are a great fan of learning by doing, and a number of converted examples outline how to use Processing.py:

cam = PeasyCam(this, 200)
$ 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.

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

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.
* __Can I use all of the existing Processing libraries?__

Put any Python libraries in the "libraries" directory, or in sketch directories.
Only pure-Python libraries will work--nothing that requires "native" code.

## Example Code ##
Yes! Processing.py is implemented in Java, and is meant to be compatible with the whole existing ecosystem of [Processing libraries](http://processing.org/reference/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](http://www.looksgood.de/libraries/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](http://github.com/jdf/processing.py/issues)!

* __I found a bug, what should I do?__

Please report any issue in the [bug tracker](http://github.com/jdf/processing.py/issues).


* __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](http://en.wikipedia.org/wiki/ABC_%28programming_language%29)
of the language.

The kids were really turned on by the demos--I showed them the
[white glove](http://whiteglovetracking.com/), and
[Golan Levin](http://flong.com/)'s
[New Year's cards](http://www.flong.com/storage/experience/newyear/newyear10/)--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](http://benfry.com/) and [Casey Reas](http://reas.com/), and they
told me that, indeed, the original Processing was a fork of
["Design By Numbers"](http://dbn.media.mit.edu/), 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](http://www.jython.org/) 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](http://mrfeinberg.com) &lt;[jdf@pobox.com](mailto:jdf@pobox.com)&gt;
Launcher & adjustments [Ralf Biedert](http://xr.io) &lt;[rb@xr.io](mailto:rb@xr.io)&gt;

Also, [YourKit, LLC](http://www.yourkit.com) was so kind to sponsor a license for their excellent [YourKit Java Profiler](http://www.yourkit.com/java/profiler/index.jsp). Thank you very much!

"""
noisefield.py - demonstrate Perlin noise
Jonathan Feinberg
"""
srcSize = 50
destSize = 400
g = createGraphics(srcSize, srcSize, JAVA2D)

def setup():
size(destSize, destSize, OPENGL)

def draw():
t = .0005 * millis()
g.beginDraw()
for y in range(srcSize):
for x in range(srcSize):
blue = noise(t + .1*x, t + .05*y, .2*t)
g.set(x, y, color(0, 0, 255 * blue))
g.endDraw()
image(g, 0, 0, destSize, destSize)

## Why? ##

I 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](http://en.wikipedia.org/wiki/ABC_%28programming_language%29)
of the language.

The kids were really turned on by the demos--I showed them the
[white glove](http://whiteglovetracking.com/), and
[Golan Levin](http://flong.com/)'s
[New Year's cards](http://www.flong.com/storage/experience/newyear/newyear10/)--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](http://benfry.com/) and [Casey Reas](http://reas.com/), and they
told me that, indeed, the original Processing was a fork of
["Design By Numbers"](http://dbn.media.mit.edu/), 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](http://www.jython.org/) 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!

Please play with this,
[report bugs](http://github.com/jdf/processing.py/issues),
and port more of the Processing examples!

## A word from a sponsor ##

YourKit has kindly granted me a license to use their excellent Java profiler.
I'm happy to give them the space to say:

> YourKit is kindly supporting open source projects with its full-featured Java Profiler.
> YourKit, LLC is the creator of innovative and intelligent tools for profiling
> Java and .NET applications. Take a look at YourKit's leading software products:
> [YourKit Java Profiler](http://www.yourkit.com/java/profiler/index.jsp) and
> [YourKit .NET Profiler](http://www.yourkit.com/.net/profiler/index.jsp).

0 comments on commit 6de2184

Please sign in to comment.