Nono.MA

Notes on Processing for Android

MARCH 28, 2018

Notes on Processing for Android

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!

Hello, Processing for Android!

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.

Using 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.)

A Simple OpenGL 3D Application

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;
}

Processing for Android OpenGL 3D Box

A Sample VR Application

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.

Processing for Android Phone Emulator Virtual Sensors

Getting the Position of a 3D Vertex in VR on the Screen

float x = 200;
float y = 150;
float sx = screenX(x, y, 0);
float sy = screenY(x, y, 0);

Drawing from the Perspective of Your "Eyes"

We can draw things relative to your virtual eyes.

void drawAim() {
  pushMatrix();
  eye();
  stroke(255,0,0);
  strokeWeight(50);
  point(0, 0, 100);
  popMatrix();
}

Android Things

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.


Android things · NXP Pico microchip with Processing and external display

Recommended books

  • Processing for Android Create Mobile, Sensor-Aware, and VR Applications Using Processing by Andrés Colubri. See it on Amazon.
  • Rapid Android Development: Build Rich, Sensor-Based Applications with Processing by Daniel Sauter. See it on Amazon.

References

  • Tilt Brush by Google.
  • Android Things by Google. "Build connected devices for a wide variety of consumer, retail, and industrial applications."
  • Source code for Processing for Android by Andrés Colubri. See it on Github.