Вход Регистрация
Файл: CloudBox-main/CloudBox/admin_assets/js/skycons.js
Строк: 442
<?php
(function(global) {
  
"use strict";

  
/* Set up a RequestAnimationFrame shim so we can animate efficiently FOR
   * GREAT JUSTICE. */
  
var requestIntervalcancelInterval;

  (function() {
    var 
raf = global.requestAnimationFrame       ||
              global.
webkitRequestAnimationFrame ||
              global.
mozRequestAnimationFrame    ||
              global.
oRequestAnimationFrame      ||
              global.
msRequestAnimationFrame     ,
        
caf = global.cancelAnimationFrame        ||
              global.
webkitCancelAnimationFrame  ||
              global.
mozCancelAnimationFrame     ||
              global.
oCancelAnimationFrame       ||
              global.
msCancelAnimationFrame      ;

    if(
raf && caf) {
      
requestInterval = function(fndelay) {
        var 
handle = {valuenull};

        function 
loop() {
          
handle.value raf(loop);
          
fn();
        }

        
loop();
        return 
handle;
      };

      
cancelInterval = function(handle) {
        
caf(handle.value);
      };
    }

    else {
      
requestInterval setInterval;
      
cancelInterval clearInterval;
    }
  }());

  
/* Catmull-rom spline stuffs. */
  /*
  function upsample(n, spline) {
    var polyline = [],
        len = spline.length,
        bx  = spline[0],
        by  = spline[1],
        cx  = spline[2],
        cy  = spline[3],
        dx  = spline[4],
        dy  = spline[5],
        i, j, ax, ay, px, qx, rx, sx, py, qy, ry, sy, t;

    for(i = 6; i !== spline.length; i += 2) {
      ax = bx;
      bx = cx;
      cx = dx;
      dx = spline[i    ];
      px = -0.5 * ax + 1.5 * bx - 1.5 * cx + 0.5 * dx;
      qx =        ax - 2.5 * bx + 2.0 * cx - 0.5 * dx;
      rx = -0.5 * ax            + 0.5 * cx           ;
      sx =                   bx                      ;

      ay = by;
      by = cy;
      cy = dy;
      dy = spline[i + 1];
      py = -0.5 * ay + 1.5 * by - 1.5 * cy + 0.5 * dy;
      qy =        ay - 2.5 * by + 2.0 * cy - 0.5 * dy;
      ry = -0.5 * ay            + 0.5 * cy           ;
      sy =                   by                      ;

      for(j = 0; j !== n; ++j) {
        t = j / n;

        polyline.push(
          ((px * t + qx) * t + rx) * t + sx,
          ((py * t + qy) * t + ry) * t + sy
        );
      }
    }

    polyline.push(
      px + qx + rx + sx,
      py + qy + ry + sy
    );

    return polyline;
  }

  function downsample(n, polyline) {
    var len = 0,
        i, dx, dy;

    for(i = 2; i !== polyline.length; i += 2) {
      dx = polyline[i    ] - polyline[i - 2];
      dy = polyline[i + 1] - polyline[i - 1];
      len += Math.sqrt(dx * dx + dy * dy);
    }

    len /= n;

    var small = [],
        target = len,
        min = 0,
        max, t;

    small.push(polyline[0], polyline[1]);

    for(i = 2; i !== polyline.length; i += 2) {
      dx = polyline[i    ] - polyline[i - 2];
      dy = polyline[i + 1] - polyline[i - 1];
      max = min + Math.sqrt(dx * dx + dy * dy);

      if(max > target) {
        t = (target - min) / (max - min);

        small.push(
          polyline[i - 2] + dx * t,
          polyline[i - 1] + dy * t
        );

        target += len;
      }

      min = max;
    }

    small.push(polyline[polyline.length - 2], polyline[polyline.length - 1]);

    return small;
  }
  */

  /* Define skycon things. */
  /* FIXME: I'm *really really* sorry that this code is so gross. Really, I am.
   * I'll try to clean it up eventually! Promise! */
  
var KEYFRAME 500,
      
STROKE 0.08,
      
TAU 2.0 Math.PI,
      
TWO_OVER_SQRT_2 2.0 Math.sqrt(2);

  function 
circle(ctxxyr) {
    
ctx.beginPath();
    
ctx.arc(xyr0TAUfalse);
    
ctx.fill();
  }

  function 
line(ctxaxaybxby) {
    
ctx.beginPath();
    
ctx.moveTo(axay);
    
ctx.lineTo(bxby);
    
ctx.stroke();
  }

  function 
puff(ctxtcxcyrxryrminrmax) {
    var 
Math.cos(TAU),
        
Math.sin(TAU);

    
rmax -= rmin;

    
circle(
      
ctx,
      
cx rx,
      
cy ry rmax 0.5,
      
rmin + (0.5) * rmax
    
);
  }

  function 
puffs(ctxtcxcyrxryrminrmax) {
    var 
i;

    for(
5i--; )
      
puff(ctx5cxcyrxryrminrmax);
  }

  function 
cloud(ctxtcxcycwscolor) {
    
/= 30000;

    var 
cw 0.21,
        
cw 0.12,
        
cw 0.24,
        
cw 0.28;

    
ctx.fillStyle color;
    
puffs(ctxtcxcyabcd);

    
ctx.globalCompositeOperation 'destination-out';
    
puffs(ctxtcxcyabss);
    
ctx.globalCompositeOperation 'source-over';
  }

  function 
sun(ctxtcxcycwscolor) {
    
/= 120000;

    var 
cw 0.25 0.5,
        
cw 0.32 0.5,
        
cw 0.50 0.5,
        
ipcossin;

    
ctx.strokeStyle color;
    
ctx.lineWidth s;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    
ctx.beginPath();
    
ctx.arc(cxcya0TAUfalse);
    
ctx.stroke();

    for(
8i--; ) {
      
= (8) * TAU;
      
cos Math.cos(p);
      
sin Math.sin(p);
      
line(ctxcx cos bcy sin bcx cos ccy sin c);
    }
  }

  function 
moon(ctxtcxcycwscolor) {
    
/= 15000;

    var 
cw 0.29 0.5,
        
cw 0.05,
        
Math.cos(TAU),
        
TAU / -16;

    
ctx.strokeStyle color;
    
ctx.lineWidth s;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    
cx += b;

    
ctx.beginPath();
    
ctx.arc(cxcyaTAU 8TAU 8false);
    
ctx.arc(cx Math.cos(p) * TWO_OVER_SQRT_2cy Math.sin(p) * TWO_OVER_SQRT_2aTAU 8TAU 8true);
    
ctx.closePath();
    
ctx.stroke();
  }

  function 
rain(ctxtcxcycwscolor) {
    
/= 1350;

    var 
cw 0.16,
        
TAU 11 12,
        
TAU *  12,
        
ipxy;

    
ctx.fillStyle color;

    for(
4i--; ) {
      
= (4) % 1;
      
cx + ((1.5) / 1.5) * (=== || === ? -1) * a;
      
cy cw;
      
ctx.beginPath();
      
ctx.moveTo(x1.5);
      
ctx.arc(xy0.75bcfalse);
      
ctx.fill();
    }
  }

  function 
sleet(ctxtcxcycwscolor) {
    
/= 750;

    var 
cw 0.1875,
        
TAU 11 12,
        
TAU *  12,
        
ipxy;

    
ctx.strokeStyle color;
    
ctx.lineWidth 0.5;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    for(
4i--; ) {
      
= (4) % 1;
      
Math.floor(cx + ((1.5) / 1.5) * (=== || === ? -1) * a) + 0.5;
      
cy cw;
      
line(ctxx1.5x1.5);
    }
  }

  function 
snow(ctxtcxcycwscolor) {
    
/= 3000;

    var 
a  cw 0.16,
        
b  0.75,
        
u  TAU 0.7,
        
ux Math.cos(u) * b,
        
uy Math.sin(u) * b,
        
v  TAU 3,
        
vx Math.cos(v) * b,
        
vy Math.sin(v) * b,
        
w  TAU 3,
        
wx Math.cos(w) * b,
        
wy Math.sin(w) * b,
        
ipxy;

    
ctx.strokeStyle color;
    
ctx.lineWidth 0.5;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    for(
4i--; ) {
      
= (4) % 1;
      
cx Math.sin((4) * TAU) * a;
      
cy cw;

      
line(ctxuxuyuxuy);
      
line(ctxvxvyvxvy);
      
line(ctxwxwywxwy);
    }
  }

  function 
fogbank(ctxtcxcycwscolor) {
    
/= 30000;

    var 
cw 0.21,
        
cw 0.06,
        
cw 0.21,
        
cw 0.28;

    
ctx.fillStyle color;
    
puffs(ctxtcxcyabcd);

    
ctx.globalCompositeOperation 'destination-out';
    
puffs(ctxtcxcyabss);
    
ctx.globalCompositeOperation 'source-over';
  }

  
/*
  var WIND_PATHS = [
        downsample(63, upsample(8, [
          -1.00, -0.28,
          -0.75, -0.18,
          -0.50,  0.12,
          -0.20,  0.12,
          -0.04, -0.04,
          -0.07, -0.18,
          -0.19, -0.18,
          -0.23, -0.05,
          -0.12,  0.11,
           0.02,  0.16,
           0.20,  0.15,
           0.50,  0.07,
           0.75,  0.18,
           1.00,  0.28
        ])),
        downsample(31, upsample(16, [
          -1.00, -0.10,
          -0.75,  0.00,
          -0.50,  0.10,
          -0.25,  0.14,
           0.00,  0.10,
           0.25,  0.00,
           0.50, -0.10,
           0.75, -0.14,
           1.00, -0.10
        ]))
      ];
  */

  
var WIND_PATHS = [
        [
          -
0.7500, -0.1800, -0.7219, -0.1527, -0.6971, -0.1225,
          -
0.6739, -0.0910, -0.6516, -0.0588, -0.6298, -0.0262,
          -
0.6083,  0.0065, -0.5868,  0.0396, -0.5643,  0.0731,
          -
0.5372,  0.1041, -0.5033,  0.1259, -0.4662,  0.1406,
          -
0.4275,  0.1493, -0.3881,  0.1530, -0.3487,  0.1526,
          -
0.3095,  0.1488, -0.2708,  0.1421, -0.2319,  0.1342,
          -
0.1943,  0.1217, -0.1600,  0.1025, -0.1290,  0.0785,
          -
0.1012,  0.0509, -0.0764,  0.0206, -0.0547, -0.0120,
          -
0.0378, -0.0472, -0.0324, -0.0857, -0.0389, -0.1241,
          -
0.0546, -0.1599, -0.0814, -0.1876, -0.1193, -0.1964,
          -
0.1582, -0.1935, -0.1931, -0.1769, -0.2157, -0.1453,
          -
0.2290, -0.1085, -0.2327, -0.0697, -0.2240, -0.0317,
          -
0.2064,  0.0033, -0.1853,  0.0362, -0.1613,  0.0672,
          -
0.1350,  0.0961, -0.1051,  0.1213, -0.0706,  0.1397,
          -
0.0332,  0.1512,  0.0053,  0.1580,  0.0442,  0.1624,
           
0.0833,  0.1636,  0.1224,  0.1615,  0.1613,  0.1565,
           
0.1999,  0.1500,  0.2378,  0.1402,  0.2749,  0.1279,
           
0.3118,  0.1147,  0.3487,  0.1015,  0.3858,  0.0892,
           
0.4236,  0.0787,  0.4621,  0.0715,  0.5012,  0.0702,
           
0.5398,  0.0766,  0.5768,  0.0890,  0.6123,  0.1055,
           
0.6466,  0.1244,  0.6805,  0.1440,  0.7147,  0.1630,
           
0.7500,  0.1800
        
],
        [
          -
0.7500,  0.0000, -0.7033,  0.0195, -0.6569,  0.0399,
          -
0.6104,  0.0600, -0.5634,  0.0789, -0.5155,  0.0954,
          -
0.4667,  0.1089, -0.4174,  0.1206, -0.3676,  0.1299,
          -
0.3174,  0.1365, -0.2669,  0.1398, -0.2162,  0.1391,
          -
0.1658,  0.1347, -0.1157,  0.1271, -0.0661,  0.1169,
          -
0.0170,  0.1046,  0.0316,  0.0903,  0.0791,  0.0728,
           
0.1259,  0.0534,  0.1723,  0.0331,  0.2188,  0.0129,
           
0.2656, -0.0064,  0.3122, -0.0263,  0.3586, -0.0466,
           
0.4052, -0.0665,  0.4525, -0.0847,  0.5007, -0.1002,
           
0.5497, -0.1130,  0.5991, -0.1240,  0.6491, -0.1325,
           
0.6994, -0.1380,  0.7500, -0.1400
        
]
      ],
      
WIND_OFFSETS = [
        {
start0.36end0.11},
        {
start0.56end0.16}
      ];

  function 
leaf(ctxtxycwscolor) {
    var 
cw 8,
        
3,
        
b,
        
= (1) * TAU,
        
Math.cos(d),
        
Math.sin(d);

    
ctx.fillStyle color;
    
ctx.strokeStyle color;
    
ctx.lineWidth s;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    
ctx.beginPath();
    
ctx.arc(x        y        ad          Math.PIfalse);
    
ctx.arc(efcMath.PId          false);
    
ctx.arc(efbMath.PId          true );
    
ctx.globalCompositeOperation 'destination-out';
    
ctx.fill();
    
ctx.globalCompositeOperation 'source-over';
    
ctx.stroke();
  }

  function 
swoosh(ctxtcxcycwsindextotalcolor) {
    
/= 2500;

    var 
path WIND_PATHS[index],
        
= (index WIND_OFFSETS[index].start) % total,
        
= (index WIND_OFFSETS[index].end  ) % total,
        
= (index                            ) % total,
        
bdfi;

    
ctx.strokeStyle color;
    
ctx.lineWidth s;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    if(
1) {
      
ctx.beginPath();

      
*= path.length 1;
      
b  Math.floor(a);
      
-= b;
      
*= 2;
      
+= 2;

      
ctx.moveTo(
        
cx + (path[2] * (a) + path[b    ] * a) * cw,
        
cy + (path[1] * (a) + path[1] * a) * cw
      
);

      if(
1) {
        
*= path.length 1;
        
d  Math.floor(c);
        
-= d;
        
*= 2;
        
+= 2;

        for(
b!== d+= 2)
          
ctx.lineTo(cx path[i] * cwcy path[1] * cw);

        
ctx.lineTo(
          
cx + (path[2] * (c) + path[d    ] * c) * cw,
          
cy + (path[1] * (c) + path[1] * c) * cw
        
);
      }

      else
        for(
b!== path.length+= 2)
          
ctx.lineTo(cx path[i] * cwcy path[1] * cw);

      
ctx.stroke();
    }

    else if(
1) {
      
ctx.beginPath();

      
*= path.length 1;
      
d  Math.floor(c);
      
-= d;
      
*= 2;
      
+= 2;

      
ctx.moveTo(cx path[0] * cwcy path[1] * cw);

      for(
2!== d+= 2)
        
ctx.lineTo(cx path[i] * cwcy path[1] * cw);

      
ctx.lineTo(
        
cx + (path[2] * (c) + path[d    ] * c) * cw,
        
cy + (path[1] * (c) + path[1] * c) * cw
      
);

      
ctx.stroke();
    }

    if(
1) {
      
*= path.length 1;
      
f  Math.floor(e);
      
-= f;
      
*= 2;
      
+= 2;

      
leaf(
        
ctx,
        
t,
        
cx + (path[2] * (e) + path[f    ] * e) * cw,
        
cy + (path[1] * (e) + path[1] * e) * cw,
        
cw,
        
s,
        
color
      
);
    }
  }

  var 
Skycons = function(opts) {
        
this.list        = [];
        
this.interval    null;
        
this.color       opts && opts.color opts.color "black";
        
this.resizeClear = !!(opts && opts.resizeClear);
      };

  
Skycons.CLEAR_DAY = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
sun(ctxt0.50.5sSTROKEcolor);
  };

  
Skycons.CLEAR_NIGHT = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
moon(ctxt0.50.5sSTROKEcolor);
  };

  
