Skip to content

Instantly share code, notes, and snippets.

@tricknotes
Created November 29, 2011 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tricknotes/1405598 to your computer and use it in GitHub Desktop.
Save tricknotes/1405598 to your computer and use it in GitHub Desktop.
refactoring-demo for SaCSS vol.29
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
width: 100%;
height: 100%;
background-color: #666;
}
canvas {
width: 600px;
height: 400px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script src="rect.js"></script>
<script src="main.js"></script>
</body>
</html>
(function(window) {
var canvas = document.getElementById('canvas');
window.fillRect(canvas);
})(window);
(function(global) {
global.fillRect = function (canvas) {
var ctx = canvas.getContext('2d');
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "red";
ctx.fillRect(2, 2, 50, 30);
}
})(typeof window == 'undefined' ? module.exports : window);
var fillRect = require('./rect').fillRect;
var Canvas = require('term-canvas');
var canvas = new Canvas(50, 50);
fillRect(canvas);
@tricknotes
Copy link
Author

SaCSS vol.29 で行ったライブコーディングの資料です。

リファクタリング進めながら、クライアントサイドで動かしていた Canvas を
Node を使ってターミナル上でも動かせるようにしていきました。

一つのコミットで一つのリファクタリングをしているつもりです。

Usage

ブラウザで動作させる場合:

$ open index.html

Node.js で動作させる場合:

$ node term.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment