Beispiel #1
0
/**
 * @brief Helper function for plotting an ellipse.
 * @param CX    x coordinate of one side
 * @param CY    y coordinate of one side
 * @param X   x coordinate of other side
 * @param Y   y coordinate of other side
 * @param color     Ellipse color 
 * @return none
 */
void inline Plot4EllipsePoints(long CX,long  CY, long X, long Y, unsigned int color)
{
  TFT_SetPixel(CX+X, CY+Y, color); //{point in quadrant 1}
  TFT_SetPixel(CX-X, CY+Y, color); //{point in quadrant 2}
  TFT_SetPixel(CX-X, CY-Y, color); //{point in quadrant 3}
  TFT_SetPixel(CX+X, CY-Y, color); //{point in quadrant 4}
}
Beispiel #2
0
/**
 * @brief This function plots a full disk on the display.
 * @param CenterX   Center x coordinate
 * @param CenterY   Center y coordinate
 * @param Radius   Disk radius
 * @param color   Disk Color 
 * @return none
 */
 void TFT_Disk(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color)
 {
	unsigned int i, x, yL, yU;

	//start at Xmiddle-Radius and end at Xmiddle+Radius
	for (x = CenterX - Radius; x <= CenterX + Radius; x++) 
	{
		yL = TFT_dfloor(CenterY - sqrt(Radius * Radius - (x - CenterX) * (x - CenterX)));
		yU = TFT_dfloor(CenterY + sqrt(Radius * Radius - (x - CenterX) * (x - CenterX)));
		//draw vertical lines between X|Yl and X|Yu
		for (i = 0; i < (yU - yL); i++) 
		{
			if (i <= yU && yL >= 0) 
			{
				TFT_SetPixel(x, yL + i, color);
			}
		}
		//draw the upper halve's pixel
		if (yU < 80 && yU > 0) 
		{
			TFT_SetPixel(x, yU, color);
		}
		//the lower pixel
		if (yL < 80 && yL > 0) 
		{
			TFT_SetPixel(x, yL, color);
		}
	}
}
Beispiel #3
0
/**
 * @brief This function draws a circle centered a x,y with radius R and specific color.
 * @param CenterX   Center x coordinate
 * @param CenterY   Center y coordinate
 * @param Radius  Circle radius
 * @param color Circle's color.
 * @return none
 */
void TFT_Circle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color)
{
  unsigned int y=0, x=0, d = 0;
  int part; 
  d = CenterY - CenterX;
  y = Radius;
  part = 3 - 2 * Radius;

  while (x <= y) { 
    TFT_SetPixel(CenterX + x, CenterY + y,color);
    TFT_SetPixel(CenterX + x, CenterY - y,color);
    TFT_SetPixel(CenterX - x, CenterY + y,color);
    TFT_SetPixel(CenterX - x, CenterY - y,color);
    TFT_SetPixel(CenterY + y - d, CenterY + x,color);
    TFT_SetPixel(CenterY + y - d, CenterY - x,color);
    TFT_SetPixel(CenterY - y - d, CenterY + x,color);
    TFT_SetPixel(CenterY - y - d, CenterY - x,color);

    if (part < 0) part += (4 * x + 6);
    else {
      part += (4 * (x - y) + 10);
      y--;
    }
    x++;
  }
}  
Beispiel #4
0
/**
 * @brief  This function draws a rectangle with round corners
 * @param x   Top left point X coordinate  
 * @param y   Top left pointy Y coordinate  
 * @param width   Rectangle width
 * @param height   Rectangle height
 * @param radius   Radius of the edges
 * @param color  Recatngle color 
 * @return none
 */
