Best approach to registering all elements touched
in
Android Processing
•
2 months ago
I have a grid of ellipses and I want to highlight the ellipses that have been on the path of a finger swiping over the screen. The code I'm using at the moment doesn't always highlight all ellipses (especially when swiping across the screen really fast). Does anyone have an idea of a more efficient way of approach this? or any ideas why not all ellipses touched get highlighted?
Code used:
- boolean[][] checked = new boolean[5][5];
- void setup() {
- size(displayWidth, displayHeight);
- ellipseMode(CENTER);
- smooth();
- noStroke();
- frameRate(30);
- }
- void draw(){
- background(255);
- for (int i=1; i<=5; i++){
- for (int j=1; j<=5; j++){
- fill(0,100);
- ellipse(i*width/5-width/10,height/8+j*height/8,width/7,width/7);
- if (mousePressed && sqrt(sq((i*width/5-width/10)-mouseX) + sq((height/8+j*height/8)-mouseY)) < width/7) {
- checked[i-1][j-1]=true;
- }
- if (checked[i-1][j-1]) {
- ellipse(i*width/5-width/10,height/8+j*height/8,width/7,width/7);
- }
- }
- }
- }
- void mouseReleased() {
- for (int i=1; i<=5; i++){
- for (int j=1; j<=5; j++){
- checked[i-1][j-1]=false;
- }
- }
- }
1