// drag the circle by its center poin
// drag a point around the circumference of a circle
// the point's start positionis 0 at South
// as it moves anti-clockwise
// the angle traces 0, 0.25, 0.5, 0.75 0.99 turn
float TURN = TWO_PI;
float x0, y0, r0, a0;
float x1, y1;
float x2, y2;
float d02;
float rmin, rmax;
String turning;
void setup() {
size(360, 240);
textFont(createFont("Georgia", 16));
x0 = 180; y0 = 120; r0 = 80; a0 = 0;
x1 = 180; y1 = 200;
rmin = 0.9 * r0;
rmax = 1.1 * r0;
smooth();
stroke(0);
} //setup
void draw() {
background(207);
strokeWeight(1);
noFill();
ellipse(x0, y0, r0*2, r0*2);
//strokeWeight(3);
//line(x0, y0, x1, y1);
strokeWeight(1);
fill(255, 0, 0);
ellipse(x0, y0, 5, 5);
fill(255, 0, 0);
ellipse(x1, y1, 15, 15);
//println(str(a0)+" turn");
a0 = round(a0 * 100) / 100.0;
turning = str(a0)+" turn";
fill(0, 0, 255);
text(turning, width/2 - 30, height - 5);
} //draw
void mouseDragged()
{
x2 = mouseX; y2 = mouseY;
d02 = dist (x0, y0, x2, y2);
if (dist(x0, y0, x2, y2) < 19) {
float dx = x2 - x0; float dy = y2 - y0;
x0 = x2; y0 = y2;
x1 += dx; y1 += dy;
a0 = atan((y1 - y0)/(x1 - x0)) / TURN;
} else if ((d02 > rmin) && (d02 < rmax)) {
if (abs(x2 - x0) < 0.7 * r0) {
if (y2 - y0 > 0) {
//println("*S*");
x1 = x2;
y1 = y0 + sqrt(r0*r0 - (x2-x0)*(x2-x0));
if (x2 < x0) {
a0 = 0.75 - atan((y1 - y0)/(x1 - x0)) / TURN;
} else {
a0 = 0.25 - atan((y1 - y0)/(x1 - x0)) / TURN;
}
} else {
//println("*N*");
x1 = x2;
y1 = y0 - sqrt(r0*r0 - (x2-x0)*(x2-x0));
if (x2 < x0) {
a0 = 0.75 - atan((y1 - y0)/(x1 - x0)) / TURN;
} else {
a0 = 0.25 - atan((y1 - y0)/(x1 - x0)) / TURN;
}
}
} else {
if (x2 - x0 > 0) {
//println("*E*");
y1 = y2;
x1 = x0 + sqrt(r0*r0 - (y2-y0)*(y2-y0));
a0 = 0.25 - atan((y1 - y0)/(x1 - x0)) / TURN;
} else {
//println("*W*");
y1 = y2;
x1 = x0 - sqrt(r0*r0 - (y2-y0)*(y2-y0));
a0 = 0.75 - atan((y1 - y0)/(x1 - x0)) / TURN;
}
}
}
} //mouseDragged
|