Levetop / LT768x Coding - Libraries & Examples (2)

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:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值