Skip to content
Proyek

tj/term-canvas

Lihat di GitHub

Tentang

javascript canvas api for your terminal!

Alat pengembangan

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
0
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

term-canvas

experimental html canvas API for the terminal written with node.js.

terminal canvas chart

terminal canvas grid

Installation

$ npm install term-canvas

Examples

States

state

Source:

var Canvas = require('term-canvas');

var canvas = new Canvas(50, 100)
  , ctx = canvas.getContext('2d');

ctx.fillStyle = 'red';
ctx.fillRect(5, 5, 20, 10);
ctx.save();

ctx.fillStyle = 'blue';
ctx.fillRect(6, 6, 18, 8);
ctx.save();

ctx.fillStyle = 'yellow';
ctx.fillRect(7, 7, 16, 6);

ctx.restore();
ctx.fillRect(8, 8, 14, 4);

ctx.restore();
ctx.fillRect(9, 9, 12, 2);

console.log('\n\n\n\n\n');
ctx.resetState();

Fill styles

Static colored rects with no draw loop:

rects

Source:

var Canvas = require('term-canvas');

var canvas = new Canvas(50, 100)
  , ctx = canvas.getContext('2d');

ctx.fillStyle = 'red';
ctx.fillRect(5, 5, 20, 10);

ctx.fillStyle = 'blue';
ctx.fillRect(27, 5, 20, 10);

ctx.fillStyle = 'yellow';
ctx.fillRect(49, 5, 20, 10);

console.log('\n\n\n');
ctx.resetState();

Animation

animated rects

Source:

var Canvas = require('term-canvas')
  , size = process.stdout.getWindowSize();

process.on('SIGINT', function(){
  ctx.reset();
  process.nextTick(function(){
    process.exit();
  });
});

process.on('SIGWINCH', function(){
  size = process.stdout.getWindowSize();
  canvas.width = size[0];
  canvas.height = size[1];
  x2 = x = 1;
  y2 = y = 1;
});

var canvas = new Canvas(size[0], size[1])
  , ctx = canvas.getContext('2d')
  , x = 1
  , y = 2
  , sx = 2
  , sy = 2
  , x2 = 1
  , y2 = 5
  , sx2 = 1
  , sy2 = 1;

ctx.hideCursor();
setInterval(function(){
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.strokeStyle = 'blue';
  ctx.strokeRect(1, 1, canvas.width - 1, canvas.height - 1);
  ctx.strokeStyle = 'green';
  ctx.strokeRect(x += sx, y += sy, 30, 5);
  ctx.fillStyle = 'yellow';
  ctx.fillRect(x2 += sx2, y2 += sy2, 12, 5);
  ctx.fillStyle = 'white';
  ctx.fillText('Rectangle', x2 + 1, y2 + 2);
  ctx.moveTo(0, 10);
  if (x + 30 >= canvas.width || x <= 1) sx = -sx;
  if (x2 + 10 >= canvas.width || x2 <= 1) sx2 = -sx2;
  if (y + 5 >= canvas.height || y <= 1) sy = -sy;
  if (y2 + 5 >= canvas.height || y2 <= 1) sy2 = -sy2;
}, 1000 / 20);

Tests

There are none! currently testing with OSX "Terminal".

License

(The MIT License)

Copyright (c) 2011 TJ Holowaychuk <[email protected]>

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.

Jelajahi proyek terkait

Memuat…