Processing – Android mode examples

Line

In this example you will draw a simple line on your Android phone display.

  1. First of all you have to enable USB debugging on your Android phone. The settings look different in different phones but you should be able to turn USB debugging on if you go to Settings > Developer options > Debugging > USB debugging, or something similar.

  2. Connect the phone to your Computer. Make sure your phone says “USB debugging connected.”

  3. Open Processing in android mode and write the following code: line

  4. size(displayWidth, displayHeight);
    line(0, 0, displayWidth, displayHeight);
    
  5. Click run icon and the program will now be executed on your phone.

New Commands

  • displayWidth: Returns the width of the display you are using.
  • displayHeight: Returns the height of the display you are using.

The sketch is saved on your phone so you can open it again.

Red Snake

In this example you will run the Red Snake program on your Android phone.

  1. Open Red Snake step 6
    
    
  2. Change the size to size(displayWidth, displayHeight)
  3. Run the code

As you can see you can still use mouseX and mouseY. Instead of returning the mouse coordinates they will return the coordinates of your finger on the display.

Note: Instead of running the programs on your phone you can run them on the emulator. In the processing IDE go to Sketch>Run in Emulator.

Find more information in english about the Processing Android mode here: https://github.com/processing/processing-android/wiki