ChrisBuilds / terminaltexteffects

TerminalTextEffects (TTE) is a terminal visual effects engine, application, and Python library.
https://chrisbuilds.github.io/terminaltexteffects/
MIT License
2.82k stars 49 forks source link

Feature Request: Loop effects for existing text #9

Closed v4u6h4n closed 4 months ago

v4u6h4n commented 4 months ago

Hello again :-)

I would love to see some basic effects that could be used in loops on text that has already been printed with one of the existing effects.

For example, after using the Beams effect to print some text, a basic effect that loops a gradient colour could be applied, using attributes similar to existing ones, like final_gradient_stop and final_gradient_direction; and perhaps a gradient_loops, or similar, attribute to define the number of loops.

There is a feature similar in rgbprint, which I'm using in combination with terminaltexteffects now, but the tte engine is so powerful would be cool to use that instead.

ChrisBuilds commented 4 months ago

Can you provide an example using the rgbprint library?

v4u6h4n commented 4 months ago

Yeah sure. I'm using this:

while True:
    print("\033c", end="")
    sys.stdout.write("\x1b[?25l")
    sys.stdout.flush()
      gradient_scroll(
          "text", 
          start_color=0x4BBEE3, 
          end_color=Color.medium_violet_red,
          delay=0.05,
          times=1
      )

The actual rgbprint code is:

gradient_scroll(
    "text", 
    start_color=0x4BBEE3, 
    end_color=Color.medium_violet_red,
    delay=0.05,
    times=1
)

The times specifies the number of times to run the colour gradient scroll, which unfortunately does not accept 0 as infinite, so I'm just using a loop to get the same effect. There is a variant that just graduates the colour of the whole text, instead of the graduating the colour change in a wave/scroll across the text, but the code is pretty much the same.

The only feature that is absent from both rgbprint and tte that would be cool, would be allowing more gradient stops, so you could do a spectral/rainbow gradient animation, but maybe you can achieve that with only three colours, I just wasn't able to when I was playing around with it in tte.

ChrisBuilds commented 4 months ago

So you don't intend to do other work while this is printing? You'll be stuck in the while loop. If that's the case, a simple effect which displays a gradient, with an option to travel the gradient wave, would be easy to make. I like the idea. Look for that effect in the next update.

As a note, TTE gradients support an arbitrary number of stops/steps. However, there are currently no effects which produce a simple gradient shift appearance and almost all effects support a directional gradient for the final result which limits which part of the spectrum is actually displayed for a given character.

I'll build an effect which cycles over a gradient with an option to shift the gradient across the text. I can experiment with an option to run indefinitely when used as a library, but I'll likely not make that option available from the command line. I'll update this issue when there's been progress. Thanks for the feedback and ideas.

v4u6h4n commented 4 months ago

So you don't intend to do other work while this is printing?

Yeah exactly :-) My project is pretty niche, and still very much a work in progress; I've integrated it into the twitch bot I'm using for my channel, to print events, like announcements, subscriptions, etc. Later, once that's done, eventually I'd love to write a terminal chat client, like twitch-tui, that uses tte.

I like the idea. Look for that effect in the next update.

Awesome, happy to hear! Can't wait to play with it.

ChrisBuilds commented 4 months ago

0.10.0 has been released and includes a new effect called ColorShift which can be used to accomplish your goal. Check out the ChangeBlog for the release and give it a try. Drop an update in here and if there's nothing else, I'll close the issue. Thanks.

Here's an example using the ColorShift effect with a single line input, radial travel direction, and infinite looping.

from terminaltexteffects.effects.effect_colorshift import ColorShift
from terminaltexteffects.utils.graphics import Gradient

text = "EXAMPLE" * 10

effect = ColorShift(text)
effect.effect_config.travel = True
effect.effect_config.travel_direction = Gradient.Direction.RADIAL
effect.effect_config.loop_gradient = True
effect.effect_config.cycles = 0
effect.terminal_config.canvas_height = 1
with effect.terminal_output() as terminal:
    for frame in effect:
        terminal.print(frame)

Result one_line_colorshift_demo

Adjust the effect.effect_config.gradient_frames to speed up/slow down the gradient travel speed.

v4u6h4n commented 4 months ago

Hey @ChrisBuilds

I actually checked in a few times leading up to 10.0 and noticed you were quite busy! I was wrapping up a lot my own project, so took a little bit to finally have a play with it, but after little configuring I got a very soothing effect, looks sooo good; just what I was imaging when I made the feature request, so thankyou :-)

Also cookbook looks great, will have to play with that kinda stuff more before long!

ChrisBuilds commented 4 months ago

Glad to hear it. The idea of infinitely looping effects is cool. I'll need to consider which existing effects could be modified and what new effects could be made explicitly to support use cases such as yours. Thanks for the issue. I'm going to move this into a discussion.