-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathsample.html
154 lines (121 loc) · 3.02 KB
/
sample.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<script src="lib/p5.js"></script>
<script src="lib/scenemanager.js"></script>
<script>
var mgr;
function setup()
{
createCanvas(600, 500);
mgr = new SceneManager();
// Preload scenes. Preloading is normally optional
// ... but needed if showNextScene() is used.
mgr.addScene ( Animation1 );
mgr.addScene ( Animation2 );
mgr.addScene ( Animation3 );
mgr.showNextScene();
}
function draw()
{
mgr.draw();
}
function mousePressed()
{
mgr.handleEvent("mousePressed");
}
function keyPressed()
{
// You can optionaly handle the key press at global level...
switch(key)
{
case '1':
mgr.showScene( Animation1 );
break;
case '2':
mgr.showScene( Animation2 );
break;
case '3':
mgr.showScene( Animation3 );
break;
}
// ... then dispatch via the SceneManager.
mgr.handleEvent("keyPressed");
}
// =============================================================
// = BEGIN SCENES =
// =============================================================
function Animation1()
{
var textX;
var textY;
// enter() will be executed each time the SceneManager switches
// to this animation
// Note: Animation1() doesn't have setup() or draw()
this.enter = function()
{
textX = 10;
textY = 0;
background("teal");
textAlign(CENTER);
fill("black");
text("Press keys 1, 2, 3 to jump to a particular animation\n" +
"... or mouse to advance animation.\n\n" +
"Press any other key to display it.", width / 2, height / 2);
}
this.keyPressed = function()
{
text(keyCode, textX, textY += 10);
if ( textY > height )
{
textX += 20;
textY = 0;
}
}
this.mousePressed = function()
{
this.sceneManager.showNextScene();
}
}
function Animation2()
{
this.y = 0;
this.draw = function()
{
background("teal");
line(0, this.y, width, this.y);
this.y++;
if ( this.y > height )
this.y = 0;
}
this.mousePressed = function()
{
this.sceneManager.showNextScene();
}
}
// When defining scenes, you can also
// put the setup, draw, etc. methods on prototype
function Animation3( )
{
this.oAnim1 = null;
}
Animation3.prototype.setup = function()
{
// access a different scene using the SceneManager
oAnim1 = this.sceneManager.findScene( Animation2 );
}
Animation3.prototype.draw = function()
{
background("lightblue");
var r = sin( frameCount * 0.01 );
fill("white");
ellipse( width / 2, height / 2, map(r, 0, 1, 100, 200) );
if ( oAnim1 != null )
{
fill("black");
textAlign(LEFT);
text( "Scene1 y: " + oAnim1.oScene.y, 10, height - 20);
}
}
Animation3.prototype.mousePressed = function()
{
this.sceneManager.showNextScene();
}
</script>