// two-dimensional array? // i = 1, 8; // int F[], // shown an height // x[i], // // constrain x[i] sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){ ibest = i; dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX); } } ellipse(x[ibest],F[ibest]+100,20,20); text (Integer.toString(ibest), mouseX+10, mouseY-12); text (Integer.toString(F[ibest]), mouseX+10, mouseY); text (Integer.toString(x[ibest]), mouseX+10, mouseY+12); if (mousePressed == true){ //now use ibest to move to mouseX, mouseY x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX)); F[ibest] = mouseY - 100; if (mouseY < 0) F[ibest] = -100; if (mouseY > 200) F[ibest] = 100; } //plot "terrain" assuming 80 point separation of F[]'s pushMatrix(); translate(0,height/2); top = 0; FF = F[0]; for (i = 0; i < n; i = i+1) { s = x[i+1]-x[i]+1; // increment used for plotting inc = 0.01*(F[i+1]-F[i])/s; for (j = 0; j < s; j = j+1) { FF = FF + inc; top = top + FF; // j increments of inc = F diff. line(x[i]+j,height,x[i]+j,top); } } popMatrix(); }