C graphics program for traffic light simulation

Description:

  1. Use turbo C++ editor to write the program
  2. Give the path of BGI, where the BGI stored in your computer in initgraph function like initgraph(&gd,&gm,”C:\\Turboc3\\BGI”);
  3. Write the logic for traffic light simulation

Using functions of graphics.h in Turbo C compiler you can make graphics programs, animations, projects, and games. We can draw circles, lines, rectangles, bars and many other geometrical figures.

				
					#include<graphics.h> 
#include<conio.h> 
#include<dos.h> 
#include<stdlib.h> 
main() 
{ 
int gd = DETECT, gm, midx, midy; 
initgraph(&gd, &gm, "C:\\Turboc3\\BGI"); 
midx = getmaxx()/2;
midy = getmaxy()/2; 
setcolor(RED); 
settextstyle(SCRIPT_FONT, HORIZ_DIR, 3); 
settextjustify(CENTER_TEXT, CENTER_TEXT); 
outtextxy(midx, midy-10, "Traffic Light Simulation program"); 
outtextxy(midx, midy+10, "Press any key to start the simulation"); 
getch(); 
cleardevice();
setcolor(WHITE); 
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1); 
rectangle(midx-30,midy-80,midx+30,midy+80); 
circle(midx, midy-50, 22); setfillstyle(SOLID_FILL,RED); 
floodfill(midx, midy-50,WHITE); 
setcolor(BLUE); 
outtextxy(midx,midy-50,"STOP"); 
delay(2000); 
graphdefaults(); 
cleardevice();
setcolor(WHITE); 
rectangle(midx-30,midy-80,midx+30,midy+80); 
circle(midx, midy, 20); 
setfillstyle(SOLID_FILL,YELLOW); 
floodfill(midx, midy,WHITE); 
setcolor(BLUE); 
outtextxy(midx-18,midy-3,"READY"); 
delay(2000); 
cleardevice(); 
setcolor(WHITE); 
rectangle(midx-30,midy-80,midx+30,midy+80); 
circle(midx, midy+50, 22); 
setfillstyle(SOLID_FILL,GREEN); 
floodfill(midx, midy+50,WHITE); 
setcolor(BLUE); 
outtextxy(midx-7,midy+48,"GO"); 
setcolor(RED); 
settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); 
outtextxy(midx-150, midy+100, "Press any key to exit from program"); 
getch(); 
closegraph(); 
return 0;
}
				
			

Leave a Reply