I am developing a sketch to graphically display GPS data coming from an Arduino. The sketch paints the background and “gauge” bezel and then calls various functions to fill in the face with appropriate data,
.
The compass function paint dots for 5 degree gradations in a circle inside the bezel. Following the dots the directional characters are displayed in a circle around the dots. Finally a pointer is painted.
The first time through the function, all is well. The second time through the function nothing changes except the directional characters are placed about 1/2" higher on the screen. I have printed out the x and y coordinates for each character each time through the function and they do not change yet the image has moved. All other parts of the screen remain in their original position.
Subsequent calls to the function cause no change (the original characters are misplaced on the screen). The clock function behaves the very same way.
I am attaching an document that shows the results of the printing.
Screen images of the before and after are attached:
My code for the compass function:
void Analog_Compass (){
int h,i;
String Directions [] = {"S","SW","W","NW","N","NE","E","SE"};
float needle_length = GD_IR * .5* 1.35;
float adjustments[] = {1.37, 1.45, 1.48, 1.45, 1.55, 1.50, 1.55, 1.50, 1.50, 1.48, 1.45, 1.45};
int w = 0;
int mindots [] = {8,8,7,5,5,5,4,4};
int hrdots [] = {15,15,13,10,10,10,8,8};
Compass_Calls ++;
//if (Compass_Calls == 2) exit();
//println ("Calls to 'Compass' with: " +nf(Current_Direction,0,1));
//................. Clear the face if using the daytime colors and establish the colors for the dots and numerals
if (SS_OnOff[10] == false){
fill (white);
stroke(white);
strokeWeight(0);
ellipse (GD_CX[Compass],GD_CY[Compass],GD_IR*2, GD_IR*2);
fill (black);
stroke(black);
} else {
fill (black);
stroke(black);
strokeWeight(0);
ellipse (GD_CX[Compass],GD_CY[Compass],GD_IR*2, GD_IR*2);
fill (blue);
stroke(blue);
}
//......................... Paint a dot every 5 degrees around the face of the compass
float dot_distance = GD_IR * .5* 1.35;
beginShape(POINTS);
for (float a = 0; a <= 360; a+=5) {
float angle = radians(a)+HALF_PI;
float x1 = GD_CX[Compass] + cos(angle) * dot_distance;
float y1 = GD_CY[Compass] + sin(angle) * dot_distance;
if (a%45 == 0) strokeWeight(hrdots[GD_Active]); else strokeWeight(mindots[GD_Active]);
vertex(x1, y1);
}
endShape();
//.......................... Paint the compass directions on the face of the compass
w = 0;
for (int a = 0; a < 360; a+=45) {
if (a%90 == 0) textSize(GD_IR *.32); else textSize(GD_IR *.22);
float angle = radians(a)+HALF_PI;
float adjusted_radius = (GD_IR * .58) * adjustments[w];
float x2 = GD_CX[Compass] + cos(angle) * adjusted_radius;
float y2 = GD_CY[Compass] + sin(angle) * adjusted_radius;
text (Directions[w],x2,y2);
// println (w + " '" + Directions[w] + "' at " + x2 + "/" + y2);
w = w+1;
}
//......................... Paint the compass needle
Needle (Compass,map(int(Current_Direction), 0, 360, 0, TWO_PI) - HALF_PI, needle_length * .93);
}//........................ End of analog compass