Created
November 29, 2011 17:22
-
-
Save tricknotes/1405598 to your computer and use it in GitHub Desktop.
refactoring-demo for SaCSS vol.29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window) { | |
var canvas = document.getElementById('canvas'); | |
window.fillRect(canvas); | |
})(window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fillRect = require('./rect').fillRect; | |
var Canvas = require('term-canvas'); | |
var canvas = new Canvas(50, 50); | |
fillRect(canvas); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SaCSS vol.29 で行ったライブコーディングの資料です。
リファクタリング進めながら、クライアントサイドで動かしていた Canvas を
Node を使ってターミナル上でも動かせるようにしていきました。
一つのコミットで一つのリファクタリングをしているつもりです。
Usage
ブラウザで動作させる場合:
Node.js で動作させる場合: