Thanks, noel! The mouseReleased() did the trick. Just use a normal tap and the count increments by only 1 and eventually after enough taps resets to 0.
Here’s the basic code:
/*
3DScatter v1.1 - June 2012
Produce, in Processing, a 3D scatter graph from serial data
Copyright (c) 2011 Hon Bo Xuan <honboxuan at gmail dot com>
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import android.view.MotionEvent;
import java.util.ArrayList;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PVector;
import Jama.*;
import ketai.ui.*;
import static processing.core.PApplet.concat;
public class Scatter extends PApplet {
PFont font;
float[] q = new float[10];
int count = 0;
int Count = 0;
int[] vals;
PVector[] vecs = new PVector[100000];
int[] Vals;
PVector[] Vecs = new PVector[100000];
int x_max = 0, x_min = 0, y_max = 0, y_min = 0, z_max = 0, z_min = 0;
int x_total = 0, y_total = 0, z_total = 0;
int x_mean = 0, y_mean = 0, z_mean = 0;
int x_length = 0, y_length = 0, z_length = 0;
float length_mean = 0, x_gain = 1, y_gain = 1, z_gain = 1;
float zoom = 0.5f;
KetaiGesture gesture;
boolean tap;
float x;
float y;
public void setup() {
// frame.addMouseWheelListener(new MouseWheelInput());
vals = new int[3];
Vals = new int[3];
gesture = new KetaiGesture(this);
}
public void draw() {
findCentroid();
findGain();
background(0);
translate(width/2, height/2);
String Counts = "Count: " + count;
text(Counts, -width/2 + 20, height/2 -280);
///////////////// text(gain, -width/2 + 20, height/2 - 20); //Print before flipping Y (mag Z axis) and rotation
// String centre = x_mean + ", " + y_mean + ", " + z_mean;
String centre = vals[0] + ", " + vals[1] + ", " + vals[2];
////////////////// textFont(font, 20);
fill(255, 255, 255);// text(centre, 0.5 * x_mean + 20, -0.5 * z_mean, 0.5 * y_mean); //Print before flipping Y (mag Z axis)
text(centre, 0.5f * vals[0] + 20, -0.5f * vals[2], 0.5f * vals[1]); //Print before flipping Y (mag Z axis)
scale(zoom, -zoom, zoom); //Flip Y (mag Z axis)
noFill();
stroke(100);
strokeWeight(1);
////////////////////// box(1200);
stroke(0, 255, 255);
strokeWeight(8);
point(vals[0], vals[2], vals[1]); //Centroid
stroke(255, 0, 0);
strokeWeight(2);
line (300, 0, 0, 275, 0, 25); //Arrow head
line (300, 0, 0, 275, 0, -25);
line (320, -20, 0, 340, 20, 0); //Axis label
line (320, 20, 0, 340, -20, 0);
line(-300, 0, 0, 300, 0, 0); //Mag X Red
stroke(0, 0, 255);
strokeWeight(2);
line (0, 0, 300, 25, 0, 275); //Arrow head
line (0, 0, 300, -25, 0, 275);
line (0, 20, 320, 0, 0, 330); //Axis label
line (0, 0, 330, 0, 20, 340);
line (0, 0, 330, 0, -20, 330);
line(0, 0, -300, 0, 0, 300); //Mag Y Blue
stroke(0, 255, 0);
strokeWeight(2);
line (0, 300, 0, 25, 275, 0); //Arrow head
line (0, 300, 0, -25, 275, 0);
line (-10, 350, 0, 10, 350, 0); //Axis label
line (10, 350, 0, -10, 320, 0);
line (-10, 320, 0, 10, 320, 0);
line(0, -300, 0, 0, 300, 0); //Mag Z Green
vals[1] = Math.round(q[6]/2);
vals[0] = Math.round(q[7]/2);
vals[2] = Math.round(q[8]/2);
Vals[1] = Math.round(q[6]);
Vals[0] = Math.round(q[7]);
Vals[2] = Math.round(q[8]);
if(mousePressed) {
if (mouseX < width / 2 && mouseY < height / 3) { //1/3
}
}
if (count == 1){
// count = 0;
}
if (count == 2){
}
if (count == 3){
}
if (count == 4){
count = 0;
}
vecs[Count] = new PVector(vals[0], vals[2], vals[1]);
Vecs[Count] = new PVector(Vals[0], Vals[2], Vals[1]);
Count++;
for (int i = 0; i < Count; i++) {
PVector v = vecs[i];
stroke(255);
strokeWeight(3);
point(v.x, v.y, v.z);
PVector V = Vecs[i];
stroke(0, 255, 0);
strokeWeight(3);
point(V.x, V.y, V.z);
}
}
public void mousePressed () {
if(tap) {
tap = false;
println("tab");
// count++;
}
}
public void mouseReleased () {
tap = true;
count++;
}
void findCentroid() { //Fixed to find centroid, all points equally weighted
if( Count > 1) {
x_total += vals[0]; //With 10,000 sample limit, should not overflow
x_mean = x_total / Count;
y_total += vals[1];
y_mean = y_total / Count;
z_total += vals[2];
z_mean = z_total / Count;
}
}
void findGain() { //Still simplistic
//Find lengths between max and min of x, y and z
//Find mean and gain of each axis
if( Count > 1) {
if (vals[0] > x_max)
x_max = vals[0];
if (vals[0] < x_min)
x_min = vals[0];
if (vals[1] > y_max)
y_max = vals[1];
if (vals[1] < y_min)
y_min = vals[1];
if (vals[2] > z_max)
z_max = vals[2];
if (vals[2] < z_min)
z_min = vals[2];
}
x_length = x_max - x_min;
y_length = y_max - y_min;
z_length = z_max - z_min;
length_mean = (x_length + y_length + z_length) / 3;
x_gain = x_length / length_mean;
y_gain = y_length / length_mean;
z_gain = z_length / length_mean;
}
//**************************************************************************************************
//******************************************************************************************************
public void settings() { fullScreen(P3D); }
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "ScatterPlot" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}