17と18のリビジョン間の差分
2014-02-08 16:39:33時点のリビジョン17
サイズ: 5596
編集者: grafi
コメント:
2014-02-08 16:44:43時点のリビジョン18
サイズ: 613
編集者: grafi
コメント:
削除された箇所はこのように表示されます。 追加された箇所はこのように表示されます。
行 5: 行 5:
<!--
   This script is based on sl.js by teramako. (Though license is not explicitly stated, re-using for just a joke should be no problem...)
   see slide <http://teramako.github.io/doc/LLTV20090829/lltv.html>
       source <https://github.com/vimpr/vimperator-plugins/pull/43>
-->
<script>
(function () {

function SL() { this.init.apply(this, arguments); }
SL.prototype = { // {{{
  init: function (elm, fontSize, frameRate, speed) {
    this.canvas = elm;
    this.ctx = this.canvas.getContext("2d");

    this.width = window.innerWidth;
    this.height = this.lineNum * fontSize;
    this.canvas.setAttribute("width", this.width);
    this.canvas.setAttribute("height", this.height);

    this.fontSize = fontSize;
    this.frameRate = frameRate;
    this.speed = speed;

    this.interval = null;
    this.count = 0;
  },

  lineNum: 16,

  start: function () {
    this.ctx.clearRect(0, 0, this.width, this.height);
    this.ctx.font = this.fontSize + "px monospace";
    this.ctx.textAlign = 'start'

    var sl = this.slGenerator();
    var self = this;
    this.interval = window.setInterval(function () {
      self.draw(sl);
    }, this.frameRate);
  },

  draw: function (gene) {
    this.count++;
    this.ctx.clearRect(0, 0, this.width, this.height);
    this.ctx.fillStyle = "rgb(0,0,0)";

    var data = gene.next();
    var x = this.width - this.count * this.speed;
    data.forEach (function (str, i) {
      this.ctx.fillText(str, x, this.height / this.lineNum * (i+1));
    }, this);
  },

  merge: function () {
    var data = [];
    for (var k = 0; k < arguments.length; k++) {
      arguments[k].forEach(function (str, i) {
        if (!data[i]) data[i] = "";
        data[i] = data[i] + str;
      });
    }
    return data;
  },

  slGenerator: function () {
    var data = this.slData;
    var self = this;

    var i = 0;
    return {
      next: (function () {
        i++;
        return [].concat(data.steam[i%data.steam.length], self.merge(data.body.concat(data.wheel[i%data.wheel.length]), data.coal));
      })
    }
  },

  slData: { /// {{{
    steam: [
      [
        " (@@) ( ) (@) ( ) @@ () @ O @ O @",
        " ( )",
        " (@@@@)",
        " ( )",
        "",
        " (@@@)",
      ],[
        " ( ) (@@) ( ) (@) () @@ O @ O @ O",
        " (@@@)",
        " ( )",
        " (@@@@)",
        "",
        " ( )"
      ]
    ],
    body: [
      " ==== ________ ___________ ",
      " _D _| |_______/ \\__I_I_____===__|_________| ",
      " |(_)--- | H\\________/ | | =|___ ___| ",
      " / | | H | | | | ||_| |_|| ",
      " | | | H |__--------------------| [___] | ",
      " | ________|___H__/__|_____/[][]~\\_______| | ",
      " |/ | |-----------I_____I [][] [] D |=======|__ "
    ],
    wheel: [
      [
        "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
        " |/-=|___|= || || || |_____/~\\___/ ",
        " \\_/ \\O=====O=====O=====O_/ \\_/ "
      ],[
        "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
        " |/-=|___|= || || || |_____/~\\___/ ",
        " \\_/ \\_O=====O=====O=====O/ \\_/ "
      ],[
        "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
        " |/-=|___|= O=====O=====O=====O|_____/~\\___/ ",
        " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
      ],[
        "__/ =| o |=-~O=====O=====O=====O\\ ____Y___________|__ ",
        " |/-=|___|= || || || |_____/~\\___/ ",
        " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
      ],[
        "__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__ ",
        " |/-=|___|= || || || |_____/~\\___/ ",
        " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
      ],[
        "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
        " |/-=|___|=O=====O=====O=====O |_____/~\\___/ ",
        " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
      ]
    ],
    coal: [
      " ",
      " ",
      " _________________ ",
      " _| \\_____A ",
      " =| | ",
      " -| | ",
      "__|________________________|_ ",
      "|__________________________|_ ",
      " |_D__D__D_| |_D__D__D_| ",
      " \\_/ \\_/ \\_/ \\_/ "
    ],
  }, /// }}}
};

// }}}

var sl = new SL(document.getElementById("sl"), 16, 60, 20);
sl.start();
})();
</script>
<script src="/grafi?action=AttachFile&do=get&target=sl.js" />

grafi