Processing for Android

Home screens

When your device have several home screens, two variables in Processing tell you how to adjust the graphics in the sketch depending on which is the current screen: homeScreenCount and homeScreenOffset. homeScreenCount holds the number of home screens (it can change while the wallpaper is running as the users adds or removes home screens). homeScreenOffset is a float number between 0 and 1 that that measures the horizontal displacement along the screens: 0 at the leftmost location, and 1 when we are located at the rightmost homescreen. This post on stackoverflow explains in more detail how the x offset works.

PImage img;
float ratio;

void setup() {
  img = loadImage("landscape.jpg");
  ratio = float(img.width)/float(img.height);

void draw() {
  float w = homeScreenCount * width;
  float h = w/ratio;
  float x = map(homeScreenOffset, 0, 1, 0, -(homeScreenCount-1) * width);
  image(img, x, 0, w, h);