Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / node_modules / nodeunit / node_modules / tap / node_modules / difflet / node_modules / charm / example / http_spin.js
1 var http = require('http');
2 var charmer = require('../');
3
4 http.createServer(function (req, res) {
5     res.setHeader('content-type', 'text/ansi');
6     
7     var charm = charmer(res);
8     charm.reset();
9     
10     var radius = 10;
11     var theta = 0;
12     var points = [];
13
14     var iv = setInterval(function () {
15         var x = 2 + (radius + Math.cos(theta) * radius) * 2;
16         var y = 2 + radius + Math.sin(theta) * radius;
17         
18         points.unshift([ x, y ]);
19         var colors = [ 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta' ];
20         
21         points.forEach(function (p, i) {
22             charm.position(p[0], p[1]);
23             var c = colors[Math.floor(i / 12)];
24             charm.background(c).write(' ')
25         });
26         points = points.slice(0, 12 * colors.length - 1);
27         
28         theta += Math.PI / 40;
29     }, 50);
30     
31     req.connection.on('end', function () {
32         clearInterval(iv);
33         charm.destroy();
34     });
35 }).listen(8081);