The positions of both arrays as text
this Sketch shows the positions with println
int[]x=
{
110, 300, 490,
110, 300, 490,
110, 300, 490
};
int[]y=
{
150, 150, 150,
300, 300, 300,
450, 450, 450
};
for (int i=0; i < x.length; i++) {
println ("field "+i+" is " +" located at " + x[i] + " and " + y[i] + " (x and y)." );
}//for
The positions of both arrays on the screen
This Sketch shows the positions as a graphic:
int[]x=
{
110, 300, 490,
110, 300, 490,
110, 300, 490
};
int[]y=
{
150, 150, 150,
300, 300, 300,
450, 450, 450
};
size(600, 600);
for (int i=0; i < x.length; i++) {
fill(255); // white
ellipse (x[i], y[i], 17, 17);
fill(0); // black
text( i, x[i]+19, y[i]);
}//for
Matching the mouse position to the positions of both arrays
And here is a Sketch that receives the mouse inputs and checks the distance to the 9 fields. When this distance is <50 we draw a X.
int[]x=
{
110, 300, 490,
110, 300, 490,
110, 300, 490
};
int[]y=
{
150, 150, 150,
300, 300, 300,
450, 450, 450
};
void setup() {
size(600, 600);
}//func
void draw() {
for (int i=0; i < x.length; i++) {
fill(255); // white
ellipse (x[i], y[i], 17, 17);
fill(0); // black
textSize(14);
text( i, x[i]+19, y[i]);
}//for
}//func
void mousePressed() {
for (int i=0; i < x.length; i++) {
//check the distance between mouse and the field #i
if (dist(mouseX, mouseY, x[i], y[i]) < 50) {
textSize(44);
text( "X", x[i]-3, y[i]+13);
}//if
}//for
}//func
//