Giter Club home page Giter Club logo

hanoi's Introduction

汉诺塔

向十年前教我递归函数的老师致敬

今天有雅兴写了一个JS版的汉诺塔演示程序,不到1K大。

可以直接复制粘贴如下代码到浏览器的console中运行查看结果:

function f(t,e,n,i,o){X.fillStyle=t,X.fillRect(e,n,i,o)}function D(t,e){f("#0F0",t-3,20,6,200);for(var n=0;n<d[e].length;n++){var i=30*d[e][n],o=20,c=t-i/2,a=(10-n)*o,r=X.createLinearGradient(c,a,c+i,a+o);r.addColorStop(0,"#F00"),r.addColorStop(1,"#FFF"),f(r,c,a,i,o)}}function s(){f("#000",0,0,1e3,500),D(150,"a"),D(450,"b"),D(750,"c")}function m(t,e){ai.push(function(){d[e].push(d[t].pop()),s()})}function M(t,e,n,i){return 1==t?void m(e,i):(M(t-1,e,i,n),m(e,i),void M(t-1,n,e,i))}function r(){ai.length&&(ai.shift()(),setTimeout(r,1e3))}document.write('<canvas id="c" width="900" height="240"></canvas>');var X=document.getElementById("c").getContext("2d"),d={a:[9,8,7,6,5,4,3,2,1],b:[],c:[]},ai=[];M(9,"a","b","c"),s(),setTimeout(r,1e3);

hanoi's People

Contributors

robertli0719 avatar

Stargazers

Yan Hong avatar

Watchers

James Cloos 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.