C++ Program for Animated Traffic Light Signal

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Here you will learn about how to create c++ program for animated traffic light signal, Its very easy to create you just need some knowledge of basic C++ graphics if you don’t have any knowledge of it and wanna to learn them don’t worry we have covered all the topics of c++ graphics you can watch those tutorials. Check C/C++ Graphics Tutorials

Below we have provide you tutorial of animated traffic light signal with the source code.

Tutorial

What functions are used to created this animated program :

  • circle function is used to create circles of traffic signal.
  • rectangle function is used to create box which contains all the circles.
  • For colors floodfill() and setfillstyle() is used.
  • For adding animation delay() is used.

If you don’t know any of these functions how they work don’t worry these are covered in are playlist its free to learn from there Check C/C++ Graphics Tutorials

Source Code for Animated Traffic light Signal

#include<iostream>
#include<graphics.h>
main()
{


		initwindow(800, 800);
		
		rectangle(250, 50, 350, 350);
		
		circle(300, 100, 50);
		circle(300, 200, 50);
		circle(300, 300, 50);
		
		//creating animation
		for(int i =0; i < 10; i++){
			
			setfillstyle(1, RED);
			floodfill(300, 100, WHITE);
			outtextxy(280, 100, "STOP");
			delay(1000);
			
			
			
			setfillstyle(1, BLACK);
			floodfill(300, 100, WHITE);
			setfillstyle(1, YELLOW);
			floodfill(300, 200, WHITE);
			outtextxy(280, 200, "HOLD");
			delay(1000);
			
			
			setfillstyle(1, BLACK);
			floodfill(300, 200, WHITE);
			setfillstyle(1, GREEN);
			floodfill(300, 300, WHITE);
			outtextxy(280, 300, "GO");
			delay(1000);
			
			setfillstyle(1, BLACK);
			floodfill(300, 300, WHITE);
			
			
		}
		
		
		
		getch();
		closegraph();

		
	
}

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore