- Copy the code in [usage](#usage) to your main.rs
The purpose of this exercise is to create an image like the example bellow:
- Create a module called geometrical_shapes in another file.
![example](image.png)
- This module will keeps all the logic for creating and operating with the different geometrical shapes and define two traits `Displayable` and `Drawable`.
For this exercise you will need to do the following:
- `Drawable` contains the methods `draw` and `color`
- Copy the code in [usage](#usage) to your `main.rs`.
- `Displayable` contains the method `display`.
- Create a module called `geometrical_shapes` in another file.
- Define them in correspondence with the way they're called in the main function
This module will keep all the logic for creating and operating with the different geometrical shapes. You need to define two traits, `Displayable` and `Drawable`.
- You have to define the structures for Point, Circle, Line, Rectangle and Triangle and make the code in `main.rs` compile and run.
- `Drawable` which contains the methods `draw` and `color`.
- You are free to implement all the shapes with the internal structure that you find more adequate, but you have to provide for all the shapes an associated function `new` which will be described next:
- `Displayable` which contains the method `display`.
- Point: a new point should be created from two i32 values
Define them according to the way they are called in the `main.rs` function.
- Line: a new line should be created from references to two points also define an associated function called `random` that receives two argument the first is the maximum x value a point can have and the
second the maximum y value that a point can have
- Triangle: a new triangle should be created from references to three points
- Rectangle: a new rectangle should be created from two references to points
- Circle: a new circle should be created from a point representing the center and an i32 value representing the radius
- The main function also requires a definition of an associated function called `random` for the types Line, Point and Circle. You should derive their signature from the usage.
In order to make the code in the `main.rs` compile and run, you have to define the following structures:
Don't forget to add the dependencies in your Cargo.toml.
- `Point`
- `Circle`
- `Line`
- `Rectangle`
- `Triangle`
#### Bonus
You are free to implement all the shapes with whatever internal structure you see fit, but you must provide an associated function `new` for all the shapes, which will be described below:
- Implement drawing a pentagon (implement the structure Pentagon, and the trait needed to draw in the image)
- `Point`: a new point should be created from two `i32` values.
- `Line`: a new line should be created from references to two different points. Also it will define an associated function called `random`:
- `random`: receives two arguments, the first is the `maximum x` value a point can have and the second is the `maximum y` value that a point can have.
- `Triangle`: a new triangle should be created from references to three different points.
- `Rectangle`: a new rectangle should be created from two references to different points.
- `Circle`: a new circle should be created from a point representing the center and an `i32` value representing the radius for the circle.
- Implement drawing a cube (implement the structure Cube, and the trait needed to draw in the image)
- The main function also requires a definition of an associated function called `random` for the types `Line`, `Point` and `Circle`. You should derive their signature from the usage.
### Notions
**Note**: Don't forget to add the dependencies in your Cargo.toml.
The objective for this raid is to create a traffic control strategy and represent it with an interface/UI.
The objective for this raid is to create a traffic control strategy and represent it with an interface/UI.
Its up to you to decide which library and file system you want do use to create this simulation, but we recommend to use the library [sdl2](https://docs.rs/sdl2/0.34.3/sdl2/)
It's up to you to decide which library and file system you want to use in order to create this simulation, but we recommend you to use the library [sdl2](https://docs.rs/sdl2/0.34.3/sdl2/)
### Instructions
### Instructions
@ -13,9 +13,11 @@ You must create an environment which contains all the objects described in this
1. Roads
1. Roads
There exists various shapes of intersections, we will focus on the widely seen four-lane intersection. For simplicity each lane will have two directions.
There are various forms of intersections, let's focus on the widely seen four-lane crossroad. For simplicity, each road will have two lanes with two different directions for the total of two roads and four lanes.
```console
```console
lane1 lane2
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
@ -24,15 +26,15 @@ There exists various shapes of intersections, we will focus on the widely seen f
| r s l | ↑ |
| r s l | ↑ |
_______________| ← ↓ → | ↑ |_____________
_______________| ← ↓ → | ↑ |_____________
| ↑ r
| ↑ r
← ← ← ← ← ← ← | ← s ← ← ← ← ←
← ← ← ← ← ← ← | ← s ← ← ← ← ← lane3
| ↓ l
| ↓ l
_________________________|_______________________
_________________________|_______________________
l ↑ |
l ↑ |
→ → → → → s → | → → → → → →
→ → → → → s → | → → → → → → lane4
r ↓ |
r ↓ |
_______________ | _____________
_______________ | _____________
| | ← ↑ → |
| | ← ↑ → |
| ↓ | r s l |
| ↓ | l s r |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
| ↓ | ↑ |
@ -40,7 +42,7 @@ _______________ | _____________
| ↓ | ↑ |
| ↓ | ↑ |
```
```
For clarification reasons we will assume that a lane can have three different routes (consider you are in the vehicle position):
For clarification reasons we will assume that a lane can have three different routes (consider that you are in the vehicle position):
- `r`, turning right
- `r`, turning right
- `s`, straight ahead
- `s`, straight ahead
@ -49,11 +51,11 @@ For clarification reasons we will assume that a lane can have three different ro
2. Traffic lights
2. Traffic lights
Traffic lights are signalize devices positioned at road intersections that follows an universal color code,
Traffic lights are signalize devices positioned at road intersections that follows an universal color code,
normally its green, red and amber, but for this project you will just use the colors **red** and **green**.
it's usually green, red and amber, but for this project you will just use the colors **red** and **green**.
You will then have to create some kind of representation for the traffic lights and distribute them for each lane in the intersection.
You will then have to create some kind of representation for the traffic lights and distribute them for each lane in the intersection.
You are free to decide what algorithm you want to implement for the traffic light system, but keep in mind that traffic congestion should not be to high.
You are free to decide what algorithm you want to implement to represent traffic light system, but keep in mind that traffic congestion should not be too high (8 or more vehicles).
3. Vehicles
3. Vehicles
@ -65,15 +67,14 @@ You are free to decide what algorithm you want to implement for the traffic ligh
Vehicles must obey this rules:
Vehicles must obey this rules:
- Vehicles must have a color depending on their route the colors are up to you to decide(ex:`r`- purple, `s`- Blue and `l`- Yellow). This must then be given during the audit
- Vehicles must have a color so that it's possible to identify which route it will follow (ex:`r`- purple, `s`- Blue and `l`- Yellow). This information about the colors must be given to the auditor of the raid. The colors are up to you to decide.
- Autonomous, vehicles driving on a lane with a **given route** must follow the direction of
- Autonomous vehicles driving on a lane with a **given route** must follow the direction of that route, it is not possible for the autonomous vehicle to change lanes or routes.
that route, its not possible for the driver to change lanes or route.
- Each vehicle must have a fixed velocity.
- Each vehicle must have a fixed velocity.
- It must be kept a safety distance from other vehicles, if one vehicle stops the other vehicle that
- A safety distance from other vehicles must be kept, if one vehicle stop the other vehicle that's
behind him must stop and keep its distance.
behind him must stop and keep it's distance.
- Vehicles must stop if the traffic light is red and proceed otherwise.
- Vehicles must stop if the traffic light is red and proceed otherwise.
@ -85,7 +86,7 @@ Vehicles must obey this rules:
#### **Commands**
#### **Commands**
The generating of vehicle must be done using the keyboard event. You must be able to generate
The generating of vehicles must be done using the keyboard event. You must be able to generate
vehicles in different lanes and with different routes.
vehicles in different lanes and with different routes.
For this it must be possible to do the following:
For this it must be possible to do the following:
@ -101,17 +102,20 @@ For this it must be possible to do the following:
- The `Esc` key must finish the simulation.
- The `Esc` key must finish the simulation.
> Arrow keys must not let the user spam the creation of vehicles, vehicles must be created with a safe distance between them.
> Arrow keys must not let the user spam the creation of vehicles, they must be created with a safe distance between them.
> A safe distance is any distance that allows the vehicles not to crash into each other.
### Example
### Example
You can see an example [here](https://www.youtube.com/watch?v=6B0-ZBET6mo).
You can see an example for the road_intersection [here](https://www.youtube.com/watch?v=6B0-ZBET6mo).
### Bonus
### Bonus
You can implement the following optional features :
You can implement the following optional features:
- Vehicle and traffic lights animation and image rendering. You can find some cool assets:
- Vehicle and traffic lights animation and image rendering. You can find some cool assets :
##### Try and run the application, then generate a vehicle by pressing the `"Arrow Up"` key.
##### Try to run the application.
###### Is the application running?
##### Try to generate a vehicle by pressing the `"Arrow Up"` key.
###### Was a vehicle generated from the cardinal south?
###### Was a vehicle generated from the cardinal south?
##### Try pressing the `"Arrow Down"` key.
##### Try to generate a vehicle by pressing the `"Arrow Down"` key.
###### Was a vehicle generated from the cardinal North?
###### Was a vehicle generated from the cardinal North?
##### Try pressing the `"Arrow Right"` key.
##### Try to generate a vehicle by pressing the `"Arrow Right"` key.
###### Was a vehicle generated from the cardinal west?
###### Was a vehicle generated from the cardinal west?
##### Try pressing the `"Arrow left"` key.
##### Try to generate a vehicle by pressing the `"Arrow left"` key.
###### Was a vehicle generated from the cardinal east?
###### Was a vehicle generated from the cardinal east?
##### Try pressing the `"R"` key.
##### Try pressing the `"R"` key.
###### Are vehicles generated randomly(random lane and route)?
###### Was the vehicle generated randomly (random lane and route)?
##### Try pressing the `"R"` key more than 5 times to generate multiple vehicles in different lines.
###### Can you confirm that the vehicles were created and maintain a safe distance from one another?
##### Try to generate tree vehicles in the same lane (do this to all lanes).
##### Try to generate three vehicles in the same lane (do this on all lanes one at a time).
###### Did all vehicles passed the intersection without any collision?
###### Can you confirm that the vehicles were created with a safe distance one from another?
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Down"` key (to this at least 3 times).
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Down"` key (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate two vehicles at the same time, one using the `"Right"` key and the other using the `"Left"` key (to this at least 3 times).
##### Try to generate two vehicles at the same time, one using the `"Right"` key and the other using the `"Left"` key (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Left"` key (to this at least 3 times).
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Left"` key (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Right"` key (to this at least 3 times).
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Right"` key (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate two vehicles at the same time, one using the `"Down"` key and the other using the `"Left"` key (to this at least 3 times).
##### Try to generate two vehicles at the same time, one using the `"Down"` key and the other using the `"Left"` key (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate two vehicles at the same time, one using the `"Down"` key and the other using the `"Right"` key (to this at least 3 times).
##### Try to generate two vehicles at the same time, one using the `"Down"` key and the other using the `"Right"` key (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate five vehicles using the `"Up"` key, at the same time generate two vehicles using the key `"Right"`.
##### Try to generate five vehicles using the `"Up"` key, at the same time generate two vehicles using the `"Right"` key.
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate one vehicle for all the lanes (to this at least 3 times).
##### Try to generate one vehicle for all the lanes (do this at least 3 times).
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate vehicles randomly using the `"R"` key. Then wait for at least 1 min.
##### Try to generate vehicles randomly using the `"R"` key. Then wait for at least 1 min.
###### Did all vehicles passed the intersection without any collision?
###### Did all the vehicles passed the intersection without any collision?
###### Was there a low traffic congestion while running the application? (ex: high traffic congestion can be 8 or more vehicles in the same lane without proceeding)?
##### Try to generate multiple vehicles in lanes of your choice.
###### Did all the vehicles passed the intersection without any collision?
##### Try to generate vehicles with lanes at your choice.
##### Try pressing the `"Esc"` key.
###### Did all vehicles passed the intersection without any collision?
###### Was the simulation finished?
###### Was there a low traffic congestion while running the application? (ex: high traffic congestion can be 8 or more vehicles in the same lane without proceeding)?
#### General
#### General
###### Is it not possible to spam the creation of vehicles(by pressing the arrow keys to many times)?
###### Can you confirm that it is impossible to spam the creation of vehicles (by pressing the arrow keys to many times or leave it pressed)?
###### Are vehicles assigned to their own route, and if so do they obey that route? (you can use the colors for each route to see this)
###### Are vehicles assigned to their own route, and if so, do they obey that route? (you can use the colors for each route to see this, ask the owner of the raid for instructions)
###### Are vehicles kept in a safe distance(do not collide when ever one stops)?
###### Do the vehicles kept a safe distance (do not collide whenever one stops)?
###### Do vehicles stop whenever there is a red light?
###### Do vehicles stop whenever there is a red light?
###### Do vehicles proceed whenever there is a green light?
###### Do vehicles proceed whenever there is a green light?
#### Bonus
#### Bonus
###### +Is there any type of image sprite for traffic light?
###### +Is there any type of image sprite for traffic light? (An image sprite is a collection of images put into a single image.)
###### +Did the student implement some kind of animation and image sprite for the vehicle?
###### +Did the student implement some kind of animation and image sprite for the vehicle?