Giter VIP home page Giter VIP logo

tachyonfx's Introduction

tachyonfx

Crate Badge API Badge Deps.rs Badge

tachyonfx is a ratatui library for creating shader-like effects in terminal UIs. This library provides a collection of effects that can be used to enhance the visual appeal of terminal applications, offering capabilities such as color transformations, animations, and complex effect combinations.

demo

Installation

Add tachyonfx to your Cargo.toml:

tachyonfx = "0.5.0"

Overview

Effects

The library includes a variety of effects, loosely categorized as follows:

Color Effects

  • fade_from: Fades from the specified background and foreground colors
  • fade_from_fg: Fades the foreground color from a specified color.
  • fade_to: Fades to the specified background and foreground colors.
  • fade_to_fg: Fades the foreground color to a specified color.
  • hsl_shift: Changes the hue, saturation, and lightness of the foreground and background colors.
  • hsl_shift_fg: Shifts the foreground color by the specified hue, saturation, and lightness over the specified duration.
  • term256_colors: Downsamples to 256 color mode.

Text/Character Effects

  • coalesce: The reverse of dissolve, coalesces text over the specified duration.
  • dissolve: Dissolves the current text over the specified duration.
  • slide_in: Applies a directional sliding in effect to terminal cells.
  • slide_out: Applies a directional sliding out effect to terminal cells.
  • sweep_in: Sweeps in from the specified color.
  • sweep_out: Sweeps out to the specified color.

Timing and Control Effects

  • consume_tick: Consumes a single tick.
  • never_complete: Makes an effect run indefinitely.
  • ping_pong: Plays the effect forwards and then backwards.
  • prolong_start: Extends the start of an effect by a specified duration.
  • prolong_end: Extends the end of an effect by a specified duration.
  • repeat: Repeats an effect indefinitely or for a specified number of times or duration.
  • repeating: Repeats the effect indefinitely.
  • sleep: Pauses for a specified duration.
  • timed_never_complete: Creates an effect that runs indefinitely but has an enforced duration.
  • with_duration: Wraps an effect and enforces a duration on it.

Geometry Effects

  • translate: Moves the effect area by a specified amount.
  • translate_buf: Copies the contents from an aux buffer, moving it by a specified amount.
  • resize_area: Resizes the area of the wrapped effect.

Combination Effects

  • parallel: Runs effects in parallel, all at the same time. Reports completion once all effects have completed.
  • sequence: Runs effects in sequence, one after the other. Reports completion once the last effect has completed.

Other Effects

  • effect_fn: Creates custom effects from user-defined functions, operating over CellIterator.
  • effect_fn_buf: Creates custom effects from functions, operating over Buffer.
  • offscreen_buffer: Wraps an existing effect and redirects its rendering to a separate buffer.

EffectTimer and Interpolations

The EffectTimer is used to control the duration and interpolation of effects. It allows for precise timing and synchronization of visual effects within your application.

Cell Selection and Area

Effects can be applied to specific cells in the terminal UI, allowing for targeted visual modifications and animations.

// only apply to cells with `Light2` foreground color
fx::sweep_in(Direction::UpToDown, 15, Dark0, timer)
    .with_cell_selection(CellFilter::FgColor(Light2.into()))

CellFilters can be combined to form complex selection criteria.

// apply effect to cells on the outer border of the area
let margin = Margin::new(1, 1);
let border_text = CellFilter::AllOf(vec![
    CellFilter::Outer(margin),
    CellFilter::Text
]);

sequence(vec![
    with_duration(duration, never_complete(fx::fade_to(Dark0, Dark0, 0))),
    fx::fade_from(Dark0, Dark0, (320, QuadOut)),
]).with_cell_selection(border_text)

Examples

Example: tweens

tweens

cargo run --release --example=tweens 

Example: basic-effects

basic effeects

cargo run --release --example=basic-effects 

Example: open-window

cargo run --release --example=open-window  

Example: fx-chart

fx-chart

A demo of the EffectTimelineWidget showcasing the composition of effects. The widget is a "plain" widget without any effects as part of its rendering. The effects are instead applied after rendering the widget.

cargo run --release --example=fx-chart

tachyonfx's People

Contributors

dependabot[bot] avatar junkdog avatar orhun avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

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.