Touch event
Processing.js, a partir de la versión de v1.1 soporta webkit touch events.
Se han añadido lo siguientes eventos:
- void touchStart(TouchEvent touchEvent);
- void touchMove(TouchEvent touchEvent);
- void touchEnd(TouchEvent touchEvent);
- void touchCancel(TouchEvent touchEvent);
Las coordenadas de los puntos se accede con el array de puntos touchEvent.touches array. y los atributos offsetX y offsetY que representan la posición relativa a la página.
void setup() {
size(400, 300);
background(255);
}
void touchMove(TouchEvent touchEvent) {
noStroke();
fill(255);
rect(0, 0, 400, 300);
// dibuja círculos en el punto donde tocas
fill(180, 180, 100);
for (int i = 0; i < touchEvent.touches.length; i++) {
int x = touchEvent.touches[i].offsetX;
int y = touchEvent.touches[i].offsetY;
ellipse(x, y, 50, 50);
}
}
void touchEnd(TouchEvent touchEvent) {
noStroke();
fill(255);
rect(1, 1, 400, 300);
}