Mittwoch, 10. Oktober 2012

Using Processing.js with Amber

"The Processing language was originally created at MIT as part of the Media lab and Aesthetics and Computation group. They needed a way to bridge the gap between software developers, artists, data visualizers, etc., and to do so in a way that allowed new programmers (or non-programmers) to do complex visual work easily. Processing was built using Java, and can be thought of as a simplified Java, with a simplified Java API for drawing and graphics." (source)

Since it is possible to write Processing code with pure JavaScript, it should be possible to use Amber with Processing.
And so it is - with some little tricks.
First, Processing should get initialized in the html page like this

A Processing instance will be created, it can get accessed via Amber in this way:

processing := <Processing.instances[0]>.

After fetching this instance, it can be used like any other Smalltalk Object:

processing background: 224.

processing line: centerX y: centerY dX: myDX dY: myDY.

I converted the clock-example to Amber, you can find it in the Example-section of my Amber Git repo. And maybe soon in the "official" Amber-Examples.

You can try it out here.

2 Kommentare:

NicolasPetton hat gesagt…


Instead of
processing := .

can you do:
processing := Processing instances first.


NicolasPetton hat gesagt…

Ok, I gave it a try, and the Processing object is actually a function, so you can't do what I just said.

Instead, you can use #basicAt: to access the instances:

(Processing basicAt: 'instances') first