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

📄 graphic_algorithm.c

📁 MSP430z_f247.rar
💻 C
字号:
/*****************************************************************
*   函数库名称:AVR硬件资源配置函数源文件                        *
*   版本:      v0.01                                            *
*   作者:      I ROBOT                                          *
*   创建日期:  Copyright (C) 2008年10月14日                     *
*----------------------------------------------------------------*
*   [支持库]                                                     *
*   支持库名称:Hardware_Apply_Init.h(AVR硬件资源配置头文件)     *
*   支持库版本:v0.01                                            *
*   支持库说明:与本文件相应的函数声明                           *
*----------------------------------------------------------------*
*   [版本更新]                                                   *
*   更新:      I ROBOT                                          *
*   更新日期:                                                    *
*   版本:                                                       *
*----------------------------------------------------------------*
*   [版本历史]                                                   *
*        v0.01  创建版本,配置AVR硬件资源                        *
*----------------------------------------------------------------*
*   [使用说明]                                                   *
*            1.配置使用的AVR硬件资源                             *
*****************************************************************/

/********************
* 头 文 件 配 置 区 *
********************/
# include "Graphic_Algorithm.h"
/********************
*   系 统 宏 定 义  *
********************/

/*------------------*
*   常 数 宏 定 义  *
*------------------*/

/*------------------*
*   动 作 宏 定 义  *
*------------------*/
                                                             
/********************
*  模块结构体定义区 *
********************/

/********************
*   函 数 声 明 区  *
********************/
void Line_To(Draw_Info *Queue,UINT8 chCur_ID_Draw,
INT16 chx_Start,INT16 chy_Start,
INT16 chx_End,INT16 chy_End);

void Draw_Graph(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 *chX_Array,UINT8 *chY_Array,UINT8 chDot_Sum);
/********************
*   模块函数声明区  *
********************/

/********************
*   模块变量声明区  *
********************/

/********************
*   全局变量声明区  *
********************/

/******************************************************************
*                       函  数  定  义  区                        *
******************************************************************/

/****************************************
*  函数说明: 图层画线函数               *
*            Bresenham视线算法-画线函数 *
*  输入    :Queue(图层队列)            *
*            chCur_ID_Draw(当前图层的ID)*
*            chx_Start(起点x)           *
*            chy_Start(起点y)           *
*            chx_End(终点x)             *
*      chy_End(终点y)             *
*  输出    :无                         *
*  调用函数: Draw_Dot()                *
*            ABS()                      *
****************************************/
void Line_To(Draw_Info *Queue,UINT8 chCur_ID_Draw,
INT16 chx_Start,INT16 chy_Start,
INT16 chx_End,INT16 chy_End)
{
    INT16 Dx = ABS(chx_End-chx_Start);
    //算法参看Bresenham视线算法
    INT16 Dy = ABS(chy_End-chy_Start);
    INT16 chx_Index = chx_Start;
    INT16 chy_Index = chy_Start;
    INT16 chx_Deta = 1;
    INT16 chy_Deta = 1;
    if (chx_End-chx_Start < 0)
    {
        chx_Deta = -1;
    }
    if (chy_End-chy_Start < 0)
    {
        chy_Deta = -1;
    }
    Draw_Dot(Queue,chCur_ID_Draw,chx_Index,chy_Index);
    if (Dx >= Dy)
    {
        UINT8 chStep_Counte = 0;
        INT16 Error = (Dy << 1)-Dx;
        
        for (chStep_Counte = 0;chStep_Counte < (UINT8)Dx;chStep_Counte++)
        {
            if (Error >= 0)
            {
                Error = Error-(Dx << 1);
                chy_Index += chy_Deta;
            }
            chx_Index += chx_Deta;
            Error = Error+(Dy << 1);
            Draw_Dot(Queue,chCur_ID_Draw,chx_Index,chy_Index);
        }
    }
    else 
    {
        UINT8 chStep_Counte = 0;
        INT16 Error = (Dx << 1)-Dy;
 
        for (chStep_Counte = 0;chStep_Counte < (UINT8)Dy;chStep_Counte++)
        {
            if (Error >= 0)
            {
                Error = Error-(Dy << 1);
                chx_Index += chx_Deta;
            }
            chy_Index += chy_Deta;
            Error = Error+(Dx << 1);
            Draw_Dot(Queue,chCur_ID_Draw,chx_Index,chy_Index);
        }
    }
}

/****************************************
*  函数说明: 图层画图函数               *
*  输入    :Queue(图层队列)            *
*      chCur_ID_Draw(当前图层的ID)*
*            chX_Array(X点集合)         *
*            chY_Array(Y点集合)         *
*            chDot_Sum(点的总数)        *
*  输出    :无                         *
*  调用函数: Line_To()                  *
****************************************/
void Draw_Graph(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 *chX_Array,UINT8 *chY_Array,UINT8 chDot_Sum)
{
    UINT8 chDot_Counter = 0;
    for (chDot_Counter = 0;chDot_Counter < chDot_Sum-1;chDot_Counter++)
    {
        Line_To
        (Queue,chCur_ID_Draw,
        (INT16)chX_Array[chDot_Counter],
        (INT16)chY_Array[chDot_Counter],
        (INT16)chX_Array[chDot_Counter+1],
        (INT16)chY_Array[chDot_Counter+1]);
    }
}



⌨️ 快捷键说明

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