Professional Documents
Culture Documents
CS&P Project Traffic Light
CS&P Project Traffic Light
PROGRAMMING PROJECT
Submitted by:
Submitted to:
Engr. Farhan Khan
Traffic Control Signal Simulation
Abstract
The traffic control signal simulation when combined with real data makes one of
the best tools for research into optimization of traffic management. In this
project, a traffic control system simulated model is created by a program that
mimics red, yellow, and green lights of traffic signal. The program utilizes
various codes and graphic library for the simulation purpose can create a traffic
schedule for help in the movement of vehicles at on the road. The red, yellow,
and green lights come on one by one within 10 seconds of each other and the
timing may also be delayed by altering the code. This program provides the way
to control the movement of traffic automatically as the sequence repeats
automatically at the end of each cycle (i.e., Red, Yellow, Green) using increment
command. The number of times to allow sequence to repeat can also be altered
based on the requirements. The following data shown in Table 1, will be handled
by the computer program.
Introduction
Computers can use graphics.h to offer direct functions for drawing various
coordinates, such as circles, rectangles, etc. These shapes can be used to draw a
variety of items. This project focuses on creating a traffic light simulation in DEV
C++ by leveraging the graphics.h library and a variety of functions. A high-level
object-oriented programming language called C++ aids developers in creating
quick, adaptable program. Most other programming languages are slower than
C++. Because of this, it can be effective in settings where server speed is very
important, including web servers and database servers. In comparison to the
majority of other programming languages like Python, etc., C++ is also closer to
2
hardware. This makes it beneficial in situations where software and hardware
are closely integrated, and low-level software assistance is necessary.
#include<graphics.h>
#define BLUE 1
#define GREEN 2
#define CYAN 3
#defineRED 4
#define PURPLE 5
#define LIGHT_GRAY 7
#define GRAY 8
#define LIGHT_BLUE 9
#define LIGHT_GREEN 10
#define LIGHT_CYAN 11
#define LIGHT_RED 12
#define PINK 13
#define MAGENTA 13
#define LIGHT_YELLOW 14
void Color(int textColor, int bgColor)//Void functions are created and used just like
value-returning functions except they do not return a value after the function executes.
void color for background color and text color
3
//GetStdHandle function returns a handle to the standard device (input, output, or
error). A handle is an index in the system table which gives access to the Windows
kernel object
int main()
{int start;
system("color E1");
Color(GREEN,LIGHT_YELLOW);
Color(GREEN,LIGHT_YELLOW);
Color(LIGHT_BLUE,LIGHT_YELLOW);
Color(RED,LIGHT_YELLOW);
Color(BLUE,LIGHT_YELLOW);
Color(BLUE,LIGHT_YELLOW);
Color(BLUE,LIGHT_YELLOW);
Color(BLACK,LIGHT_YELLOW);
cout<<"ASSALAM-O-ALAIKUM!"<<'\n';
cout<<"We have Created This New Project, We Hope You Will Like This. . ."<<'\n';
Color(RED,LIGHT_YELLOW);
cout<<"In This Project Lights Turn ON and OFF Automatically After Each Ten Seconds";
4
rectangle(250, 50, 350, 350);//define position of rectangle
//creating animation
for(int i =0; i < 10; i++)//runs the traffic light sequence 10 times
floodfill(300, 100, WHITE);//Stops red color going outside circle white border
setfillstyle(1, BLACK);
setfillstyle(1, YELLOW);
delay(10000);
setfillstyle(1, GREEN);
delay(10000);
}}
5
The Python Code
root = Tk() #It helps to display the root window and manages all the
other components of the tkinter application.
6
while True: #They are used to repeat a sequence of statements an
unknown number of times.
canvas.itemconfig(yellow_light, fill="black")
canvas.itemconfig(green_light, fill="black")
canvas.itemconfig(red_light, fill="black")
canvas.itemconfig(yellow_light, fill="yellow")
canvas.itemconfig(green_light, fill="black")
root.update()
time.sleep(10)
canvas.itemconfig(red_light, fill="black")
canvas.itemconfig(yellow_light, fill="black")
canvas.itemconfig(green_light, fill="green")
root.update()
time.sleep(10)
7
for events from the user, until the user exits the program – either
by closing
3. Using canva for drawing graphical objects like oval,rectangle and defining
their positions.
8
successful. The program seems to be suitable for developing graphics as well as
code for actual traffic light signal. Further research in this area may lead to the
development of Traffic light signal that can help authority manage road traffic
much efficiently. Hence there is room for more research in this area.
9
10
Python Output Result:
11
Conclusion
To experience the utility of the C++ and Python language, a traffic control signal
application was created in this project and run in DEVC++. One of the most
significant programming languages is C++ and Python since it can be used to
create similar but more sophisticated programs like Windows, photo editing
software, video games, and web browsers. And almost all the programs/systems
that we use have some or the other part of the codebase that is written in C/C++
or Python. Hence it is concluded that Python and C++ plays an integral role in
almost all applications that we use.
The End
12