Hello. I'm using the Bresenham Algorithm to plot pixels to be used in the tft.drawLine function.
tft.drawLine needs start and end coordinates which I am storing in Arrays.
I'm computing the coordinates once and storing the data for later use.
So far my code stores each x, y, x0, y0 in separate Arrays. I would like to combine these into 1 or 2 Arrays.
Getting this far has really hurt my brain learning about pointers and Arrays but I just need a little help crossing the line.
Thanks
My Array setup for Start coordinates...
int MyArray_x0[100];
int MyArray_y0[100];
int *myPointer_x0;
int *myPointer_y0;
int MyArray_x1[100];
int MyArray_y1[100];
int *myPointer_x1;
int *myPointer_y1;
My Plotline code. I have another function that plotsLine_x1_y1 but have left it out to save clutter
void plotLine_x0_y0(int x0, int y0, int x1, int y1)
{
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = dx+dy, e2; /* error value e_xy */
for (;;) { /* loop */
tft.drawPixel(x0, y0, TFT_YELLOW);// used for testing Line
UpdateArray_x0_y0(x0, y0);
e2 = 2*err;
if (e2 >= dy) { /* e_xy+e_x > 0 */
if (x0 == x1) break;
err += dy; x0 += sx;
}
if (e2 <= dx) { /* e_xy+e_y < 0 */
if (y0 == y1) break;
err += dx; y0 += sy;
}
}
}
My Update Array Code
void UpdateArray_x0_y0(int x0, int y0){
static unsigned int call_count = 0;
myPointer_x0 = &MyArray_x0[call_count];
myPointer_y0 = &MyArray_y0[call_count];
*myPointer_x0 = x0;
*myPointer_y0 = y0;
call_count++;
}
void UpdateArray_x1_y1(int y1, int x1){
static unsigned int call_count = 0;
myPointer_y1 = &MyArray_y1[call_count];
myPointer_x1 = &MyArray_x1[call_count];
*myPointer_y1 = y1;
*myPointer_x1 = x1;
call_count++;
}
