Computer Graphics Lab Programs

Embed Size (px)

Citation preview

Digital Differential Analyzer(D.D.A.) AlgorithmVoid Line_DDA(int x1, int y1, int x2, int y2) { int dx = x2-x1; int dy = y2-y1; int step,k; float x_inc,y_inc,x,y; x=x1; y=y1; if(abs(dx)>abs(dy)) step=abs(dx); else step=abs(dy); x_inc=dx/(float)step; y_inc=dy/(float)step; setpixel(ROUND(x),ROUND(y)); for(k=0;kabs(dy)) { step=abs(dx); } else { step=abs(dy); }

x_inc=dx/(float)step; y_inc=dy/(float)step; putpixel(ROUND(x),ROUND(y),6); for(k=0;k((int)x+0.5)) { y=floor(x); } if(x x2) { x=x1; y=y1; x_end=x1; } else { x=x1; y=y1; x_end=x2; } setpixel(x,y,1); while(x < x_end) { x=x+1; if(px2) { x=x2; y=y2; x_end=x1; }

else { x=x1; y=y1; x_end=x2; } putpixel(x,y,1); while(x