Skycons.PARTLY_CLOUDY_DAY = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
sun(ctxt0.6250.3750.75STROKEcolor);
    
cloud(ctxt0.3750.6250.75STROKEcolor);
  };

  
Skycons.PARTLY_CLOUDY_NIGHT = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
moon(ctxt0.6670.3750.75STROKEcolor);
    
cloud(ctxt0.3750.6250.75STROKEcolor);
  };

  
Skycons.CLOUDY = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
cloud(ctxt0.50.5sSTROKEcolor);
  };

  
Skycons.RAIN = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
rain(ctxt0.50.370.9STROKEcolor);
    
cloud(ctxt0.50.370.9STROKEcolor);
  };

  
Skycons.SLEET = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
sleet(ctxt0.50.370.9STROKEcolor);
    
cloud(ctxt0.50.370.9STROKEcolor);
  };

  
Skycons.SNOW = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
snow(ctxt0.50.370.9STROKEcolor);
    
cloud(ctxt0.50.370.9STROKEcolor);
  };

  
Skycons.WIND = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh);

    
swoosh(ctxt0.50.5sSTROKE02color);
    
swoosh(ctxt0.50.5sSTROKE12color);
  };

  
Skycons.FOG = function(ctxtcolor) {
    var 
ctx.canvas.width,
        
ctx.canvas.height,
        
Math.min(wh),
        
STROKE;

    
fogbank(ctxt0.50.320.75kcolor);

    
/= 5000;

    var 
Math.cos((t       ) * TAU) * 0.02,
        
Math.cos((0.25) * TAU) * 0.02,
        
Math.cos((0.50) * TAU) * 0.02,
        
Math.cos((0.75) * TAU) * 0.02,
        
0.936,
        
Math.floor(0.5) + 0.5,
        
Math.floor(2.5) + 0.5;

    
ctx.strokeStyle color;
    
ctx.lineWidth k;
    
ctx.lineCap "round";
    
ctx.lineJoin "round";

    
line(ctx0.2 0.5e0.8 0.5e);
    
line(ctx0.2 0.5f0.8 0.5f);
  };

  
