-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrabbler.min.js
1 lines (1 loc) · 1.73 KB
/
scrabbler.min.js
1
(function(e){function a(e,t){e=e*(o/180);i=n+Math.cos(e)*t;s=r+Math.sin(e)*t}function f(e,t){var n;for(n=0;n<t.length;n++){if(t[n].x==e.x&&t[n].y==e.y){return true}}return false}function l(e,t){if(e.length>1){for(var n=false,r=-1,i=e.length,s=i-1;++r<i;s=r)(e[r].y<=t.y&&t.y<e[s].y||e[s].y<=t.y&&t.y<e[r].y)&&t.x<(e[s].x-e[r].x)*(t.y-e[r].y)/(e[s].y-e[r].y)+e[r].x&&(n=!n);return n}else return true}var t="http://www.w3.org/2000/svg";var n=0;var r=0;var i=0;var s=0;var o=3.14159265359;var u=[];e.fn.scrabbler=function(o){var c=e.extend({polygon:[],angle:60,size:40,angleType:"fixed",sizeType:"fixed",resizeContainer:false,noLines:-1},o);var h=e(this);if(c.resizeContainer)h.css({width:window.innerWidth+"px",height:window.innerHeight+"px"});if(c.resizeContainer)e(window).resize(function(){h.css({width:window.innerWidth+"px",height:window.innerHeight+"px"})});var p=window.innerWidth;var d=window.innerHeight;n=parseInt(p)/2;r=60;var v=0;var m=setInterval(function(){p=h.css("width");d=h.css("height");var e=Math.floor(Math.random()*1e3+1);var o=Math.floor(Math.random()*2e3+1);var g=Math.floor(Math.random()*180+1);var y=Math.floor(Math.random()*40+10);var b=c.size;var w=c.angle;if(c.angleType==="mixed"){w=c.angle/(o%4)}if(c.sizeType==="mixed"){b=c.size/(o%4)}a(e%o*w,b);if(l(c.polygon,{x:i,y:s})&&i>0&&s>0&&i<parseInt(p)&&s<parseInt(d)&&!f({x:i,y:s},u)){var E=document.createElementNS(t,"line");E.setAttributeNS(null,"id","myLine");E.setAttributeNS(null,"x1",n);E.setAttributeNS(null,"y1",r);E.setAttributeNS(null,"x2",i);E.setAttributeNS(null,"y2",s);E.setAttributeNS(null,"stroke","rgb("+(g%50+150)+","+(o%50+150)+","+(y%50+150)+")");document.getElementById(h.attr("id")).appendChild(E);u.push({x:i,y:s});n=i;r=s}v++;if(v==c.noLines)clearInterval(m)},5)}})(jQuery)