欢迎来到天天文库
浏览记录
ID:61022057
大小:93.50 KB
页数:3页
时间:2021-01-20
《easy x实现Bresenham画线算法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Easyx实现Bresenham画线算法drawLine.h:/****/#include//四舍五入inlineintround(constfloata){return(int)(a+0.5);}//bresenhamdrawlinevoiddrawLine_Bresenham(intxFirst,intyFirst,intxEnd,intyEnd,intcolor){intdx=abs(xEnd-xFirst),dy=abs(yEnd-yFirst);intp=2*dy-dx;inttwoDy=2*dy,twoDyMinusDx=2*(dy-dx)
2、;intx,y;/*Determinewhichendpointtouseasstartposition.*/if(xFirst>xEnd){x=xEnd;y=yEnd;xEnd=xFirst;}//end(xFirst>xEnd)else{x=xFirst;y=yFirst;}//endelse//在坐标(x,y)处画一个颜色为color的点putpixel(x,y,color);while(x3、lor);}//endwhile(x#include"drawLine.h"#ifndef_DRAWLINE_H#define_DRAWLINE_Hvoidmain(){initgraph(640,480);//输出提示信息TCHARnotice1[]=_T("Notice:");TCHARnotice2[]=_T("Green:DDADrawLine");TCHARnotice3[]=_T("Yellow:BresenhamDrawLine");sette4、xtcolor(BLUE);outtextxy(400,10,notice1);outtextxy(400,30,notice2);outtextxy(400,50,notice3);//DDA画线//drawLine_DDA(50,100,600,200,GREEN);//bresenham画线drawLine_Bresenham(50,150,600,300,YELLOW);//按任意键退出getch();//关闭图形库closegraph();}//endmain()method#endif运行结果:
3、lor);}//endwhile(x#include"drawLine.h"#ifndef_DRAWLINE_H#define_DRAWLINE_Hvoidmain(){initgraph(640,480);//输出提示信息TCHARnotice1[]=_T("Notice:");TCHARnotice2[]=_T("Green:DDADrawLine");TCHARnotice3[]=_T("Yellow:BresenhamDrawLine");sette
4、xtcolor(BLUE);outtextxy(400,10,notice1);outtextxy(400,30,notice2);outtextxy(400,50,notice3);//DDA画线//drawLine_DDA(50,100,600,200,GREEN);//bresenham画线drawLine_Bresenham(50,150,600,300,YELLOW);//按任意键退出getch();//关闭图形库closegraph();}//endmain()method#endif运行结果:
此文档下载收益归作者所有