GithubHelp home page GithubHelp logo

pierrechevalier83 / matrix_display Goto Github PK

View Code? Open in Web Editor NEW
16.0 4.0 1.0 5.11 MB

A rust library to visualise pretty matrixes in cli

Rust 99.88% Shell 0.12%
rust rust-library matrix-display cli unicode

matrix_display's Introduction

Build Status Coverage Status Matrix Display

A simple rust library to visualize 2D matrixes in rust.

  • Supports 256 terminal colours using AnsiTerm
  • Multiple unicode box character sets supported (plain, retro, thin, rounded, thick, double)

Documentation

Click here to access the documentation

Build

Run

  • cargo run --example chess
  • cargo run --example 2048
  • cargo run --example palette

Example: visualising a chess board

extern crate matrix_display;
use matrix_display::*;

fn main() {
    let format = Format::new(7, 3);
	let board = vec!['♜', '♞', '♝', '♛', '♚', '♝', '♞', '♜',
	                 '♟', '♟', '♟', '♟', '♟', '♟', '♟', '♟',
					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
                     ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
					 '♖', '♘', '♗', '♕', '♔', '♗', '♘', '♖',
					 '♙', '♙', '♙', '♙', '♙', '♙', '♙', '♙']
        .iter()
        .enumerate()
		.map(|(i, x)| {
            let ansi_fg = 33;
			let mut ansi_bg = 0;
		    if i % 2 + (i / 8) % 2 == 1 {
			    ansi_bg = 7;
			}
		    cell::Cell::new(x.clone(), ansi_fg, ansi_bg)
			})
        .collect::<Vec<_>>();
    let data = matrix::Matrix::new(8, board);
    let display = MatrixDisplay::new(format, data);
	display.cell_at_cursor_position((13, 6)).color.bg = 10;
    display.print(&mut std::io::stdout(), &style::BordersStyle::None);
}

alt tag

For a working version of the game, see chess-rs

Example: visualising a 2048 game

extern crate matrix_display;
use matrix_display::*;

fn main() {
    let format = Format::new(7, 3);
    let colour_theme = vec![247, 78, 222, 220, 214, 208, 202, 196, 162, 160, 126, 90, 88, 54, 53, 52];
    let board = (0..16)
        .map(|x| {
            cell::Cell::new(2_f64.powi(x + 1),
                      7,
                      *colour_theme.get(x as usize).unwrap() as u8)
        })
        .collect::<Vec<_>>();
    let data = matrix::Matrix::new(4, board);
    let display = MatrixDisplay::new(format, data);
    display.print(&mut std::io::stdout(), &style::BordersStyle::Thick);
}

alt tag

For a working version of the game, see 2048-rs

Example: visualising a 256 colors palette

extern crate matrix_display;
use matrix_display::*;

fn main() {
    let format = Format::new(5, 1);
    let board = (0..256)
        .map(|x| cell::Cell::new(x, 0, x as u8))
        .collect::<Vec<_>>();
    let data = matrix::Matrix::new(8, board);
    let display = MatrixDisplay::new(format, data);
    display.print(&mut std::io::stdout(), &style::BordersStyle::Thin);

alt tag

For a self contained implementation, see palette-rs

TODO

  • Leverage fdehau/tui-rs to avoid redrawing the entire screen at every frame
  • Should help with performance issues with snake-rs, my snake implementations.

matrix_display's People

Contributors

pierrechevalier83 avatar quininer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

stratusfearme21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.