I have this code that will draw pixels or lines mapped as an arc across the display.
I wanted to draw numbers in increments but I don't know the code to do this?
so far the code will generate points which can be converted to an x,y location.
but how can a map EACH point to a letter or number?
how would I make each point 1,2,3,4,5,6, etc and draw to x,y (of the display pos.)
thanks!
//draw arc points
int x3, y3;
int length3 = 45;
float angle3 = 0.0;
float angle_stepsize3 = 0.314;
// go through all angles from 0 to 2 * PI radians
while (angle3 < 2 * PI)
{
// calculate x, y from a vector with known length and angle
x3 = x0 - length3 * cos (angle3);
y3 = y0 - length3 * sin (angle3);
display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(x3,y3); display.print(?);
angle3 += angle_stepsize3;
}
//draw arc
Set a variable, of type byte, such as pointNumber, to 0 before the while loop that does the work. As the first thing in the body of the while loop, increment pointNumber.
and draw to x,y
Draw what? At which x and y? Converting pointNumber to a string is trivial, using itoa(). Getting that text onto the display is for you to do. We can't tell what methods that object has, from just that snippet.
There is NO excuse for putting multiple statements on one line. Stop doing that.
void drawArcPoints()
{
//draw arc points
int x3, y3;
int length3 = 45;
float angle3 = 0.0;
float angle_stepsize3 = 0.314;
int i;
// go through all angles from 0 to 2 * PI radians
for (angle3 = 0.0, i = 0; angle3 < 2 * PI; angle += angle_stepsize3, i++)
{
// calculate x, y from a vector with known length and angle
x3 = x0 - length3 * cos (angle3);
y3 = y0 - length3 * sin (angle3);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(x3, y3);
display.print( i );
}
}
thanks john for helping, I will give that a try also.
I had already figured out a quick fix below, but have also found using numbers like 0, 10, 100 all shift the centring of the arc (which can be tweaked a bit with the other inputs in the code)
// calculate x, y from a vector with known length and angle
x3 = x03 - length3 * cos (angle3);
y3 = y03 - length3 * sin (angle3); int ss;
display.setCursor(x3,y3); display.print(ss); ss = ss+1; > johnwasser: > ``` **> void drawArcPoints()
{
//draw arc points
int x3, y3;
int length3 = 45;
float angle3 = 0.0;
float angle_stepsize3 = 0.314;
int i;
// go through all angles from 0 to 2 * PI radians
for (angle3 = 0.0, i = 0; angle3 < 2 * PI; angle += angle_stepsize3, i++)
{
// calculate x, y from a vector with known length and angle
x3 = x0 - length3 * cos (angle3);
y3 = y0 - length3 * sin (angle3);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(x3, y3);
display.print( i );
}
}
__> ```**__
It is likely that characters and drawn above and to the right of the starting point or below and to the right of the starting point. If you want the text centered on the starting point you will need to calculate the text's width and height and apply half the width to the X position and half the height to the Y position to center the text.