-
Notifications
You must be signed in to change notification settings - Fork 0
/
dots.html
172 lines (146 loc) · 4.59 KB
/
dots.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Dots</title>
<meta name="description" content="" />
<meta name="author" content="baptooo" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<style type="text/css">
.rule {
position: absolute;
}
</style>
</head>
<body>
<p class="rule">Double click to add dots that you can drag & drop</p>
<div id="container"></div>
<script type="text/javascript" src="src/ext-core.js"></script>
<script type="text/javascript" src="src/kinetic.latest.js"></script>
<script type="text/javascript" src="src/base.js"></script>
<script type="text/javascript">
Game = Ext.extend(Ext.Base, {
progress: 0,
constructor: function() {
Game.superclass.constructor.apply(this, arguments);
},
initScene: function() {
Game.superclass.initScene.apply(this, arguments);
var me = this;
me.balls = [];
me.line = new Kinetic.Spline({
points: [{
x: 0, y: 0
}, {
x: 0, y: 0
}, {
x: 0, y: 0
}],
stroke: 'red',
strokeWidth: 10,
lineCap: 'round',
tension: 0.5
});
me.layer.add(me.line);
},
setEvents: function() {
var me = this;
if('ontouchstart' in window) {
var last = Date.now(),
count = 0;
Ext.get('container').dom.addEventListener('touchstart', function(e) {
if(Date.now() - last > 150) {
count = 0;
}
last = Date.now();
count++;
if(count < 2) {
return;
}
console.log('doubletap');
me.addBall(me.mouse.x, me.mouse.y);
});
}
window.ondblclick = function() {
me.addBall(me.mouse.x, me.mouse.y);
}
},
addBall: function(x, y) {
var me = this,
ballSize = 25,
sY = y / me.sH * ballSize;
var b = new Kinetic.Circle({
radius: sY,
fill: 'black',
x: x, y: y,
draggable: true
});
b.on('dragmove', function(e) {
this.setRadius(e.pageY / me.sH * ballSize);
});
me.balls.push(b);
me.layer.add(b);
},
curve: {
x: 0, y: 0
},
onFrame: function(frame) {
var me = this,
balls = me.balls,
bLen = balls.length,
mouse = me.mouse;
if(!bLen) return;
var headSpeed = 0.4,
queueSpeed = 0.2,
curve = me.curve,
cX = curve.x,
cY = curve.y,
b = balls[me.progress],
bX = b.getX(),
bY = b.getY(),
l = me.line,
p = l.getPoints(),
aX = p[0].x,
aY = p[0].y,
nX = p[1].x,
nY = p[1].y;
var head = {
x: nX + (bX - nX) * headSpeed,
y: nY + (bY - nY) * headSpeed
}
cX = cX + (head.x - cX) * queueSpeed;
cY = cY + (head.y - cY) * queueSpeed;
var queue = {
x: aX + (cX - aX) * queueSpeed,
y: aY + (cY - aY) * queueSpeed
}
if(Math.abs(queue.x - bX) < 5 && Math.abs(queue.y - bY) < 5) {
me.progress = (me.progress + 1 + bLen) % bLen;
}
curve.x = cX;
curve.y = cY;
l.setPoints([queue, curve, head]);
}
});
Ext.onReady(function() {
var stage = new Kinetic.Stage({
width: window.innerWidth - 24,
height: window.innerHeight - 24,
container: 'container'
});
var layer = new Kinetic.Layer();
var main = new Game({
autoStart: true,
stage: stage,
layer: layer
});
});
</script>
</body>
</html>