-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.js
More file actions
105 lines (95 loc) · 3.6 KB
/
Copy pathtest2.js
File metadata and controls
105 lines (95 loc) · 3.6 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
(function(){
var stage, form, input;
var circles, textPixels, textFormed;
var offsetX, offsetY, text;
var colors = ['#ff0000', '#7a7200', '#51ff00', '#00d4ff', '#ff00d0'];
function init() {
initStages();
initCircles();
animate();
}
// Init Canvas
function initStages() {
offsetX = (window.innerWidth-600)/2;
offsetY = (window.innerHeight-600)/2;
stage = new createjs.Stage("stage");
stage.canvas.width = window.innerWidth;
stage.canvas.height = window.innerHeight;
}
function initCircles() {
circles = [];
for(var i=0; i<10; i++) {
var circle = new createjs.Shape();
var r = 300;
var x = window.innerWidth*Math.random();
var y = window.innerHeight*Math.random();
var color = colors[Math.floor(i%colors.length)];
var alpha = .1*Math.random()*0.5;
circle.alpha = alpha;
circle.radius = r;
circle.graphics.beginFill(color).drawCircle(0, 0, r);
circle.x = x;
circle.y = y;
circles.push(circle);
stage.addChild(circle);
circle.movement = 'float';
tweenCircle(circle);
}
}
// animating circles
function animate() {
stage.update();
requestAnimationFrame(animate);
}
function tweenCircle(c, dir) {
if(c.tween) c.tween.kill();
if(dir == 'in') {
c.tween = TweenLite.to(c, 0.4, {x: c.originX, y: c.originY, ease:Quad.easeInOut, alpha: 1, radius: 5, scaleX: 0.4, scaleY: 0.4, onComplete: function() {
c.movement = 'jiggle';
tweenCircle(c);
}});
} else if(dir == 'out') {
c.tween = TweenLite.to(c, 0.8, {x: window.innerWidth*Math.random(), y: window.innerHeight*Math.random(), ease:Quad.easeInOut, alpha: 0.2 + Math.random()*0.5, scaleX: 1, scaleY: 1, onComplete: function() {
c.movement = 'float';
tweenCircle(c);
}});
} else {
if(c.movement == 'float') {
c.tween = TweenLite.to(c, 5 + Math.random()*3.5, {x: c.x + -100+Math.random()*200, y: c.y + -100+Math.random()*200, ease:Quad.easeInOut, alpha: 0.2 + Math.random()*0.5,
onComplete: function() {
tweenCircle(c);
}});
} else {
c.tween = TweenLite.to(c, 0.05, {x: c.originX + Math.random()*3, y: c.originY + Math.random()*3, ease:Quad.easeInOut,
onComplete: function() {
tweenCircle(c);
}});
}
}
}
function formText() {
for(var i= 0, l=textPixels.length; i<l; i++) {
circles[i].originX = offsetX + textPixels[i].x;
circles[i].originY = offsetY + textPixels[i].y;
tweenCircle(circles[i], 'in');
}
textFormed = true;
if(textPixels.length < circles.length) {
for(var j = textPixels.length; j<circles.length; j++) {
circles[j].tween = TweenLite.to(circles[j], 0.4, {alpha: 0.1});
}
}
}
function explode() {
for(var i= 0, l=textPixels.length; i<l; i++) {
tweenCircle(circles[i], 'out');
}
if(textPixels.length < circles.length) {
for(var j = textPixels.length; j<circles.length; j++) {
circles[j].tween = TweenLite.to(circles[j], 0.4, {alpha: 1});
}
}
}
// event handlers
window.onload = function() { init() };
})();