Draw A Unique House In Computer Graphics Using C Language
Unique House
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define round(a) (a+0.5)
int gdriver=DETECT,gmode;
void dda();
void midpoint_circle(int xc,int yc,int r){
int x=0;
int y=r;
int d=1-r;
draw_circle(xc,yc,x,y);
while(x<y){
x++;
if(d<0){
d=d+2*x+1;
}
else{
y--;
d=d+2*(x-y)+1;
}
draw_circle(xc,yc,x,y);
}
}
int draw_circle(int x0,int y0,int x,int y){
putpixel (x0+x, y0+y, 2);
putpixel (x0+y, y0+x, 2);
putpixel (x0-y, y0+x, 2);
putpixel (x0-x, y0+y, 2);
putpixel (x0-x, y0-y, 2);
putpixel (x0-y, y0-x, 2);
putpixel (x0+y, y0-x, 2);
putpixel (x0+x, y0-y, 2);
return 0;
}
void main()
{
clrscr();
initgraph(&gdriver, &gmode, "C:\\Turboc3\\BGI");
dda (200, 50, 400, 50);
dda (200, 50, 150, 200);
dda (400, 50, 450, 200);
dda (150, 200, 450, 200);
dda (150, 200, 160, 210);
dda (450, 200, 440, 210);
dda (160, 210, 440, 210);
dda (180, 210, 180, 400);
dda (420, 210, 420, 400);
dda (180, 400, 420, 400);
dda (215, 380, 215, 270);
dda (215, 270, 275, 270);
dda (275, 270, 275, 380);
midpoint_circle (265, 330, 5);
dda (205, 380, 285, 380);
dda (205, 380, 205, 400);
dda (285, 380, 285, 400);
dda (195, 400, 195, 420);
dda (295, 400, 295, 420);
dda (195, 420, 295, 420);
dda (300, 270, 400, 270);
dda (300, 270, 300, 350);
dda (300, 350, 400, 350);
dda (400, 350, 400, 270);
dda (395, 345, 395, 275);
dda (395, 345, 305, 345);
dda (305, 345, 305, 275);
dda (305, 275, 395, 275);
dda (350, 275, 350, 345);
dda (305, 310, 395, 310);
dda (250, 115, 250, 175);
dda (250, 175, 350, 175);
dda (350, 175, 350, 115);
dda (300, 75, 225, 135);
dda (300, 75, 375, 135);
dda (300, 70, 375, 130);
dda (375, 135, 375, 130);
dda (300, 70, 225, 130);
dda (225, 130, 225, 135);
midpoint_circle (300, 130, 30);
dda (300, 100, 300, 160);
dda (270, 130, 330, 130);
getch();
}
void dda(int xa,int ya,int xb,int yb)
{
float x,y,xincr,yincr;
int dy,dx,steps,i;
dx=xb-xa;
dy=yb-ya;
x=xa;
y=ya;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xincr=dx/(float)steps;
yincr=dy/(float)steps;
putpixel(round(x),round(y),2);
for(i=1;i<=steps;i++)
{
x+=xincr;
y+=yincr;
putpixel(round(x),round(y),2);
}
}
Know more about Display File In Computer Graphics
Draw all types and styles of lines in c graphics
Comment your views for this Article :)
No comments
Comment your views on this article