-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
130 lines (101 loc) · 3.72 KB
/
Copy pathindex.html
File metadata and controls
130 lines (101 loc) · 3.72 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
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
<html>
<head>
<style type="text/css">
body {
padding: 0px;
margin: 0px;
}
#canvas {
background-color: #ccc;
}
</style>
</head>
<body onload="new pt.TestApp">
<canvas id="canvas"></canvas>
<script type="text/javascript" src="http://code.createjs.com/easeljs-0.5.0.min.js"></script>
<script type="text/javascript" src="http://code.createjs.com/tweenjs-0.3.0.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script type="text/javascript">
var c = createjs;
var presstube = {};
var pt = presstube;
var p;
pt.TestApp = function() {
var canvas = document.getElementById("canvas");
var stage = new c.Stage(canvas);
var bgRect = new c.Shape;
var centeredContainer = new c.Container;
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
bgRect.graphics.clear().beginFill("888").drawRect(0, 0, canvas.width, canvas.height);
centeredContainer.x = canvas.width/2;
centeredContainer.y = canvas.height/2;
}
function spawnNoun() {
var noun = new pt.Noun;
noun.x = Math.random()*200 - Math.random()*200;
noun.y = Math.random()*200 - Math.random()*200;
noun.rotation = Math.random()*30 - Math.random()*30;
centeredContainer.addChild(noun);
// wait 2 seconds and then dematerialize
_.delay( function() {
noun.dematerialize();
}, 2000);
}
function onPress() {
spawnNoun();
}
function onTick() {
if (Math.random() < 0.05) {
spawnNoun();
}
}
resize();
window.onresize = resize;
c.Ticker.setFPS(30);
c.Ticker.addListener(stage);
stage.addChild(bgRect);
stage.addChild(centeredContainer);
bgRect.onPress = onPress;
stage.onTick = onTick;
}
pt.Noun = function() { this.initialize(); };
p = pt.Noun.prototype = new c.Container;
p.Container_initialize = p.initialize;
p.initialize = function() {
this.Container_initialize();
var noun = this;
var libraryAnim = new c.BitmapAnimation(pt.Noun.libraryAnimSpriteSheet);
var puffAnim = new c.BitmapAnimation(pt.Noun.puffAnimSpriteSheet);
var numFrames = libraryAnim.spriteSheet.getNumFrames();
function materialize() {
c.Tween.get(libraryAnim, {onChange: matchPuffFrameToScale} ).to({scaleX: 1, scaleY: 1}, 800, c.Ease.quintIn);
}
function dematerialize() {
c.Tween.get(libraryAnim, {onChange: matchPuffFrameToScale} ).to({scaleX: 0, scaleY: 0}, 800, c.Ease.quintOut).call(onDematerializeComplete);
}
function onDematerializeComplete(){
noun.parent.removeChild(noun);
}
function onPress(){
dematerialize();
}
function matchPuffFrameToScale() {
var frame = Math.floor(puffAnim.spriteSheet.getNumFrames() * libraryAnim.scaleX);
//console.log(frame);
puffAnim.gotoAndStop(frame);
}
libraryAnim.scaleX = libraryAnim.scaleY = 0;
noun.addChild(libraryAnim);
libraryAnim.gotoAndStop(Math.floor(Math.random() * numFrames));
materialize();
noun.onPress = onPress;
noun.addChild(puffAnim);
noun.dematerialize = dematerialize;
}
pt.Noun.libraryAnimSpriteSheet = new c.SpriteSheet( {"images": ["test1.png"], "frames": [[2, 2, 124, 124, 0, 62, 62], [130, 2, 124, 124, 0, 62, 62], [258, 2, 124, 124, 0, 62, 62]], "animations": {"all": {"frames": [0, 1, 2]}}} );
pt.Noun.puffAnimSpriteSheet = new c.SpriteSheet( {"images": ["puff.png"], "frames": [[2, 2, 124, 124, 0, 62, 62], [130, 2, 124, 124, 0, 62, 62], [258, 2, 124, 124, 0, 62, 62], [386, 2, 124, 124, 0, 62, 62], [514, 2, 124, 124, 0, 62, 62], [642, 2, 124, 124, 0, 62, 62], [770, 2, 124, 124, 0, 62, 62], [898, 2, 124, 124, 0, 62, 62], [1026, 2, 124, 124, 0, 62, 62], [1154, 2, 124, 124, 0, 62, 62]], "animations": {"all": {"frames": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]}}} );
</script>
</body>
</html>