Last active
January 25, 2016 15:25
-
-
Save Hamcha/332edcae1ef9b4fd5da9 to your computer and use it in GitHub Desktop.
Speedcoding lib v2.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Speedcoding library by @hamcha | |
// ver. 2.1 | |
// Oval function by Deven Kalra | |
w=h=600;_w=window;_d=document;_fs=!w; | |
for(i in mf=Object.getOwnPropertyNames(Math))_w[mf[i]]=Math[mf[i]]; | |
function clear(){$.ce(0,0,w,h)} | |
function clearp(a){$.fillStyle="rgba(255,255,255,"+a+")";$.fc(0,0,w,h);$.fillStyle="#000"} | |
function f(){$.fl()} | |
function s(){$.sr()} | |
function rect(x,y,w,h){$.ba();$.rc(x,y,w,h)} | |
function box(x,y,w,h){rect(x-w/2,y-h/2,w,h)} | |
function circle(x,y,r){$.ba();$.ac(x,y,r,0,PI*2)} | |
function oval(x,y,X,Y){$.sv();$.ba();$.ta(x-X,y-Y);$.sa(X,Y);$.ac(1,1,1,0,2*PI,0);$.rr()} | |
function poly(x,y,l,s,o){$.ba();$.mv(x+sin(o)*l,y+cos(o)*l);for(_i=s;_i--;)$.ln(x+sin(o+_i/s*PI*2)*l,y+cos(o+_i/s*PI*2)*l)} | |
function line(x,y,X,Y){$.ba();$.mv(x,y);$.ln(X,Y);s()} | |
function _f(a){return(a*256)|0} | |
function sw(s){$.lineWidth=s} | |
function scol(r,g,b,a){if(!a)a=1;$.strokeStyle="rgba("+[r,g,b].map(_f)+","+a+")"} | |
function fcol(r,g,b,a){if(!a)a=1;$.fillStyle="rgba("+[r,g,b].map(_f)+","+a+")"} | |
function font(t){$.font=t} | |
function ftxt(t,x,y){$.fx(t,x,y)} | |
function stxt(t,x,y){$.sx(t,x,y)} | |
function blend(m){$.globalCompositeOperation=m} | |
function _r(){requestAnimationFrame(_r);ms=new Date;t=ms/1e3;if(_w.render)render()} | |
function init(W,H){ | |
if((typeof W)[0]=="n")w=W,h=H | |
else if(W===true)w=_w.innerWidth,h=_w.innerHeight,_fs=true | |
_c=_d.createElement("canvas");_c.width=w;_c.height=h; | |
if(!_fs)_c.style.border="1px solid #ccc",_c.style.margin="5px" | |
else _w.onresize=function(){w=_w.innerWidth;h=_w.innerHeight;_c.width=w;_c.height=h} | |
_d.body.appendChild(_c);$=_c.getContext("2d");for(Z in $)$[Z[0]+(Z[6]||Z[2])]=$[Z];_r() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Se alla fine di init() ci metti un "return $" imho è tutto di guadagnato: metti che vuoi usare qualche feature non compresa nella lib (es. il testo): basta fare $ = init(); $.fillText(blabla).