Beruflich Dokumente
Kultur Dokumente
int main()
{
//initilizing graphic mode and
//graphic driver variable
int graphicdriver=DETECT,graphicmode;
initwindow(800,800);
putpixel(100,200,3);
getch();
}
Output:
Question No 2: Get X coordinates using computer graphics programming.
Answer:
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
char arr[100];
// moveto function
moveto(150, 100);
sprintf(arr, "Current position of x = %d",
getx());
// outtext function displays text at
// current position.
outtext(arr);
getch();
return 0;
}
OutPut:
Question No 3: Get Y coordinates in computer graphics
Answer:
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
char arr[100];
// moveto function
moveto(100, 150);
sprintf(arr, "Current position of y = %d",
gety());
getch();
return 0;
}
Output:
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
char arr[100];
getch();
return 0;
}
OutPut:
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
char arr[100];
getch();
return 0;
}
OutPut:
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
initwindow(800,800);
int x=10, y=10;
int font= 7, direction= 1;
int font_size= 18;
settextstyle(font, direction, font_size);
outtextxy(x,y,"Yamna");
getch();
closegraph();
return 0;
}
Output:
Question No 7: Set font color in computer graphics
Answer:
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
delay(500);
}
delay(2000);
}
// driver program
int main()
{
printMsg();
}
OutPut:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
char msg[80];
errorcode = graphresult();
getch();
}
/* maximum color index supported */
maxcolor = getmaxcolor();
settextjustify(CENTER_TEXT, CENTER_TEXT);
x = getmaxx() / 2;
y = getmaxy() / 2;
cleardevice();
setbkcolor(bkcol);
/* output a messsage */
if (bkcol == WHITE)
setcolor(BLUE);
outtextxy(x, y, msg);
getch();
}
/* clean up */
closegraph();
return 0;
}
OutPut:
Question No 9: Get back ground color in computer
Answer:
#include <graphics.h>
#include <stdio.h>
// driver code
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
char arr[100];
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system .
closegraph();
return 0;
}
OutPut:
// driver code
int main()
{
// gm is Graphics mode which is a computer display
// mode that generates image using pixels.
// DETECT is a macro defined in "graphics.h" header file
int gd = DETECT, gm;
getch();
//driver code
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
// circle function
circle(350, 300, 150);
getch();
return 0;
}
OutPut:
Question No 13: Set font-style in computer graphics
Answer:
#include <graphics.h>
// driver code
int main()
{
// font style
int font = 8;
// font direction
int direction = 0;
// font size
int font_size = 5;
// for setting text style
settextstyle(font, direction, font_size);
getch();
closegraph();
return 0;
}
OutPut:
// driver code
int main()
{
// location of text
int x = 150;
int y = 150;
// font style
int font = 7;
// font direction
int direction = 1;
// font size
int font_size = 5;
// for setting text style
settextstyle(font, direction, font_size);
getch();
closegraph();
return 0;
}
OutPut:
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
getch();
closegraph();
}
OutPut:
int main()
{
// gm is Graphics mode which is a computer display
// mode that generates image using pixels.
// DETECT is a macro defined in "graphics.h" header file
int gd = DETECT, gm;
// location of ellipse
int x = 250, y = 200;
// ellipse function
ellipse(x, y, start_angle,
end_angle, x_rad, y_rad);
getch();
closegraph();
return 0;
}
OutPut:
// Driver code
int main()
{
int gd = DETECT, gm;
// rectangle function
rectangle(left, top, right, bottom);
getch();
closegraph();
}
OutPut:
Question No 19: Draw a circle with color in computer graphics
Answer:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int main()
{
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
setfillstyle(CLOSE_DOT_FILL,GREEN);
circle(200,200,100);
floodfill(202,202,15);
getch();
closegraph();
}
OutPut:
// Driver Code
int main()
{
getch();
closegraph();
}
OutPut:
Question No 22: Draw a moving cycle in Computer graphics
Answer:
#include<graphics.h>
#include<conio.h>
#include<dos.h>
int main()
{
initwindow(800,800);
line(0,435,800,435);
for(int i=0;i<800;i=i+10)
{
setcolor(WHITE);
line(50+i,405,100+i,405);
line(75+i, 375, 125+i, 375);
line(50+i, 405, 75+i, 375);
line(100+i,405,125+i,375);
line(150+i,405,100+i,345);
line(75+i,375,75+i,370);
line(70+i,370,80+i,370);
line(80+i,345,100+i,345);
circle(150+i,405,30);
circle(50+i,405,30);
delay(100);
setcolor(BLACK);
line(50+i,405,100+i,405);
line(75+i, 375, 125+i, 375);
line(50+i, 405, 75+i, 375);
line(100+i,405,125+i,375);
line(150+i,405,100+i,345);
line(75+i,375,75+i,370);
line(70+i,370,80+i,370);
line(80+i,345,100+i,345);
circle(150+i,405,30);
circle(50+i,405,30);
}
getch();
closegraph();
}
OutPut:
Question No 23: Draw a moving car in computer graphics
Answer:
#include <graphics.h>
#include <stdio.h>
delay(100);
getch();
closegraph();
}
// Driver code
int main()
{
draw_moving_car();
return 0;
}
OutPut:
Question No 24: Draw hut in computer graphics
Answer:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setcolor(5);
rectangle(60,80,150,200);
rectangle(95,140,120,200);
line(60,80,100,15);
line(100,15,150,80);
circle(100,60,10);
getch();
closegraph();
}
OutPut: