Skip to content
Browse files

messy to start with but it works server and browser side

  • Loading branch information...
0 parents commit 0c1bc5425cf0deac3600245edacef0dd6c2e2b07 @substack substack committed Jul 28, 2011
Showing with 66 additions and 0 deletions.
  1. +6 −0 ex.js
  2. +8 −0 index.html
  3. +25 −0 index.js
  4. +12 −0 main.js
  5. +15 −0 server.js
6 ex.js
@@ -0,0 +1,6 @@
+var fs = require('fs');
+var heatmap = require('./');
+
+var c = heatmap(500,500);
+var buf = c.toBuffer();
+fs.writeFileSync('out.png', buf);
8 index.html
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>heatmap demo</title>
+ <script type="text/javascript" src="/browserify.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
25 index.js
@@ -0,0 +1,25 @@
+var mrcolor = require('mrcolor');
+
+if (process.argv) {
+ var Canvas = (require)('canvas');
+}
+
+var exports = module.exports = function (canvas) {
+ if (typeof canvas !== 'object') {
+ canvas = new Canvas(arguments[0], arguments[1]);
+ }
+
+ var ctx = canvas.getContext("2d");
+ var g = ctx.createRadialGradient(250, 250, 20, 250, 250, 150);
+
+ var colors = mrcolor.take(6).forEach(function (c, i) {
+ var a = Math.floor(255 * (1 - i / 5));
+ var rgba = c.rgb().concat(a).join(',');
+ g.addColorStop(i / 5, 'rgba(' + rgba + ')');
+ });
+
+ ctx.fillStyle = g;
+ ctx.fillRect(100, 100, 300, 300);
+
+ return canvas;
+};
12 main.js
@@ -0,0 +1,12 @@
+var $ = require('jquery-browserify');
+var heatmap = require('./');
+
+$(window).ready(function () {
+ var canvas = $('<canvas>').attr({
+ width : 500,
+ height : 500
+ });
+ canvas.appendTo(document.body);
+
+ heatmap(canvas.get(0));
+});
15 server.js
@@ -0,0 +1,15 @@
+var connect = require('connect');
+var app = connect.createServer();
+app.use(connect.static(__dirname));
+
+var browserify = require('browserify');
+var bundle = browserify({
+ entry : __dirname + '/main.js',
+ filter : require('uglify-js'),
+ watch : true
+});
+
+app.use(bundle);
+
+app.listen(8080);
+console.log('Listening on :8080');

0 comments on commit 0c1bc54

Please sign in to comment.
Something went wrong with that request. Please try again.