Draw a house using display file concept in computer graphics


 Display File Concept


draw a house using display file concept in computer graphics,draw a house using display file concept in c graphics,display file concept,display file,display file in computer graphics,display file in c graphics

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<graphics.h>

#include<string.h>

#define r(a) (a+0.5)

#define size 35


int gdriver=DETECT, gmode;

float df_penx, df_peny, frame_penx, frame_peny, df_op[size], df_x[size], df_y[size];

float hs, he, h, we, ws, w, x, y;

int op,fre,erase_flag=0, x1, y1, n;


void new_frame();

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

void display_file(int op);

void move_abs(float x, float y);

void line_abs(float dx, float dy);

void house();

void getpoint(int n);

void domove(float x, float y);

void doline(float x, float y);

void interpret(int s, int count);

void make_pic();

void bresenham(int xa, int ya, int xb, int yb);

float max(float a, float b);

float min(float a, float b);

void erase();

void initialize();


void main()

{

clrscr();

initgraph(&gdriver, &gmode, "C:\\Turboc3\\BGI");

setcolor(WHITE);

initialize();

new_frame();

move_abs(0.3, 0.2);

house();

make_pic();

getch();

}


void initialize()

{

fre=0;

df_penx=0;

df_peny=0;

frame_penx=0;

frame_peny=0;

hs=0;

he=getmaxy();

h=he-hs;

ws=0;

we=getmaxy();

w=we-ws;

}


void move_abs(float x, float y)

{

df_penx=x;

df_peny=y;

display_file(1);

}


void display_file(int op)

{

putpoint(op, df_penx, df_peny);

}


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

{

if(fre>size)

printf("Display file full...");

else

{

df_op[fre]=op;

df_x[fre]=x;

df_y[fre]=y;

fre++;

}

}


void house()

{

line_abs(0.9, 0.2);//-

line_abs(1, 0.4);

line_abs(0.2, 0.4);

line_abs(0.3, 0.2);

move_abs(0.2, 0.4);

line_abs(0.23, 0.43);

line_abs(0.97, 0.43);

line_abs(1, 0.4);

move_abs(0.25, 0.43);

line_abs(0.25, 0.8);

line_abs(0.95, 0.8);

line_abs(0.95, 0.43);

move_abs(0.37, 0.8);

line_abs(0.37, 0.55);

line_abs(0.53, 0.55);

line_abs(0.53, 0.8);

move_abs(0.37, 0.55);

line_abs(0.47, 0.57);

line_abs(0.47, 0.8);

move_abs(0.35, 0.8);

line_abs(0.35, 0.83);

line_abs(0.57, 0.83);

line_abs(0.57, 0.8);

move_abs(0.87, 0.7);

line_abs(0.7, 0.7);

line_abs(0.7, 0.55);

line_abs(0.87, 0.55);

line_abs(0.87, 0.7);

move_abs(0.785, 0.55);

line_abs(0.785, 0.7);

move_abs(0.87, 0.625);

line_abs(0.7, 0.625);

}


void line_abs(float dx, float dy)

{

df_penx=dx;

df_peny=dy;

display_file(2);

}


void make_pic()

{

if(erase_flag==1)

{

erase();

erase_flag=0;

}

if(fre>1)

interpret(0, fre-1);

fre=0;

}


void interpret(int s, int count)

{

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

{

getpoint(n);

if(op==1)

domove(x, y);

else if(op==2)

doline(x, y);

else

printf("Wrong OPCode...");

}

}


void getpoint(int n)

{

op=df_op[n];

x=df_x[n];

y=df_y[n];

}


void domove(float x, float y)

{

float p1, q1;

p1=min(we, (x*w+ws));

q1=min(he, (y*h+hs));

frame_penx=max(ws, p1);

frame_peny=max(hs, q1);

}


void doline(float x, float y)

{

float p1, q1;

p1=min(we, (x*w+ws));

q1=min(he, (y*h+hs));

x1=frame_penx;

y1=frame_peny;

frame_penx=max(ws, p1);

frame_peny=max(hs, q1);

bresenham(r(x1), r(y1), r(frame_penx), r(frame_peny));

}


float max(float a, float b)

{

if(a>b)

return (a);

else

return (b);

}

float min(float a, float b)

{

if(a<b)

return (a);

else

return (b);

}


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

{

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

float m;

dx=abs(xa-xb);

dy=abs(ya-yb);

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


if(dx>dy)

{

p=2*dy-dx;

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, 3);


while(x<xend)

{

x++;

if(p<0)

p=p+twody;

else

{

if(0<m && m<1)

y++;

else

y--;

p=p+twodydx;

}

    // delay(10);

putpixel(x, y, 3);

}

}

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, 3);


while(y<yend)

{

y++;

if(p<0)

p=p+twodx;

else

{

if(m>=1)

x++;

else

x--;

p=p+twodxdy;

}

      // delay(10);

putpixel(x, y, 3);

}

}

}


void new_frame()

{

erase_flag=1;

}


void erase()

{

int j;

for(n=1;n<we+1;n++)

for(j=1;j<he+1;j++)

putpixel(n, j, 0);

}

Polygon Relative In Computer Graphics 

Draw a cube using display file in computer graphics

Comment your views on this Article :)


Thank you for visiting my blog :)


1 comment:

  1. Excellent post. You have shared some wonderful tips. I completely agree with you that it is important for any blogger to help their visitors. Once your visitors find value in your content, they will come back for more concept of computer graphics



    ReplyDelete

Comment your views on this article

Powered by Blogger.