#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Minimum distance step movement for orbiting circle

edited April 2017

I've partly borrowed some code that creates a 'clock' by splitting 360 degrees around the center of the screen into 12 steps. While the circle does 'jump' between steps, the 'jumping' behaviour doesn't work the way it is supposed to. The problem is that the circle will only jump forward by one step, if the angle of the mouse is >= the angle of the step, and it jumps backwards a step as soon as the mouse angle goes below the angle of the step.

I've through various different methods tried (and failed) to create an effective method to make the stepping circle jump to the step which angle is closest to the angle of the mouse, so that it would jump step 1 when the angle was greater than 15 degrees and less than 45.

Any ideas?

(Also: I am for some reason completely unable to format the code into the forum(???) so i've uploaded it to github): github.com/xtxte/RebelScum/blob/master/sketch_170325b.pde

Tagged:

• to format the code, edit your post, highlight the code, press ctrl-o.

i must've written those words 100000 times.

``````float rad;    //radius of circle
PVector vCent, vMouse;
float angle1;
final float half=0.5;
int step;
float stepAngle;
final float twelve=12;
float cxubx;
float cyubx;
float ccx;

void setup() {
fullScreen();
fill(255);
vCent= new PVector(0, -height*half); //Straight upwards
ccx=half*width;
}

void draw() {
background(0);
translate(width/2, height/2);
vMouse= new PVector(mouseX-width/2, mouseY-height/2);
fill(#FFB803);
angle1=(mouseX<=ccx) ? 360-degrees(PVector.angleBetween(vCent, vMouse)) : degrees(PVector.angleBetween(vCent, vMouse));

step=int(map(angle1, 0, 360, 0, twelve)); //dividing 360 degrees into 12 steps

if (step==12) {
step=0;
}
stepAngle=((step / twelve) * TWO_PI);

fill(#2303FF);

fill(255);
textSize(34);
text("mouseangle;"+angle1, 100, 100);
text("step:"+step, 100, 150);
text("stepangle:"+degrees(stepAngle), 100, 200);
}
``````
• edited April 2017

I know exactly what you mean and have an idea for how to solve it that I know works as I'we done it years ago, but it wasn't in processing or even for mouse,
actually it was for a xbox 360 controller, and 8 steps rather than 12,
but the principle should be the same, you check the "change of rotation" in steps and add it to the clock, rather than direct the clock towards the mouse.

Something like this..

``````stepchange=step-pstep;
if(abs(stepchange)>=2){
clockstep+=stepchange+((stepchange>0)?-1:1);
previous_step=step;
}
``````

You need a special case for when it goes from 12 to 1 and vice versa

Also having 36 mouse steps and 12 clock steps would help

• solution to this was to use round() instead of int() when mapping the angles