Question: Matlab Programming, basically make a traffic simulation using imagesc, the requirements are stated below. Ex. 1Cross road traffic game At a cross road cars are
Matlab Programming, basically make a traffic simulation using imagesc, the requirements are stated below. 

Ex. 1Cross road traffic game At a cross road cars are either moving if the light is green or waiting if it is red. A road is composed of two lanes, for cars going in opposite directions while the light is located on the right hand side of the cars, before the cross. Moving cars are all going at a same constant speed of one unit every second. A snapshot of the scenario at a time t is shown on Figure 1. On the picture three cars are going from top to bottom but are waiting as the traffic light is red. In the meantime five cars going from right to left are crossing, while two other cars are coming from the opposite direction. The two last cars can be seen coming from the bottom but have not yet arrived at the cross road. Requirement for the above scenario: . The user inputs n, the total number of cars, w the width of the crossroad, p the prob- ability that a cars does not stop at the red light, and t the probability for a car to turn left of right: The number of cars on each line is randomly decided with respect to . The color cycle of a traffic light is green for g s, orange for o s, and red for r s: The user sets the value of the variables g, o, and r Lights in the diagonal of the cross road have a same color Each time a light changes from green to orange the cars before the light stop and the ones which have already passed it finish crossing: e.g. on Fig. 1 if the green light be- comes orange then the two cars in the middle of the cross should reach the other side before the red light turns green; Figure 1: Traffic at a cross road. e Cars should appear at the beginning of the road with respect to where they come from; e.g. a car coming from the right should start from the right most edge of the figure; Every second all the non-waiting cars move by one unit: The goal is to animate the displacement of the cars with respect to the traffic lights. The choice of the user will impact the risk for a car crash to happen. The animation stops as soon a crash occurs and the player loses. If all the cars have gone through without any problem the player wins. Ex. 1Cross road traffic game At a cross road cars are either moving if the light is green or waiting if it is red. A road is composed of two lanes, for cars going in opposite directions while the light is located on the right hand side of the cars, before the cross. Moving cars are all going at a same constant speed of one unit every second. A snapshot of the scenario at a time t is shown on Figure 1. On the picture three cars are going from top to bottom but are waiting as the traffic light is red. In the meantime five cars going from right to left are crossing, while two other cars are coming from the opposite direction. The two last cars can be seen coming from the bottom but have not yet arrived at the cross road. Requirement for the above scenario: . The user inputs n, the total number of cars, w the width of the crossroad, p the prob- ability that a cars does not stop at the red light, and t the probability for a car to turn left of right: The number of cars on each line is randomly decided with respect to . The color cycle of a traffic light is green for g s, orange for o s, and red for r s: The user sets the value of the variables g, o, and r Lights in the diagonal of the cross road have a same color Each time a light changes from green to orange the cars before the light stop and the ones which have already passed it finish crossing: e.g. on Fig. 1 if the green light be- comes orange then the two cars in the middle of the cross should reach the other side before the red light turns green; Figure 1: Traffic at a cross road. e Cars should appear at the beginning of the road with respect to where they come from; e.g. a car coming from the right should start from the right most edge of the figure; Every second all the non-waiting cars move by one unit: The goal is to animate the displacement of the cars with respect to the traffic lights. The choice of the user will impact the risk for a car crash to happen. The animation stops as soon a crash occurs and the player loses. If all the cars have gone through without any problem the player wins
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