Skycons.prototype = {
    
_determineDrawingFunction: function(draw) {
      if(
typeof draw === "string") {
        
draw draw.toUpperCase().replace(/-/g"_");
        return 
Skycons.hasOwnProperty(draw) ? Skycons[draw] : null;
      }
    },
    
add: function(eldraw) {
      var 
obj;

      if(
typeof el === "string")
        
el document.getElementById(el);

      
// Does nothing if canvas name doesn't exists
      
if(el === null)
        return;

      
draw this._determineDrawingFunction(draw);

      
// Does nothing if the draw function isn't actually a function
      
if(typeof draw !== "function")
        return;

      
obj = {
        
elementel,
        
contextel.getContext("2d"),
        
drawingdraw
      
};

      
this.list.push(obj);
      
this.draw(objKEYFRAME);
    },
    
set: function(eldraw) {
      var 
i;

      if(
typeof el === "string")
        
el document.getElementById(el);

      for(
this.list.lengthi--; )
        if(
this.list[i].element === el) {
          
this.list[i].drawing this._determineDrawingFunction(draw);
          
this.draw(this.list[i], KEYFRAME);
          return;
        }

      
this.add(eldraw);
    },
    
remove: function(el) {
      var 
i;

      if(
typeof el === "string")
        
el document.getElementById(el);

      for(
this.list.lengthi--; )
        if(
this.list[i].element === el) {
          
this.list.splice(i1);
          return;
        }
    },
    
draw: function(objtime) {
      var 
canvas obj.context.canvas;

      if(
this.resizeClear)
        
canvas.width canvas.width;

      else
        
obj.context.clearRect(00canvas.widthcanvas.height);

      
obj.drawing(obj.contexttimethis.color);
    },
    
play: function() {
      var 
self this;

      
this.pause();
      
this.interval requestInterval(function() {
        var 
now Date.now(),
            
i;

        for(
self.list.lengthi--; )
          
self.draw(self.list[i], now);
      }, 
1000 60);
    },
    
pause: function() {
      var 
i;

      if(
this.interval) {
        
cancelInterval(this.interval);
        
this.interval null;
      }
    }
  };

  global.
Skycons Skycons;
}(
this));
?>
Онлайн: 4
Реклама