void TFT_RoundRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int radius, unsigned int color)
{
      int tSwitch, x1 = 0, y1 = radius;
      tSwitch = 3 - 2 * radius;
    
    while (x1 <= y1) {
        TFT_SetPixel(x+radius - x1, y+radius - y1, color);
        TFT_SetPixel(x+radius - y1, y+radius - x1, color);

        TFT_SetPixel(x+width-radius + x1, y+radius - y1, color);
        TFT_SetPixel(x+width-radius + y1, y+radius - x1, color);
        
        TFT_SetPixel(x+width-radius + x1, y+height-radius + y1, color);
        TFT_SetPixel(x+width-radius + y1, y+height-radius + x1, color);

        TFT_SetPixel(x+radius - x1, y+height-radius + y1, color);
        TFT_SetPixel(x+radius - y1, y+height-radius + x1, color);

        if (tSwitch < 0) {
            tSwitch += (4 * x1 + 6);
        } else {
            tSwitch += (4 * (x1 - y1) + 10);
            y1--;
        }
        x1++;
    }
          
    TFT_HorizontalLine(x+radius,y, width-(2*radius), color);                // top
    TFT_HorizontalLine(x+radius,y+height, width-(2*radius),  color);        // bottom
    TFT_VerticalLine(x,y+radius,height-(2*radius), color);                // left
    TFT_VerticalLine(x+width, y+radius,height-(2*radius),  color);        // right
}
Beispiel #5
0
//*************************************************************************************
void TFT_DrawChar( int ascii, int poX, int poY,int size, int fgcolor)
{
	int i = 0;   int f =0 ;
	int temp=0, k;
	if((ascii>=32)&&(ascii<=255))	{;}
	else	{ascii = '?'-32;}
	
	for (i = 0; i < FONT_X; i++ ) 
	{
		if ((ascii >= 0x20) && (ascii <= 0x7F))
		{
			temp = (Font16x16[ascii-0x20][i]);// temp = (&Font16x16[ascii-0x20][i]);
		}
		else if ( ascii >= 0xC0 )
		{
			temp = (Font16x16[ascii-0x65][i]);//  temp = (&Font16x16[ascii-0x65][i]);+++++++++++++++++++
		}
		k=i / 8;
		for(f =0 ; f < FONT_Y; f++)
		{
			if((temp>>f)&0x01)
			{
				if (size == 0)TFT_SetPixel(poX+i-(k*8), poY+f+(k*8),fgcolor);
				else TFT_FillRectangle(poX+i*size-(k*8)*size, poY+f*size+(k*8)*size, size, size, fgcolor);
			}
		}
	}
}
Beispiel #6
0
//*************************************************************************************
void TFT_DrawCircle(int poX, int poY, int r,int color)
{
	int x = -r, y = 0, err = 2-2*r, e2;
	do {
		TFT_SetPixel(poX-x, poY+y,color);
		TFT_SetPixel(poX+x, poY+y,color);
		TFT_SetPixel(poX+x, poY-y,color);
		TFT_SetPixel(poX-x, poY-y,color);
		e2 = err;
		if (e2 <= y) {
			err += ++y*2+1;
			if (-x == y && e2 <= x) e2 = 0;
		}
		if (e2 > x) err += ++x*2+1;
	} while (x <= 0);
}
Beispiel #7
0
/**
 * @brief This function paints an empty rectangle on the screen. The width of the contour is 1 pixel.
 * @param Xaxis1 Starting point x coordinate.
 * @param Yaxis1 Starting point y coordinate.
 * @param Xaxis2 Finish point x coordinate. 
 * @param Yaxis2 Finish point y coordinate.
 * @param color Contour color.
 */
void TFT_EmptyRectangle(unsigned int Xaxis1,unsigned int Yaxis1, unsigned int Xaxis2,unsigned int Yaxis2,unsigned int color)
{
      unsigned int CurrentValue;

    /* Draw the two horizontal lines */
      for (CurrentValue = 0; CurrentValue < Xaxis2 - Xaxis1+ 1; CurrentValue++) 
      {
        TFT_SetPixel(Xaxis1 + CurrentValue, Yaxis1,color);
        TFT_SetPixel(Xaxis1 + CurrentValue, Yaxis2,color);
    }
      
      /* draw the two vertical lines */
      for (CurrentValue = 0; CurrentValue < Yaxis2 - Yaxis1 + 1; CurrentValue++)    
      {
        TFT_SetPixel(Xaxis1, Yaxis1 + CurrentValue,color);
        TFT_SetPixel(Xaxis2, Yaxis1 + CurrentValue,color);
    }
}
Beispiel #8
0
/**
 * @brief This function draws a circle centered a x,y with radius R and specific color.
 * @param CenterX   Center x coordinate
 * @param CenterY   Center y coordinate
 * @param Radius  Circle radius
 * @param color Circle's color.
 * @return none
 */
void TFT_DrawCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color)
{
	unsigned int x, yL, yU;

	for (x = (CenterX - Radius); x <= CenterX + Radius; x++) 
	{
		yL = CenterY - sqrt(Radius * Radius - (x - CenterX) * (x - CenterX));
		yU = CenterY + sqrt(Radius * Radius - (x - CenterX) * (x - CenterX));

		if (yL < 80 && yL > 0) 
		{
			TFT_SetPixel(x, yL, color);
		}
		if (yU < 80 && yU > 0) 
		{
			TFT_SetPixel(x, yU, color);
		}
	}
}
Beispiel #9
0
/**
 * @brief This function paints a filled rectangle on the screen.
 * @param Xaxis1 x coordinate of upper point 
 * @param Yaxis1 y coordinate of upper point 
 * @param Xaxis2 x coordinate of lower point 
 * @param Yaxis2 y coordinate of lower point 
 * @param color Rectangle plot
 * @return none
 */
void TFT_FullRectangle(unsigned int Xaxis1, unsigned int Yaxis1, unsigned int Xaxis2 ,unsigned int Yaxis2,unsigned int color)
{
  unsigned int i = 0;
  unsigned int j = 0;

    for(i=Xaxis1;i<= Xaxis2;i++)
    {
        for(j=Yaxis1;j<=Yaxis2;j++)
        {
            TFT_SetPixel(i,j,color);
        } 
    }   
}  
Beispiel #10
0
/**
 * @brief This function paints a 
 * @param x1    Starting point x coordinate.
 * @param y1    Starting point y coordinate.
 * @param x2    Finish point x coordinate.
 * @param y2    Finish point y coordinate.
 * @param color Color of the line.
 * @return none
 */
void TFT_Line(unsigned int x1, unsigned int  y1, unsigned int  x2, unsigned int  y2, unsigned int color)
{
   unsigned int  deltax, deltay, x,y;
   unsigned char   steep;
   int lerror, ystep;

    steep = absDiff(y1,y2) > absDiff(x1,x2);   //check slope

    if (steep)
    {
        swap(x1, y1);
        swap(x2, y2);
    }

    if (x1 > x2)
    {
        swap(x1, x2);
        swap(y1, y2);
    }

    deltax = x2 - x1;
    deltay = absDiff(y2,y1);  
    lerror = deltax / 2;
    y = y1;
    if(y1 < y2) ystep = 1;  else ystep = -1;

    for(x = x1; x <= x2; x++)
    {
        if (steep) TFT_SetPixel(y,x, color); else TFT_SetPixel(x,y, color);
           lerror -= deltay;
        if (lerror < 0){
            y = y + ystep;
            lerror += deltax;
        }
    }
}
Beispiel #11
0
//*************************************************************************************
void TFT_DrawLine( int x0,int y0,int x1, int y1,int color)
{
	int x = x1-x0;
	int y = y1-y0;
	int dx = abs(x), sx = x0<x1 ? 1 : -1;
	int dy = -abs(y), sy = y0<y1 ? 1 : -1;
	int err = dx+dy, e2;                                                /* error value e_xy             */
	for (;;){                                                           /* loop                         */
		TFT_SetPixel(x0,y0,color);
		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;
		}
	}
}
Beispiel #12
0
/**
 * @brief Plot a slanty line from x1,y1 to x2,y2 on the display.
 * @param lX1 Starting point x coordinate.
 * @param lY1 Starting point y coordinate.
 * @param lX2 Finish point x coordinate. 
 * @param lY2 Finish point y coordinate.
 * @param color
 * @return none
 */
void TFT_SlantyLine(unsigned int lX1, unsigned int lY1, unsigned int lX2,unsigned int lY2,unsigned int color)
{
    long lError, lDeltaX, lDeltaY, lYStep, bSteep;       
    
    // A steep line has a bigger ordinate.
    
    if(((lY2 > lY1) ? (lY2 - lY1) : (lY1 - lY2)) > ((lX2 > lX1) ? (lX2 - lX1) : (lX1 - lX2))){
        bSteep = 1;
    }else {
        bSteep = 0;
    }
        
    // If line is steep, swap the X and Y coordinates.
    if(bSteep){
        lError = lX1;
        lX1 = lY1;
        lY1 = lError;
        lError = lX2;
        lX2 = lY2;
        lY2 = lError;
    }
   
    // If the starting X coordinate is larger than the ending X coordinate,
    // swap the start and end coordinates.
    if(lX1 > lX2){
        lError = lX1;
        lX1 = lX2;
        lX2 = lError;
        lError = lY1;
        lY1 = lY2;
        lY2 = lError;
    }
        
    lDeltaX = lX2 - lX1;	 // Compute the difference between the start and end coordinates. 
    lDeltaY = (lY2 > lY1) ? (lY2 - lY1) : (lY1 - lY2);
                                                                   
    lError = -lDeltaX / 2;          // Initialize the error term to negative half the X delta.
     
    if(lY1 < lY2){           // Determine the direction to step in the Y axis when required.
        lYStep = 1;
    }else{
        lYStep = -1;
    }
        
    for(; lX1 <= lX2; lX1++)
	{    // Loop through all the points along the X axis of the line.
        
        // See if this is a steep line.
        
        if(bSteep){            
            // Plot this point of the line, swapping the X and Y coordinates.            
            TFT_SetPixel(lY1, lX1,color);
        }
        else {           // Plot this point of the line, using the coordinates as is.            
            TFT_SetPixel(lX1, lY1,color);
        }                     
        
        // Increment the error term by the Y delta.
        
        lError += lDeltaY; 
                    
        if(lError > 0){        		// See if the error term is now greater than zero.
                     
            lY1 += lYStep;        	// Take a step in the Y axis.
                                                                       
            lError -= lDeltaX;     	// Decrement the error term by the X delta.
        }
    }
}