1 line
7.8 KiB
JavaScript
1 line
7.8 KiB
JavaScript
|
var canvas,delta=[0,0],stage=[window.screenX,window.screenY,window.innerWidth,window.innerHeight];getBrowserDimensions();var theme,worldAABB,world,bodies,elements,text,mouseJoint,themes=[[" #10222B","#95AB63","#BDD684","#E2F0D6","#F6FFE0"],["#362C2A","#732420","#BF734C","#FAD9A0","#736859"],["#0D1114","#102C2E","#695F4C","#EBBC5E","#FFFBB8"],["#2E2F38","#FFD63E","#FFB54B","#E88638","#8A221C"],["#121212","#E6F2DA","#C9F24B","#4D7B85","#23383D"],["#343F40","#736751","#F2D7B6","#BFAC95","#8C3F3F"],["#000000","#2D2B2A","#561812","#B81111","#FFFFFF"],["#333B3A","#B4BD51","#543B38","#61594D","#B8925A"]],iterations=1,timeStep=1/15,walls=[],wall_thickness=200,wallsSetted=!1,createMode=!1,destroyMode=!1,isMouseDown=!1,mouse={x:0,y:0},gravity={x:0,y:1},PI2=2*Math.PI,timeOfLastTouch=0;function init(){canvas=document.getElementById("canvas"),document.onmousedown=onDocumentMouseDown,document.onmouseup=onDocumentMouseUp,document.onmousemove=onDocumentMouseMove,document.ondblclick=onDocumentDoubleClick,document.addEventListener("touchstart",onDocumentTouchStart,!1),document.addEventListener("touchmove",onDocumentTouchMove,!1),document.addEventListener("touchend",onDocumentTouchEnd,!1),window.addEventListener("deviceorientation",onWindowDeviceOrientation,!1),(worldAABB=new b2AABB).minVertex.Set(-200,-200),worldAABB.maxVertex.Set(window.innerWidth+200,window.innerHeight+200),world=new b2World(worldAABB,new b2Vec2(0,0),!0),setWalls(),reset()}function play(){setInterval(loop,25)}function reset(){var i;if(bodies)for(i=0;i<bodies.length;i++){var body=bodies[i];canvas.removeChild(body.GetUserData().element),world.DestroyBody(body),body=null}for(theme=themes[Math.random()*themes.length>>0],document.body.style.backgroundColor=theme[0],bodies=[],elements=[],createInstructions(),i=0;i<10;i++)createBall()}function onDocumentMouseDown(){return isMouseDown=!0,!1}function onDocumentMouseUp(){return isMouseDown=!1,!1}function onDocumentMouseMove(event){mouse.x=event.clientX,mouse.y=event.clientY}function onDocumentDoubleClick(){reset()}function onDocumentTouchStart(event){if(1==event.touches.length){event.preventDefault();var now=(new Date).getTime();if(now-timeOfLastTouch<250)return void reset();timeOfLastTouch=now,mouse.x=event.touches[0].pageX,mouse.y=event.touches[0].pageY,isMouseDown=!0}}function onDocumentTouchMove(event){1==event.touches.length&&(event.preventDefault(),mouse.x=event.touches[0].pageX,mouse.y=event.touches[0].pageY)}function onDocumentTouchEnd(event){0==event.touches.length&&(event.preventDefault(),isMouseDown=!1)}function onWindowDeviceOrientation(event){event.beta&&(gravity.x=Math.sin(event.gamma*Math.PI/180),gravity.y=Math.sin(Math.PI/4+event.beta*Math.PI/180))}function createInstructions(){var element=document.createElement("div");element.width=250,element.height=250,element.style.position="absolute",element.style.left="-200px",element.style.top="-200px",element.style.cursor="default",canvas.appendChild(element),elements.push(element),(circle=document.createElement("canvas")).width=250,circle.height=250;var graphics=circle.getContext("2d");graphics.fillStyle=theme[3],graphics.beginPath(),graphics.arc(125,125,125,0,PI2,!0),graphics.closePath(),graphics.fill(),element.appendChild(circle),(text=document.createElement("div")).onSelectStart=null;var flinks=JSON.parse(localStorage.getItem("logos"));text.innerHTML='<span class="gdtx" style="color:'+theme[0]+'"><img src='+flinks[Math.floor(Math.random()*flinks.length)]+"></img></span>",text.style.color=theme[1],text.style.position="absolute",text.style.left="0px",text.style.top="0px",text.style.fontFamily="Georgia",text.style.textAlign="center",element.appendChild(text),text.style.left=(250-text.clientWidth)/2+"px",text.style.top=(250-text.clientHeight)/2+"px";var circle,b2body=new b2BodyDef;(circle=new b2CircleDef).radius=125,circle.density=1,circle.friction=.3,circle.restitution=.3,b2body.AddShape(circle),b2body.userData={element:element},b2body.position.Set(Math.random()*stage[2],-200*Math.random()),b2body.linearVelocity.Set(400*Math.random()-200,400*Math.random()-200),bodies.pus
|