I attended the Processing for Android Workshop by Andrés Colubri on March 28, 2018, at Fathom Information Design. Here are the notes I took on the setup and (some) of the samples or recommendations Andrés walked us through!
To develop for Android, you first need to choose the "Android mode."
If you don't have it installed yet, you need to choose "Add Mode.." and then install it. The download process can either be manual or automatically downloaded by Processing (which will prompt you to accept the license agreement of Android before you can start developing).
When you are all set, you can start developing.
You can directly start running your Processing sketches on Android devices but you will need to download and install a phone "image" to be able to use an Android phone emulator on your computer. (This will be the only way to go if you don't own an Android device.) The emulator installs the Intel HAXM, Hardware Accelerated Execution Manager, without which "Processing would be extremely slow To the point of being unusable," Andrés' words.
pixelDensity
In Android mode
you can use the pixelDensity
variable in Processing to have consistent sizes across different device displays. (This is equivalent to the pixelDensity()
function call in Java mode
.)
float angle = 0;
void setup() {
// Setup the OpenGL renderer (P3D)
fullScreen(P3D);
pixelDensity(displayDensity());
}
void draw() {
// Set the color of the background
background(#506983);
// Move our location to the center of the screen
translate(width/2, height/2);
// Rotate the location
rotateY(angle);
// Make a box
box(200);
angle += 0.01;
}
For virtual reality, we need to use the STEREO
renderer instead of the P3D
renderer, and we need to import the VR
library by going to Sketch > "Import Library.." > VR.
One trick is that on the simulator you can click the three small dots in the vertical menu and access "Virtual sensors" to emulate a physical phone moving.
float x = 200;
float y = 150;
float sx = screenX(x, y, 0);
float sy = screenY(x, y, 0);
We can draw things relative to your virtual eyes.
void drawAim() {
pushMatrix();
eye();
stroke(255,0,0);
strokeWeight(50);
point(0, 0, 100);
popMatrix();
}
Hardware compatible with Android software to—on top of assembling apps—assemble devices. These can be programmed with Android and (also) Processing for Android.
Processing for Android is a great environment to introduce non-programmers not only to app development but also to device programming, such as Blackberry PI or Arduino.