Problem in creating compass in Processing for Android

Hello. I’m trying to create a simple compass in processing.
I’m following this tutorial:
https://android.processing.org/tutorials/wallpapers/index.html

everything is fin. The rotation angle which I’m getting is also correct. (I’ve tried other playstore apps to verify it) but when the compass needle draws itself. I see too much variation in it.

Here’s the code for drawing:

void draw() {
background(255);

float cx = width * 0.5;
float cy = height * 0.4;
float radius = 0.8 * cx;

translate(cx, cy);

noFill();
stroke(0);
strokeWeight(2);
ellipse(0, 0, radius2, radius2);
line(0, -cy, 0, -radius);

fill(192, 0, 0);
noStroke();
//rotate(-azimuth);
rotate(round(bearingInFloat));
beginShape();
vertex(-30, 40);
vertex(0, 0);
vertex(30, 40);
vertex(0, -radius);
endShape();

}

bearingInFloat is the variable containing rotation angle from 0 to 360.

Here’s the video of the problem:

Hi, @aiman

Taking a fast look, the problem can be the angle, rotation expect the angles in radians (when your cursor move that fast with little variations, that can be because of the angles), you can put the anglemode in radians, or cast bearingInFloat to radians

rotate(radians(bearingInFloat));

Hope it helps :smiley:

1 Like

Thank you so much for replying. Yes I did figure that out hours after posting the thread. I do appreciate your help thou. Thanks :slight_smile: