-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
138 lines (126 loc) · 3.82 KB
/
demo.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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MiniMorphicJS demo</title>
</head>
<body style="margin: 0">
<h2 id="loading">Loading...</h2>
<canvas id="world" oncontextmenu="return false"></canvas>
<script src="js/core/KeyCode.js"></script>
<script src="js/core/Canvas.js"></script>
<script src="js/core/Form.js"></script>
<script src="js/core/EventHandler.js"></script>
<script src="js/core/Morph.js"></script>
<script src="js/core/World.js"></script>
<script src="js/core/Sprite.js"></script>
<script src="js/core/Ellipse.js"></script>
<script src="js/core/Button.js"></script>
<script src="js/demo/BouncingBall.js"></script>
<script src="js/demo/Fountain.js"></script>
<script src="js/demo/GuybrushThreepwood.js"></script>
<script src="js/demo/OptimizedFountain.js"></script>
<script>
// First we load all the images we're going to use
Form.load([
"images/gb1.png" ,
"images/gb2.png" ,
"images/gb3.png" ,
"images/gb4.png" ,
"images/gb5.png" ,
"images/gb6.png"
]).then(function (forms) {
// Remove loading
document.body.removeChild(loading);
var world = new World();
var buttons = [];
/*
Clear submorphs
*/
var clearButton = new Button();
buttons.push(clearButton);
clearButton.label="Clear";
clearButton.position={ x: 10, y: 10 };
clearButton.on("mouseUp", function () {
var toRemove = [];
world.submorphsDo(function (morph) {
// If it's not a button
if (buttons.indexOf(morph) === -1) {
toRemove.push(morph);
}
});
toRemove.forEach(function (morph) {
morph.remove();
});
});
/*
Small demo of bouncing morphs
*/
var bounceButton = new Button();
buttons.push(bounceButton);
bounceButton.label="Bouncing balls";
bounceButton.left=clearButton.left;
bounceButton.top=clearButton.bottom + 10;
bounceButton.on("mouseUp", function () {
for (var i = 0; i < 15; i++) {
world.addMorph(new BouncingBall());
}
});
/*
Simple "fountain" demo
*/
var fountainButton = new Button();
var fountain = undefined;
buttons.push(fountainButton);
fountainButton.label="Start fountain";
fountainButton.left=bounceButton.left;
fountainButton.top=bounceButton.bottom + 10;
fountainButton.on("mouseUp", function () {
if (fountain === undefined) {
fountain = new Fountain();
world.addMorph(fountain);
fountainButton.label="Stop fountain";
} else {
fountain.stop();
fountain = undefined;
fountainButton.label="Start fountain";
}
});
/*
Optimized "fountain" demo
*/
var optimizedFountainButton = new Button();
var optimizedfountain = undefined;
buttons.push(optimizedFountainButton);
optimizedFountainButton.label="Start optimized fountain";
optimizedFountainButton.left=fountainButton.left;
optimizedFountainButton.top=fountainButton.bottom + 10;
optimizedFountainButton.on("mouseUp", function () {
if (optimizedfountain === undefined) {
optimizedfountain = new OptimizedFountain();
world.addMorph(optimizedfountain);
optimizedFountainButton.label="Stop optimized fountain";
} else {
optimizedfountain.stop();
optimizedfountain = undefined;
optimizedFountainButton.label="Start optimized fountain";
}
});
/*
"Guybrush Threepwood" walking demo
*/
var threepwoodButton = new Button();
buttons.push(threepwoodButton);
threepwoodButton.label="Guybrush Threepwood";
threepwoodButton.left=optimizedFountainButton.left;
threepwoodButton.top=optimizedFountainButton.bottom + 10;
threepwoodButton.on("mouseUp", function () {
world.addMorph(new GuybrushThreepwood(forms));
});
// Add buttons to the world
buttons.forEach(function (button) {
world.addMorph(button);
});
});
</script>
</body>
</html>