-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsketch.js
108 lines (82 loc) · 1.52 KB
/
sketch.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var train;
var light;
var blip;
var val=0;
function setup(){
createCanvas(720,400);
train = new reg;
light = new sig;
blip = new blip;
noLoop();
}
function draw(){
background(230);
train.move();
train.display();
light.move();
light.display();
blip.move();
blip.display();
}
function mousePressed(){
loop();
}
function mouseReleased(){
noLoop();
}
function reg(){
this.x = 100;
this.y = 100;
this.xspeed = 2;
this.yspeed = 0
this.move = function(){
if (this.x > width){
this.x = 100;
}else{
this.x = this.x + this.xspeed;
}
};
this.display = function(){
fill(100,100,100);
rect(this.x,this.y,100,50);
};
}
function sig(){
this.x = train.x - 25;
this.y = train.y - 10;
this.xspeed = train.xspeed;
this.yspeed = train.yspeed;
this.move = function(){
if (this.x > width){
this.x = 100;
}else{
this.x = this.x + this.xspeed;
}
};
this.display = function(){
fill(50,50,50);
rect(this.x+50,this.y+50,10,10);
};
}
function blip(){
this.x = light.x + 55;
this.y = light.y + 50;
this.xspeed = light.xspeed;
this.yspeed = -1;
this.move = function(){
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
if (this.y < 100 || this.y > 145){
this.yspeed = this.yspeed*-1
}else{
}
if (this.x > width + 2.5){
this.x = 100;
}else{
}
};
this.display = function(){
fill(100,10,10);
rect(this.x,this.y,2,5);
};
}