I am intrigued. What is so special about the code?
// Draw a moving sinewave
x = 1;
for (int i = 1; i < (318 * 20); i++) //draw 20 iterations
{
x++;
if (x == 319) //start again
x = 1;
if (i > 319) //rub out the previous sinewave
{
if ((x == 159) || (buf[x - 1] == 119)) // ?axes
myGLCD.setColor(0, 0, 255); //yes, draw BLUE axis
else
myGLCD.setColor(0, 0, 0); //else rub out i.e. draw BLACK point
myGLCD.drawPixel(x, buf[x - 1]); //replace the previous point
}
myGLCD.setColor(0, 255, 255); //new graph is in CYAN
y = 119 + (sin(((i * 1.1) * 3.14) / 180) * (90 - (i / 100)));
myGLCD.drawPixel(x, y); //plot the new sinewave point
buf[x - 1] = y; //remember the point for next pass
}
You would use exactly the same algorithm in GFX. Except that it looks like
// Draw a moving sinewave
x = 1;
for (int i = 1; i < (318 * 20); i++) //draw 20 iterations
{
uint16_t color = BLACK; //for rubout
x++;
if (x == 319) //start again
x = 1;
if (i > 319) //rub out the previous sinewave
{
if ((x == 159) || (buf[x - 1] == 119)) // ?axes
color = BLUE; //yes, draw BLUE axis
tft.drawPixel(x, buf[x - 1], color); //replace the previous point
}
y = 119 + (sin(((i * 1.1) * 3.14) / 180) * (90 - (i / 100)));
tft.drawPixel(x, y, CYAN); //plot the new sinewave point
buf[x - 1] = y; //remember the point for next pass
}
Untested. The same algorithm. I just added comments to UTFT. And typed GFX version into my Browser.
UTFT sets the colour in a separate method. GFX uses colour as an argument to each graphics method. (which is a bit more intuitive)
David.