Giter Site home page Giter Site logo

wowiconify's Introduction

Mihail Szabolcs

Senior Software Engineer, Open Source Evangelist, Renaissance Man.

GitHub Contributions Snake

In order to play snake in the contributions matrix below, perform the following incantations:

  1. create a bookmark with the code below
  2. click on it while on this page
  3. scroll down to the contributions matrix
  4. use the arrow keys to control the snake
javascript:(function(){class t{constructor(){this.reset(),window.addEventListener("keydown",this._onKeyDown)}reset=()=>{this.left=!1,this.right=!1,this.up=!1,this.down=!1};_onKeyDown=t=>{switch(t.preventDefault(),t.stopPropagation(),t.keyCode){case 37:this.left=!0;break;case 38:this.up=!0;break;case 39:this.right=!0;break;case 40:this.down=!0}}}const e="GitHub Contributions Snake",l="You can only play "+e+" on your GitHub profile!";class s{constructor(){let s=[],i=0,r=0;const a=document.querySelectorAll(".js-calendar-graph-svg g .ContributionCalendar-day");if(0<a.length){a.forEach(t=>t.setAttribute("data-level",0)),i=Math.ceil(a.length/7),r=7,s=Array(i*r).fill(-1);for(let e=0;e<r;e++)for(let t=0;t<i;t++)s[t+e*i]=a[e+t*r]}else document.querySelectorAll(".js-calendar-graph-table tr").forEach(t=>{let e=t.querySelectorAll(".ContributionCalendar-day");if(0<e.length){e.length>i&&(i=e.length),e.forEach(t=>{t.removeAttribute("tabindex"),t.setAttribute("data-level",0),s.push(t)});for(let t=e.length;t<i;t++)s.push(-1);r++}});if(0==i||0==r)throw alert(l),l;console.log(e,i,r),this.tiles=s,this.w=i,this.h=r}set_tile_at=(t,e,s)=>{var{tiles:i,w:r}=this;let a=i[e+s*r];a&&-1!=a&&a.setAttribute("data-level",t)};get_tile_at=(t,e)=>{var{tiles:s,w:i}=this;let r=s[t+e*i];return r&&-1!=r?parseInt(r.getAttribute("data-level")):-1}}class i{constructor(t){this.grid=t,this.dx=1,this.dy=0,this.dt=0,this.tiles=[{x:2,y:3},{x:3,y:3},{x:4,y:3}],t.set_tile_at(2,5,5)}moveTo=(t,e)=>{this.dx=t,this.dy=e};draw=()=>{const{tiles:t,grid:e}=this;for(var s=0;s<t.length;s++){var i=t[s];e.set_tile_at(4,i.x,i.y)}};update=t=>{const{dx:e,dy:s,grid:i,tiles:r}=this;if(this.dt+=t,!(this.dt<.2)){this.dt=0;var a=(t=r[r.length-1]).x+e,l=t.y+s;if(!(a<0||a>i.w-1||l<0||l>i.h-1)&&-1!=(t=i.get_tile_at(a,l))&&4!=t)if(r.push({x:a,y:l}),t<=1){t=r.shift();i.set_tile_at(0,t.x,t.y)}else for(let t=0;t<7;t++){a=Math.floor(1+Math.random()*(i.w-1)),l=Math.floor(1+Math.random()*(i.h-1));if(0==i.get_tile_at(a,l)){i.set_tile_at(2,a,l);break}}}}}(new class{constructor(){this.keyboard=new t,this.grid=new s,this.snake=new i(this.grid)}run=()=>{this.last=0,this._tick(0)};_tick=t=>{const{keyboard:e,snake:s,last:i,_tick:r}=this;var a=.001*(t-i);this.last=t,e.left?s.moveTo(-1,0):e.right?s.moveTo(1,0):e.up?s.moveTo(0,-1):e.down&&s.moveTo(0,1),s.update(a),s.draw(),e.reset(),requestAnimationFrame(r)}}).run()})();

wowiconify's People

Contributors

icebreaker avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.