Thursday , September 21 2017
Home / C / Program in C to draw a House

Program in C to draw a House

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(3);
line(100,200,300,200);

line(100,400,300,400);

line(100,400,100,200);

line(300,400,300,200);

line(300,200,500,200);

line(300,400,500,400);

line(500,200,500,400);

line(170,250,270,250);

line(170,200,270,200);

line(170,250,170,400);

line(270,250,270,400);

line(200,50,400,50);

line(400,50,500,200);

line(300,200,200,50);

line(100,200,200,50);
getch();
closegraph();
}

OUTPUT:

Tags: Program in C to draw a HOUSE,c graphics program to draw a house, opengl to draw a house with source code

 

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

2 comments

  1. Thejna Harshakumar

    /* Aim : 1. Create the following graphics using simple OpenGL graphics primitives.Display a picture containing a simple house (use glBegin(GL_LINE_LOOP) and glBegin(GL_LINE_STRIP)).
    Author : Thejna Harshakumar
    Date :23/06/17
    */
    #include
    #include
    #include
    #include

    void display(void)
    {
    int x=1280,y=720; /* clear all pixels */
    glClear (GL_COLOR_BUFFER_BIT);
    glClearColor (0,0,0,0); //background color setting

    glMatrixMode(GL_PROJECTION); // Projecting something from buffer to screen
    glLoadIdentity();
    //glOrtho(-1.0, 1.0, -1.0, 1.0,-1.0,1.0);
    //glOrtho(0.0, 1.0, 0.0, 1.0,0.0,1.0);
    gluOrtho2D(0,x,0,y);

    glPointSize(2.0);
    glColor3f(1,1,1);

    glBegin(GL_LINE_LOOP); // square part done with lineloop
    glVertex2i(x/4,100);
    glVertex2i(x/4,400);
    glVertex2i((x*3)/4,400);
    glVertex2i((x*3)/4,100);
    glEnd();
    glBegin(GL_LINE_LOOP); // triangle for top
    glVertex2i((x/4)-70,400);
    glVertex2i(x/2,600);
    glVertex2i(((x*3)/4)+70,400);
    glEnd();
    glBegin(GL_LINE_STRIP); //square for door
    glVertex2i((x/2)+30,100);
    glVertex2i((x/2)+30,300);
    glVertex2i((x/2)-100,300);
    glVertex2i((x/2)-100,100);
    glEnd();
    glBegin(GL_LINES);
    glVertex2i((x/2)-35,100);
    glVertex2i((x/2)-35,300);
    glEnd();

    glBegin(GL_LINE_STRIP); //
    glVertex2i(x/2,600);
    glVertex2i((x/2)+100,620);
    glVertex2i(((x*3)/4)+160,420);
    glVertex2i(((x*3)/4)+70,400);
    glEnd();

    glBegin(GL_LINE_STRIP); //
    glVertex2i(((x*3)/4)+110,410);
    glVertex2i(((x*3)/4)+110,120);
    glVertex2i(((x*3)/4),100);
    glEnd();

    glBegin(GL_LINE_LOOP); // Window
    glVertex2i((x/2)+100,200);
    glVertex2i((x/2)+100,350);
    glVertex2i((x/2)+280,350);
    glVertex2i((x/2)+280,200);
    glEnd();

    glBegin(GL_LINES); // window line inside
    glVertex2i((x/2)+158,200);
    glVertex2i((x/2)+158,350);

    glVertex2i((x/2)+162,200);
    glVertex2i((x/2)+162,350);

    glVertex2i((x/2)+218,200);
    glVertex2i((x/2)+218,350);

    glVertex2i((x/2)+222,200);
    glVertex2i((x/2)+222,350);
    glEnd();

    glColor3f(0,0,1);

    glEnd();
    glFlush ();
    }

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (1280,720);
    glutInitWindowPosition (50,50);
    glutCreateWindow (“Point”);

    glutDisplayFunc(display);

    glutMainLoop();
    return 0;
    }

  2. In output i am getting BGI Error: Graphics not initialized (use ‘initgraph’)

Leave a Reply

Your email address will not be published. Required fields are marked *