-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrafficLight.java
More file actions
51 lines (44 loc) · 1.23 KB
/
TrafficLight.java
File metadata and controls
51 lines (44 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @author (Herbert wenisch)
* @version (08-12-23)
*/
import java.awt.Color;
public class TrafficLight {
private final String version = "1.1";
// Colors:
private final Color green = new Color(21,153,39);
private final Color red = Color.red;
private final Color gray = Color.gray;
// states: red (normal state), green
private String state; // current state
// lamps:
private Lamp lampUpper;
private Lamp lampLower;
public TrafficLight(){
state = "red";
lampUpper = new Lamp(0, 80, red);
lampLower = new Lamp(0, 30, gray);
display();
}
public void display(){
// frame:
Turtlegrafik.turtle.setPenColor(Color.black);
Turtlegrafik.turtle.setPenWidth(2);
Turtlegrafik.turtle.setPos(30,0);
for(int i = 0; i < 2; i++){
Turtlegrafik.turtle.fd(110);
Turtlegrafik.turtle.lt(90);
Turtlegrafik.turtle.fd(60);
Turtlegrafik.turtle.lt(90);
}
// lamps:
lampUpper.display();
lampLower.display();
}
public void switchGreen(){
state = "green";
lampUpper.setColor(green);
lampLower.setColor(gray);
display();
}
}