Problem in creating compass in Processing for Android

Hello. I’m trying to create a simple compass in processing.
I’m following this tutorial:

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() {

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

translate(cx, cy);

ellipse(0, 0, radius2, radius2);
line(0, -cy, 0, -radius);

fill(192, 0, 0);
vertex(-30, 40);
vertex(0, 0);
vertex(30, 40);
vertex(0, -radius);


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


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: