-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlalluvia.js
109 lines (79 loc) · 2.46 KB
/
lalluvia.js
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
// questions?@alfonsofonso:alert("cheers!");
//audio
var contexto=new AudioContext();
fun=function(e){
var osc=contexto.createOscillator();
osc.frequency.value=216 * Math.pow(2,Math.ceil(Math.random()*7)/7);//or Math.random()*440+220;
var ganancia=contexto.createGain();
ganancia.gain.value = 0;
osc.connect(ganancia);
ganancia.connect(contexto.destination);
let t=contexto.currentTime+Math.random()
ganancia.gain.linearRampToValueAtTime(0.1,t)
ganancia.gain.exponentialRampToValueAtTime(0.00001,t+Math.random())
setTimeout(function(){osc.stop(t+2);osc.disconnect();ganancia.disconnect()},2000)
ponEstrella(e);
osc.start();
}
//visuals
var amp=10;
var alt=10;
var speed=false;
var percVel=300;
var noteVel=1000;
var radioCircle=2;
var radioCircleFinal=24;
var stage = new createjs.Stage("micanvas");
var canvasContext=document.getElementById("micanvas");
createjs.Ticker.timingMode = createjs.Ticker.RAF;
createjs.Ticker.setFPS=10;
createjs.Ticker.addEventListener("tick", tick);
var body = document.body;
var html = document.documentElement;
ponEstrella=function(e){// star
var equis=20;//(radius/(2 + Math.random()*20) )* Math.cos(ang) + amp/2;
var igriega=20;//(radius/(2 + Math.random()*20) ) * Math.abs(Math.sin(ang)) + alt/2;
var vel=2000;
var c = new createjs.Shape();
c.graphics.beginFill("white").drawCircle(2, 2, radioCircle);
if (e.name==undefined) {
console.log("clic ")
c.x = e.x;
c.y = e.y+window.scrollY;
}else{
console.log("scroll");
c.x=amp*(Math.random());
c.y=e.scrollY+300;
}
stage.addChild(c);
var tamanyo=Math.random()*radioCircleFinal;
createjs.Tween.get(c)
.to({scaleX:tamanyo, scaleY:tamanyo, alpha:0},vel, createjs.Ease.getPowOut(2))
.call(handleComplete, [c]);
}
function tick(event) {
stage.update()
}
window.onresize = function(event) {
ajustaCanvas();
}
ajustaCanvas=function(){
alt = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
amp=canvasContext.width = window.innerWidth;
canvasContext.height = alt;
radioCircle=amp/100;
radioCircleFinal=amp/20;
}
function handleComplete(dispon) {
dispon.removeAllEventListeners();
stage.removeChild(dispon);
dispon=null;
intervalando=false;
clearInterval(inter);
}
//events
var intervalando=false;
var inter;
onclick=fun;
onscroll=function(){if(!intervalando){ inter=setInterval(function(){ fun(this) }, 300); intervalando=true }}
onload=ajustaCanvas;