Draw A Polygon Object Using Polygon Relative In Computer Graphics


 Polygon Relative  


polygon relative in c graphics,polygon relative in computer graphics,draw a polygon object using display file in computer graphics,draw a polygon object using display file in c graphics,draw a polygon object using polygon relative in computer graphics,draw a polygon object using polygon relative in c graphics

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

#define r(a) (a+0.5)

int free1;

//float ax[]={0.2, 0.2, 0.1, 0.1, 0.4, 0.4, 0.3, 0.3};

//float ay[]={0.1, 0.3, 0.3, 0.4, 0.4, 0.3, 0.3, 0.1};

float ax[]={0.1, 0.1, 0.1, 0.1, 0.1};

float ay[]={0.2, 0.1, -0.1, 0.1, -0.1};

float df_penx, df_peny, frame_penx, frame_peny;

int hs, ws;

int he, df_size=100;

int df_op[20];

float  df_x[20], df_y[20];

int we, op;

float x1, y1;

int h, w;

int gd=DETECT, gm;

void pol_rel(int, float[], float[]);

void putpoint(int, float, float);

void dis_file_enter(int);

void getpoint(int);

void doline(float, float);

void domove(float, float);

void interpret(int, int);

void move_abs(float, float);

//void line_rel(float, float);

void line_abs(float, float);

//void house();

void ini();

//void bre(int, int, int, int);

int min(float, float);

int max(float, float);

void make_pic_current();

void dopoly(float, float);

void dda(int xa, int ya, int xb, int yb)

{

int step, i, dx, dy;

float xincr, yincr, temp, x, y;


dx=xb-xa;

dy=yb-ya;

x=xa;

y=ya;

if(abs(dx) > abs(dy))

{

step=abs(dx);

}

else

{

step=abs(dy);

}

temp=step;

xincr=dx/temp;

yincr=dy/temp;

putpixel(r(x), r(y), 1);

for(i=1;i<step;i++)

{

x+=xincr;

y+=yincr;

putpixel(r(x), r(y), 1);


}



}


void dopoly(float x, float y)

{

domove(x, y);

}

void make_pic_current()

{

if(free1>1)

{

interpret(1, free1-1);

}

free1=1;

}

/*void bre(int xa, int ya, int xb, int yb)

{

int dx, dy, p, xend, yend, twody, twodydx, x, y, twodx, twodxdy ;

float m;

dx=abs(xa-xb);

dy=abs(ya-yb);

m=(float)(yb-ya)/(xb-xa);

if(dx>=dy)

{

p=(2*dy);

twody=2*dy;

twodydx=2*(dy-dx);

if(xa>xb)

{

x=xb;

y=yb;

xend=xa;

}

else

{

x=xa;

y=ya;

xend=xb;


}

putpixel(x, y, 1);

while(x<xend)

{

x++;

if(p<0)

{

p=p+twody;

}

else

{

if(0<m && m<1)

{

y++;

}

else

{

y--;

}

p=p+twodydx;

}

putpixel(x, y, 1);

}


}

else

{

p=(2*dx)-dy;

twodx=2*dx;

twodxdy=2*(dx-dy);

if(ya>yb)

{

x=xb;

y=yb;

yend=ya;

}

else

{

x=xa;

y=ya;

yend=yb;

}

putpixel(x, y, 1);

while(y<yend)

{

y++;

if(p<0)

{

p=p+twodx;

}

else

{

if(m>1)

{

x++;

}

else

{

x--;

}

p=p+twodxdy;

}

putpixel(x, y, 1);


}

}

} */

int max(float n1, float n2)

{

if(n1>n2)

{

return n1;

}

else

return n2;

}

int min(float n1, float n2)

{

if(n1<n2)

{

return n1;

}

else

return n2;

}

void putpoint(int op, float x, float y)

{

if (free1 > df_size)

{

printf("display file full..");

}

df_op[free1]=op;

df_x[free1]=x;

df_y[free1]=y;

free1++;

}

void ini()

{

free1=1, df_penx=0, df_peny=0, frame_penx=0; frame_peny=0;

hs=0, ws=0;

he=479;

we=639;

h=he-hs;

w=we-ws;

}

void dis_file_enter(int op)

{

putpoint(op, df_penx, df_peny);

}

void move_abs(float x1, float y1)

{

df_penx=x1;

df_peny=y1;

dis_file_enter(1);

}

void line_rel(float dx, float dy)

{

df_penx+=dx;

df_peny+=dy;

dis_file_enter(2);

}

void getpoint(int n)

{

op=df_op[n];

x1=df_x[n];

y1=df_y[n];

}

void interpret(int start, int count)

{

int n;

for(n=start;n<=count;n++)

{

getpoint(n);

{

if(op==1)

{

domove(x1, y1);


}

else if(op==2)

{

doline(x1, y1);

}

else

{

dopoly(x1, y1);

}

}

}

}

void domove(float xx, float yy)

{

frame_penx=max(ws, min(we,xx*w+ws));

frame_peny=max(hs, min(he,yy*h+hs));

}

void doline(float xx, float yy)

{

int x1, y1;

x1=frame_penx;

y1=frame_peny;

frame_penx=max(ws, min(we,xx*w+ws));

frame_peny=max(hs, min(he,yy*h+hs));

/* x1+=0.5;

y1+=0.5;

frame_penx+=0.5;

frame_peny+=0.5;

  */ dda(x1, y1, frame_penx, frame_peny);

}

void poly_rel(int no, float a[], float b[])

{

int i;

float tmpx, tmpy;

if(no<3)

{

printf("Wrong polygon sides ..");

}

df_penx+=a[0];

df_peny+=b[0];

tmpx=df_penx;

tmpy=df_peny;


dis_file_enter(no);

for(i=1;i<=no-1;i++)

{

line_rel(a[i], b[i]);

}

line_abs(tmpx, tmpy); // line_abs(ax[0], ay[0]);

}

void line_abs(float x, float y)

{

df_penx=x;

df_peny=y;

dis_file_enter(2);

}

void main()

{

clrscr();

ini();

initgraph(&gd, &gm, "c:\\turboc3\\bgi");

poly_rel(5, ax, ay);

make_pic_current();

getch();

}

Text Generation Program In C Graphics

Draw a house using display file in C graphics 

Comment your views on this Article :)


Thank you for visiting my blog :)


No comments

Comment your views on this article

Powered by Blogger.