⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display_graphics.c

📁 一个小的嵌入式os
💻 C
字号:
//======================================
//file name:Display_graphics.c
//function:draw graphics
//author:by kaka,20080611
//======================================







#include "Gui.h"
#include "lcdconf.h"
#include <math.h>


//======================================
//function:display_line
//description:draw a line,this function is copyed from other's.
//			i don't know how did it worked.
//date:20080611
//======================================

void display_line(int s_x,int s_y,int e_x,int e_y,int color)
{  
	int Offset_x,Offset_y,Offset_k = 0;
	int Err_d = 1;
	if(s_y>e_y)
	{
		Offset_x = s_x;
		s_x = e_x;
		e_x = Offset_x;
		Offset_x = s_y;
		s_y = e_y;
		e_y = Offset_x;
	}
	Offset_x = e_x-s_x;
	Offset_y = e_y-s_y;
	draw_point(s_x,s_y,color);
	if(Offset_x<=0)
	{
		Offset_x = s_x-e_x;
		Err_d = -1;
	}
	if(Offset_x>Offset_y)
	{
		while(s_x!=e_x)
		{
			if(Offset_k>0)
			{
				s_y+=1;
				Offset_k += (Offset_y-Offset_x);
			}
			else Offset_k += Offset_y; 
			s_x+=Err_d;
			if(s_x>320||s_y>240) break;
			draw_point(s_x,s_y,color);
		}	
	}
	else
	{
		while(s_y!=e_y)
		{
			if(Offset_k>0)
			{
				s_x+=Err_d;
				Offset_k += (Offset_x-Offset_y);
			}
			else Offset_k += Offset_x;
			s_y+=1;
			if(s_x>=320||s_y>=240) break;
			draw_point(s_x,s_y,color);
		}
	}    
}




//======================================
//function:display_circle
//description:draw a circle,this function used float operation
//			i think ,the float operation will consume the 
//			capability.I will make it batter later.
//author:by kaka,
//date:20080611
//======================================
void display_Circle(int x,int y,int r,int color)
{

double y_Circle=0,r_circle=0,x_Circle=0;
x_Circle=(double)(x-r);
r_circle=(double)r;
	while(x_Circle<=(x+r))
		{
		y_Circle=sqrt(	((r)*(r))-(fabs(r_circle))*(fabs(r_circle))		);
		draw_point(x_Circle, (y+(int)y_Circle), color);
		draw_point(x_Circle, (y-(int)y_Circle), color);
		x_Circle=x_Circle+0.1; //you can change the 0.1 to 0.2 ,0.3.....or 1 to change the graphics's percision.
		r_circle=r_circle-0.1;	//you can change the 0.1 to 0.2 ,0.3.....or 1 to change the graphics's percision.
		}
}


//======================================
//funciont :display_circle_half
//description:draw a half circle,up circle
//author:by kaka.
//date:20080611
//======================================

void display_Circle_half(int x,int y,int r,int color)
{

double y_Circle=0,r_circle=0,x_Circle=0;
x_Circle=(double)(x-r);
r_circle=(double)r;
	while(x_Circle<=(x+r))
		{
		y_Circle=sqrt(	((r)*(r))-(fabs(r_circle))*(fabs(r_circle))		);
		//draw_point(x_Circle, (y+(int)y_Circle), color);
		draw_point(x_Circle, (y-(int)y_Circle), color);
		x_Circle=x_Circle+0.1;
		r_circle=r_circle-0.1;
		}
}


//======================================
//funciont :display_circle_solid
//description:draw a solid circle.
//author:by kaka.
//date:20080611
//======================================
void display_Circle_solid(int x,int y,int r,int color)
{

double y_Circle=0,r_circle=0,x_Circle=0;
x_Circle=(double)(x-r);
r_circle=(double)r;


	while(x_Circle<=(x+r))
		{
		y_Circle=sqrt(	((r)*(r))-(fabs(r_circle))*(fabs(r_circle))		);
		draw_point(x_Circle, (y+(int)y_Circle), color);
		draw_point(x_Circle, (y-(int)y_Circle), color);
		display_line(x_Circle, (y+(int)y_Circle),x_Circle, (y-(int)y_Circle), color);
		x_Circle=x_Circle+0.1;
		r_circle=r_circle-0.1;
		}
}







//=============================================
//
//
//
//
//
//=============================================




//=============================================
//
//
//
//
//
//=============================================






















//=============================================
//
//
//
//
//
//=============================================















//=============================================
//
//
//
//
//
//=============================================
















//=============================================
//
//
//
//
//
//=============================================
















//=============================================
//
//
//
//
//
//=============================================


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -