Permalink
Browse files

tea. earl grey. hot.

  • Loading branch information...
0 parents commit 8721f9d7b4e5bb3d38c53521c1087536d57974ad @substack committed Jul 1, 2012
Showing with 171 additions and 0 deletions.
  1. +18 −0 LICENSE
  2. +36 −0 README.markdown
  3. +11 −0 cup.txt
  4. +2 −0 example/hot.js
  5. +72 −0 index.js
  6. +32 −0 package.json
18 LICENSE
@@ -0,0 +1,18 @@
+This software is released under the MIT license:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
+# earl-grey
+
+[Tea. Earl grey. Hot.](https://www.youtube.com/watch?v=xHSD0tR2IOU)
+
+# example
+
+``` js
+var tea = require('earl-grey').hot();
+tea.pipe(process.stdout);
+```
+
+![tea earl grey hot](http://substack.net/images/screenshots/tea_earl_grey_hot.png)
+
+# methods
+
+``` js
+var tea = require('earl-grey')
+```
+
+## tea.hot()
+
+Return a readable animated hot ansi tea stream.
+
+## tea.cold()
+
+Return a readable cold ansi tea stream.
+
+# install
+
+```
+npm install earl-grey
+```
+
+# license
+
+MIT
11 cup.txt
@@ -0,0 +1,11 @@
+ xxxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxxx xx
+ xxxxxxxxxxxxxxxxxxxxxxx xx
+ xxxxxxxxxxxxxxxxxxxxxxx xx
+ xxxxxxxxxxxxxxxxxxxxxxx xx
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxx
@@ -0,0 +1,2 @@
+var tea = require('../').hot();
+tea.pipe(process.stdout);
@@ -0,0 +1,72 @@
+var charm = require('charm');
+var fs = require('fs');
+var cupData = fs.readFileSync(__dirname + '/cup.txt');
+
+exports.cup = cup;
+exports.cold = cup;
+
+function cup (cb) {
+ var c = charm();
+ var indent = Array(30+1).join(' ');
+ process.nextTick(function () {
+ c.foreground('white');
+ c.write(indent);
+ for (var i = 0; i < cupData.length; i++) {
+ var s = String.fromCharCode(cupData[i]);
+
+ if (s === 'x') {
+ c.background('white').write(' ');
+ c.display('reset').foreground('white');
+ }
+ else if (s === '\n') {
+ c.write('\n' + indent);
+ }
+ else c.write(s);
+ }
+ if (cb) cb();
+ });
+ return c;
+}
+
+exports.hot = function () {
+ process.nextTick(function () {
+ c.reset();
+ c.down(14);
+ });
+ var cupRows = cupData.toString().split('\n').length;
+ var particles = [];
+
+ var c = cup(function () {
+ setInterval(function () {
+ particles.push([ 30 + 3 + Math.random() * 22, 14, '.' ]);
+
+ if (Math.random() > 0.5) {
+ particles.push([ 30 + 3 + Math.random() * 22, 14, '*' ]);
+ }
+
+ for (var i = 14; i >= 1; i--) {
+ c.position(1,i);
+ c.erase('line');
+ particles.forEach(function (p) {
+ if (Math.floor(p[1]) === i) {
+ c.position(Math.floor(p[0]), i);
+ c.write(p[2]);
+ }
+ });
+ }
+
+ particles.forEach(function (p) {
+ p[0] += Math.random() - 0.5;
+ p[1] -= 1;
+ });
+ particles = particles.filter(function (p) {
+ return p[1] >= 1 && Math.random() > 0.2;
+ });
+
+ console.log();
+ c.position(1, 1);
+ }, 100);
+ });
+
+ return c;
+};
@@ -0,0 +1,32 @@
+{
+ "name" : "earl-grey",
+ "version" : "0.0.0",
+ "description" : "animated ansi earl grey tea",
+ "main" : "index.js",
+ "bin" : {},
+ "directories" : {
+ "example" : "example",
+ "test" : "test"
+ },
+ "dependencies" : {
+ "charm" : "~0.1.0"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "git://github.com/substack/earl-grey.git"
+ },
+ "homepage" : "https://github.com/substack/earl-grey",
+ "keywords" : [
+ "tea",
+ "earl",
+ "grey",
+ "hot"
+ ],
+ "author" : {
+ "name" : "James Halliday",
+ "email" : "mail@substack.net",
+ "url" : "http://substack.net"
+ },
+ "license" : "MIT",
+ "engine" : { "node" : ">=0.6" }
+}

0 comments on commit 8721f9d

Please sign in to comment.