LT768x supports plenty of geometric drawing functions, including drawing lines, circles, curves, rectangles, and much more. This section is to explain how users can draw geometric figures through LT768x.
(1) Draw a line to connect (X1, Y1) and (X2, Y2) in designated color and width.
void LT768_DrawLine_Width
(
unsigned short X1 // 1st point: X1
,unsigned short Y1 // 1st point: Y1
,unsigned short X2 // 2nd point: X2
,unsigned short Y2 // 2nd point: Y2
,unsigned long LineColor // Line color
,unsigned short Width // Line width
)
(2) Draw a hollow circle at the center of (XCenter, YCenter) with R radius and designated color.
void LT768_DrawCircle
(
unsigned short XCenter // Circle center, x coordinate
,unsigned short YCenter // Circle center, y coordinate
,unsigned short R // Circle radius
,unsigned long CircleColor // Line color
)
(3) Draw a hollow rectangle from left-top (X1, Y1) to right-bottom (X2, Y2) in designated line color.
void LT768_DrawSquare
(
unsigned short X1 // Left-top coordinate X1
,unsigned short Y1 // Left-top coordinate Y1
,unsigned short X2 // Right-bottom coordinate X2
,unsigned short Y2 // Right-bottom coordinate Y2
,unsigned long SquareColor // Line color
)
Example codes are as below:
/*---------------------------------------------------------------------------------------*/
/* Function: Draw_Demo */
/* */
/* Parameters: None */
/* Returns: None */
/* Description: Demonstrate geometric drawing functions */
/*---------------------------------------------------------------------------------------*/
void Draw_Demo(void)
{
unsigned long i,j,h,z,d,w;
unsigned long resx1,resy1,resx2,resy2;
Select_Main_Window_16bpp();
Main_Image_Start_Address(layer3_start_addr); // Set main window starting address
Main_Image_Width(LCD_XSIZE_TFT);
Canvas_Image_Start_address(layer3_start_addr); // Set canvas window starting address
Canvas_image_width(LCD_XSIZE_TFT); // Set canvas width
Active_Window_XY(0,0);
Active_Window_WH(LCD_XSIZE_TFT,LCD_YSIZE_TFT); // Set the active window area
Main_Window_Start_XY(0,0); // Set the starting coordinate of the main window
//--------------------------- Line ------------------------------
LT768_DrawSquare_Fill(0,0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,White); // Display full white screen
h=0;
do
{
resx1=rand()%LCD_XSIZE_TFT; // Starting x coordinate
resy1=rand()%(LCD_YSIZE_TFT); // Starting y coordinate
resx2=rand()%LCD_XSIZE_TFT; // Ending x coordinate
resy2=rand()%(LCD_YSIZE_TFT); // Ending y coordinate
i=rand()%65536; // Line color
w=rand()%20;
LT768_DrawLine_Width(resx1,resy1+w,resx2,resy2+w,i,w);
h++;
}
while(h<20);
h=0;
do
{
resx1=rand()%LCD_XSIZE_TFT; // Starting x coordinate
resy1=rand()%(LCD_YSIZE_TFT); // Starting y coordinate
resx2=rand()%LCD_XSIZE_TFT; // Ending x coordinate
resy2=rand()%(LCD_YSIZE_TFT); // Ending y coordinate
i=rand()%65536; // Line color
w=rand()%20;
LT768_DrawLine_Width(resx1,resy1+w,resx2,resy2+w,i,w);
h++;
}
while(h<2500);
//------------------------ Circle ------------------------------
LT768_DrawSquare_Fill(0,0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,White); // Display full white screen
h=0;
do
{
resx1=rand()%LCD_XSIZE_TFT; // x coordinate of the circle center
resy1=rand()%(LCD_YSIZE_TFT-24); // y coordinate of the circle center
z=rand()%200; // radius
i=rand()%65536; // Color
j=rand()%3;
if(j) LT768_DrawCircle(resx1,resy1,z,i); // Draw hollow circle
else LT768_DrawCircle_Fill(resx1,resy1,z,i); // Draw solid circle
h++;
}
while(h<20);
h=0;
do
{
resx1=rand()%LCD_XSIZE_TFT; // x coordinate of the circle center
resy1=rand()%(LCD_YSIZE_TFT-24); // y coordinate of the circle center
z=rand()%200; // radius
i=rand()%65536; // Color
j=rand()%3;
if(j) LT768_DrawCircle(resx1,resy1,z,i); // Draw hollow circle
else LT768_DrawCircle_Fill(resx1,resy1,z,i); // Draw solid circle
h++;
}
while(h<2500);
//------------------------- Rectangle ----------------------------
LT768_DrawSquare_Fill(0,0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,White); // Display full white screen
h=0;
do
{
resx1=rand()%LCD_XSIZE_TFT; // x coordinate of the starting point
resy1=rand()%(LCD_YSIZE_TFT); // y coordinate of the starting point
resx2=rand()%LCD_XSIZE_TFT; // x coordinate of the ending point
resy2=rand()%(LCD_YSIZE_TFT); // y coordinate of the ending point
i=rand()%65536; // Color
j=rand()%3;
if(j) LT768_DrawSquare(resx1,resy1,resx2,resy2,i); // Draw hollow rectangle
else LT768_DrawSquare_Fill(resx1,resy1,resx2,resy2,i); // Draw solid rectangle
h++;
}
while(h<20);
h=0;
do
{
resx1=rand()%LCD_XSIZE_TFT; // x coordinate of the starting point
resy1=rand()%(LCD_YSIZE_TFT); // y coordinate of the starting point
resx2=rand()%LCD_XSIZE_TFT; // x coordinate of the ending point
resy2=rand()%(LCD_YSIZE_TFT); // y coordinate of the ending point
i=rand()%65536; // Color
j=rand()%3;
if(j) LT768_DrawSquare(resx1,resy1,resx2,resy2,i); // Draw hollow rectangle
else LT768_DrawSquare_Fill(resx1,resy1,resx2,resy2,i); // Draw solid rectangle
h++;
}
while(h<2000);
}
Running result: