C++ Program for Animated Traffic Light Signal

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();

  
 
}
reecry

Share
Published by
reecry

Recent Posts

Insta360 – Videos keep exporting backwards | Wrong side render in insta360

https://youtu.be/0RRUOIvmuWA I realized that I had my camera set up incorrectly, so when I upload…

8 months ago

Make Animated progress step bar using Figma

https://youtu.be/C3oFfV20K_c Make Animated progress step bar using Figma

9 months ago

How to Hide All Grids in Figma

https://youtu.be/o3pSH_oRzko How to Hide All Grids in Figma

9 months ago

How to Create Responsive Tool tip in figma

https://youtu.be/hdSUylKSsho How to Create Responsive Tool tip in Figma

9 months ago

Pixel Grid not visible in figma | How to Turn on figma Pixel Grid

https://youtu.be/AEiH7dSDhKo Having issue in figma pixel grid? learn how to show/ hide figma pixel grid…

9 months ago

Fix External Monitor Lag on Mac OS Ventura

https://youtu.be/iilYzHg9LwQ There are some issues going on in ventura OS its still in development phase…

1 year ago