We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm looking to create an ellipse at a certain coordinate depending on the Mouse coordinates. Depending on the mouse position, the dot will be placed on one of the positions of the fret board. Thanks for the help!
PImage img;
float X_Space = 32;
float Y_Space = 33;
float X_Base = 63;
float Y_Base = 28;
void setup(){
size(576,144);
img = loadImage("Ukulele.png");
}
void draw(){
image(img, 0, 0);
ellipse(X_Base+(4*X_Space),Y_Base,20,20);
Answers
Just imagine a circle over each intersection and then use OverCircle() to determine the position. On mouse release loop over the positions to find the location. A release between circles will be a dead zone.
x,y is the line intersection, the diameter, the distance between frets
Faster alternative for overCircle(): ;;)
Under the heading of
Make it work, make it right, make it run faster...
Surprised no one suggested an optimization for calculating the column based on x, then the row, based on y, and checking the specific circle, and not looping over the 60 positions.
However for user interaction over a small number of fret positions it could be over-kill.
no need for any distance calculations or any iterating - it's a grid with equal spacing in both directions (see lines 2-5).
just take the offset off the mouse position, integer divide it by the spacing. multiply it by the spacing and add the offset back on and that should've aligned it to one of the frets. (give or take half a spacing)
(think that's right - will supply a code example when i'm not at work)
I've got an online example which places rects by offset in a double loop to form a grid: =:)
http://studio.processingtogether.com/sp/pad/export/ro.98-pSvW97Q-RE/latest
which is completely unrelated. he HAS the grid, it's a png, it's attached in the question.
ok, something like this. unfortunately the image attached doesn't quite match the numbers given - it might've been resized by the forum or during the download.