Cpp Programs

November 12, 2016 | Author: satish kulkarni | Category: N/A
Share Embed Donate


Short Description

graphics prg...

Description

Draw a line using DDA Line Drawing Algorithm. Hardik H Hadvani on 00:01 1 comments

Write a program to draw a line using DDA Line DrawingAlgorithm. (A)Center Line (B)Dotted Line Friends this program is for the draw a line using dda line drawing algorithm using center line or dotted line both code are given to you as follows.This program is usually used in the computer graphic and it is run in the turbo c. I hope this code is very true and if any kindly request please replay me on email.

(A)Center Line

#include #include #include void main() { int gd=DETECT,gm,xa,xb,ya,yb,i; double xin,yin,dx,dy,x,y,steps; clrscr(); initgraph(&gd,&gm,""); printf("Enter Xa="); scanf("%d",&xa); printf("Enter Ya="); scanf("%d",&ya);

printf("Enter Xa="); scanf("%d",&xb); printf("Enter Yb="); scanf("%d",&yb); cleardevice(); if(xb>xa) dx=xb-xa; else dx=xa-xb; if(yb>ya) dy=yb-ya; else dy=ya-yb; if(dx>dy) steps=dx; else steps=dy; xin=dx/steps; yin=dy/steps; x=xa;y=ya; for(i=0;ixa) dx=xb-xa; else dx=xa-xb;

if(yb>ya) dy=yb-ya; else dy=ya-yb; if(dx>dy) steps=dx; else steps=dy; xin=dx/steps; yin=dy/steps; x=xa;y=ya; for(i=0;i\" Sutherland-Cohen \""; coutxIntersectxIntersect) p=NULL; else { q=p; p=p->next; } } edge->next=q->next; q->next=edge; } /*************************************************************************///-------------------------- makeEdgeRec( ) -------------------------///*************************************************************************/void makeEdgeRec(const PointCoordinates lower,const PointCoordinates upper, constint yComp,Edge *edge,Edge *edges[]) { edge->dxPerScan=((upper.x-lower.x)/(upper.y-lower.y)); edge->xIntersect=lower.x; if(upper.yyUpper=(upper.y-1); else edge->yUpper=upper.y; insertEdge(edges[lower.y],edge); } /*************************************************************************///-------------------------- buildEdgeList( ) -----------------------///*************************************************************************/void buildEdgeList(constint cnt,const PointCoordinates pts[],Edge *edges[]) { Edge *edge; PointCoordinates v1; PointCoordinates v2; int yPrev=(pts[cnt-2].y); v1.x=pts[cnt-1].x; v1.y=pts[cnt-1].y; for(int count=0;countnext; insertEdge(active,p); p=q; } } /*************************************************************************///--------------------------- fillScan( ) ---------------------------///*************************************************************************/void fillScan(constint scan,const Edge *active,constint fill_color) { Edge *p1; Edge *p2; p1=active->next; while(p1) { p2=p1->next; for(int count=p1->xIntersect;countxIntersect;count++) putpixel(count,scan,fill_color); p1=p2->next; } } /*************************************************************************///------------------------ deleteAfter( ) ---------------------------///*************************************************************************/void deleteAfter(Edge * q) {

Edge *p=q->next; q->next=p->next; delete p; } /*************************************************************************///------------------------ updateActiveList( ) ----------------------///*************************************************************************/void updateActiveList(constint scan,Edge *active) { Edge *q=active; Edge *p=active->next; while(p) { if(scan>=p->yUpper) { p=p->next; deleteAfter(q); } else { p->xIntersect=(p->xIntersect+p->dxPerScan); q=p; p=p->next; } } } /*************************************************************************///------------------------ resortActiveList( ) ----------------------///*************************************************************************/void resortActiveList(Edge *active) { Edge *q; Edge *p=active->next; active->next=NULL; while(p) { q=p->next; insertEdge(active,p); p=q; } } /*************************************************************************///---------------------------- Polygon( ) ---------------------------///*************************************************************************/void Polygon(constint n,constint coordinates[]) { if(n>=2) { Line(coordinates[0],coordinates[1], coordinates[2],coordinates[3]);

for(int count=1;countx_2) { x1=x_2; y1=y_2; x2=x_1; y2=y_1; } int dx=abs(x2-x1); int dy=abs(y2-y1); int inc_dec=((y2>=y1)?1:-1); if(dx>dy) { int two_dy=(2*dy); int two_dy_dx=(2*(dy-dx)); int p=((2*dy)-dx); int x=x1; int y=y1; putpixel(x,y,color); while(x
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF