Last active
December 18, 2015 10:49
-
-
Save max-giro/5771320 to your computer and use it in GitHub Desktop.
[Fixed code for multitouch Processing on Android example at http://www.akeric.com/blog/?p=1411]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.akeric.com/blog/?p=1411 | |
// Eric Pavey - AkEric.com - 2010-12-29 | |
// Example showing simple multi-touch detection in 'Processing - Android'. | |
// My Samsung Captivate (Galaxy S) can track 5 touch-points. | |
// Updated to work with Processing's surfaceTouchEvent instead of | |
// Android's dispatchTouchEvent. | |
// Should point out that API Level 9 has MotionEvent.PointerCoords class that | |
// expose some cool functionality, but I'm only on Level 7. | |
import android.view.MotionEvent; | |
String[] fontList; | |
PFont androidFont; | |
int circleBaseSize = 512; // change this to make the touche circles bigger\smaller. | |
void setup() { | |
size(displayWidth, displayHeight); | |
// Fix the orientation so the sketch won't reset when rotated. | |
orientation(PORTRAIT); | |
stroke(255); | |
smooth(); | |
// Setup Fonts: | |
fontList = PFont.list(); | |
androidFont = createFont(fontList[0], 16, true); | |
textFont(androidFont); | |
textAlign(LEFT); | |
} | |
void draw() { | |
background(0); | |
} | |
void infoCircle(float x, float y, float siz, int id) { | |
// What is drawn on sceen when touched. | |
float diameter = circleBaseSize * siz; | |
noFill(); | |
ellipse(x, y, diameter, diameter); | |
fill(0, 255, 0); | |
ellipse(x, y, 8, 8); | |
text( ("ID:"+ id + " " + int(x) + ", " + int(y) ), x-128, y-64); | |
} | |
//----------------------------------------------------------------------------------------- | |
// Override Processing's surfaceTouchEvent, which will intercept all | |
// screen touch events. This code only runs when the screen is touched. | |
public boolean surfaceTouchEvent(MotionEvent me) { | |
// Number of places on the screen being touched: | |
int numPointers = me.getPointerCount(); | |
for (int i=0; i < numPointers; i++) { | |
int pointerId = me.getPointerId(i); | |
float x = me.getX(i); | |
float y = me.getY(i); | |
// Added the .5 to make the outer ellipse noticeable | |
float siz = me.getSize(i) + .5; | |
infoCircle(x, y, siz, pointerId); | |
} | |
// If you want the variables for motionX/motionY, mouseX/mouseY etc. | |
// to work properly, you'll need to call super.surfaceTouchEvent(). | |
return super.surfaceTouchEvent(me); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment