-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.js
123 lines (104 loc) · 2.91 KB
/
Matrix.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
110
111
112
113
114
115
116
117
118
119
// Funcion que devuelve un valor aleatorio entre el min y max incluidos
// IN: Min (int) y Max (int)
// OUT: Valor aleatorio (int)
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
// Clase Simbolo
function Simbolo(x,y,velocidad,primero){
this.x = x;
this.y = y;
this.valor;
this.vel = velocidad;
this.FPS2cambiar = getRndInteger(5,25);
this.primero = primero;
this.SimboloAleatorio = function(){
if(Math.random()>=0.9){
var num = getRndInteger(0,9);
this.valor = num.toString();
}
else{
this.valor = String.fromCharCode(0x30A0 + getRndInteger(0,96));
}
}
this.Mover = function(){
this.y = (this.y>=alto) ? 0 : this.y += this.vel;
if (FPS % this.FPS2cambiar == 0){
this.SimboloAleatorio();
}
}
}
// Clase cadena que contiene un numero aleatorio de simbolos
function Cadena(){
this.Caracteres = [];
this.longitud = getRndInteger(5,35);
this.velocidad = getRndInteger(2,10);
this.rellenarCadena = function(x, y){
var first = (Math.random()>0.75) ? true : false;
for(var i=0;i<this.longitud;i++){
var Caracter = new Simbolo(x,y,this.velocidad,first);
Caracter.SimboloAleatorio();
this.Caracteres.push(Caracter);
y -= tamLetra;
first = false;
}
}
this.Representar = function(){
this.Caracteres.forEach(function(caracter){
ctx.shadowColor = "#FFFFFF";
if (caracter.primero == true){
ctx.fillStyle = "#c8ffc8";
ctx.shadowBlur = 5;
}
else {
ctx.fillStyle = "#32CD32";
ctx.shadowBlur = 0;
}
ctx.fillText(caracter.valor,caracter.x,caracter.y);
caracter.Mover();
});
}
this.Mover = function(){
this.y = (this.y>=alto) ? 0 : this.y += this.vel;
}
}
// Funcion encargada de animar esperando al refresco de la pantalla
function Animar(){
FPS = (FPS > 59) ? 0 : FPS += 1;
ctx.clearRect(0,0,ancho,alto);
cadenas.forEach(function(cad){
cad.Representar();
});
requestAnimFrame(Animar);
}
// --------------------------------------------------------------------------------------------------------------------
// Inicializacion
var ancho = window.innerWidth;
var alto = window.innerHeight;
var tamLetra = 15;
var FPS = 0;
// Setup del canvas
var c = document.getElementById("myCanvas");
c.width = ancho;
c.height = alto;
var ctx = c.getContext("2d");
ctx.clearRect(0,0,ancho,alto);
ctx.font = String(tamLetra) + "px Arial";
// Setup de la animacion
window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame
|| window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
// Seccion principal
var cadenas = [];
var x = 0;
for (var i=0; i<= Math.floor(ancho/tamLetra); i++){
var cad = new Cadena();
cad.rellenarCadena(x,getRndInteger(-500,0));
cadenas.push(cad);
x += tamLetra;
}
Animar();