Hello
I am implementing an interface for my drone and I am blocked in the algorithm that draws the course.
The idea is to make vertical stripes along a landscape rectangle. The long lines are every 50px and they have the curse number every 5 degrees (for example 340, 345,350, 355, 0, 005, 010 …). The short lines are every 10px and do not have the numbers written.
So far I have been able to write the long and short stripes but the numbers above the long stripes do not come out correctly.
The section of the code is inside the draw function of the Heading class.
I’ve been trying for many days but I’m already quite blocked, I would need help.
Thank you!
class Heading {
PGraphics hg;
Heading(int xDim, int yDim) {
hg = createGraphics(xDim, yDim);
hg.beginDraw();
hg.noStroke();
hg.endDraw();
}
void draw(float value) {
hg.beginDraw();
hg.background(0, 0, 0);
hg.textAlign(CENTER, CENTER);
hg.stroke(255, 255, 0);
hg.fill(255);
hg.strokeWeight(2);
hg.strokeCap(SQUARE);
for (int i = -hg.width; i < hg.width; i++) {
//Long lines every 50px are 5 degrees (340 345 350 355 360 005 010 , by instante)
if (int(i+value)%50 == 0) {
hg.line(hg.width+i, hg.height, hg.width+i, hg.height-20);
hg.text(int(i+value), hg.width+i, 15); //I think here is my problem...
}
//Sort lines every 10px are 1 degrees and they haven't the number.
if ((int(i+value)%50 != 0) && (int(i+value)%10 == 0)) {
hg.line(hg.width+i, hg.height, hg.width+i, hg.height-10);
}
}
hg.stroke(255, 0, 0);
hg.line(hg.width/2, 0, hg.width/2, hg.height);
hg.endDraw();
image(hg, 0, 0);
}
}
float hdgValue;
Heading head0;
void setup() {
size(600, 400);
head0 = new Heading(300, 50);
hdgValue = 0;
}
void draw(){
background(155, 155, 155);
//heading();//Edited, it is not necesary
translate(width/4, height/4*3);
head0.draw(hdgValue);
translate(-width/4, -height/4*3);
}
void mouseClicked(){
hdgValue = random(0, 360);
}
/*//Edited, this is not necesary...
void heading(){
if (mouseX < 150)
hdgValue = hdgValue + 0.01 *((mouseX - 150));
if (mouseX > 300)
hdgValue = hdgValue + 0.01*((mouseX - 300));
if (hdgValue >= 360)
hdgValue = 0;
if (hdgValue < 0)
hdgValue = 360;
}
*/