Astro Classes

This commit is contained in:
2015-08-14 21:06:23 +08:00
parent d3f924adf3
commit 0a25f87965
157 changed files with 11676 additions and 2 deletions

View File

@@ -0,0 +1,77 @@
(function(){
var ns = __namespace( "Astro.Mechanism.CharacterCloud" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
var CharacterCloud = {};
// Character cloud creates a cloud of character with randomized properties
var create = function( ch, char_class, size, cloudRange, charSize )
{
var cloudMap = Dand.wrapc( "characterCloud" )
, charElmt
, rx, ry, rs
, cs = charSize || 15
, l_l = cloudRange.lowerLimit
// vertical range
, vr = cloudRange.upperLimit - l_l
, lf_l = cloudRange.leftLimit
// horizontal range
, hr = cloudRange.rightLimit
, charStack = ( ch instanceof Array );
;
// The loop is CPU intensive
// we need to focus on reducing the CPU usage
if( charStack )
{
var l = ch.length;
for(var i = 0; i < size; i ++)
{
rx = String( lf_l + Math.random()*hr ) + "%";
ry = String( l_l + Math.random()*vr ) + "%";
rs = Math.random()*cs;
charElmt = Dand.wrap('span', null, char_class, ch[Math.floor(Math.random()*l)]);
var cE_style = charElmt.style;
cE_style.position = "absolute";
cE_style.left = rx;
cE_style.top = ry;
// cE_style.opacity = Math.random() + "";
cE_style.fontSize = rs + "em";
cE_style.marginTop = marginLeft = String( -0.5*rs ) + "em";
cloudMap.appendChild(charElmt);
}
}
else
{
for(var i = 0; i < size; i ++)
{
rx = String(lf_l + Math.random()*hr) + "%";
ry = String(l_l + Math.random()*vr) + "%";
rs = Math.random()*15;
charElmt = Dand.wrap('span', null, char_class, ch);
var cE_style = charElmt.style;
cE_style.position = "absolute";
cE_style.left = rx;
cE_style.top = ry;
// cE_style.opacity = String(Math.random());
cE_style.fontSize = String(rs) + "em";
cE_style.marginTop = marginLeft = String( -0.5*rs ) + "em";
cloudMap.appendChild( charElmt );
}
}
return cloudMap;
};
ns[ NS_EXPORT ]( EX_FUNC, "create", create );
})();