Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

echo-rainbow.bat - rainbow-ize any message

Jul
278
7
Rainbow-echo (echo-rainbow.bat). Included in attachments is echo-rainbow.bat, as well as set-colors.bat which is optional and used in a non-required way.

1689541590628-png.4105


1689541613073.png


Code:
@echo off

rem *** Are we running in test mode?
        if "%*"=="test" (
            gosub :generateTestString
        ) else (
            set inputStr=%*
        )

rem *** Get length of string, and use it to calculate the step size between hues
        set strLength=%@len[%inputStr%]
        set MAX_HUE=1530
        set colorStep=%@EVAL[%MAX_HUE/%strLength]
        REM @echo strlength is '%strLength'%wide%

rem Iterate over each character and interpolate color
        for /l %N in (0,1,%strLength%) gosub printCharWithColor %n%


goto :eof


    :printCharWithColor [%n]
        set charPosition=%%N

        set hue=%@FLOOR[%@EVAL[(%charposition/%strLength)*%MAX_HUE]]
        REM echo hue is %hue

        set /a redComponent=0
        set /a greenComponent=0
        set /a blueComponent=0

        if %hue% lss 256 (
            set /a redComponent=255
            set /a greenComponent=%hue%
        ) else (
            if %hue% lss 512 (
                set /a redComponent=511-%hue%
                set /a greenComponent=255
            ) else (
                if %hue% lss 768 (
                    set /a greenComponent=255
                    set /a blueComponent=%hue%-512
                ) else (
                    if %hue% lss 1024 (
                        set /a greenComponent=1023-%hue%
                        set /a blueComponent=255
                    ) else (
                        if %hue% lss 1280 (
                            set /a redComponent=%hue%-1024
                            set /a blueComponent=255
                        ) else (
                            set /a redComponent=255
                            set /a blueComponent=1535-%hue%
                        )
                    )
                )
            )
        )

        :next_1
        set singleChar=%@INSTR[%charPosition%,1,%inputStr%]``
        if "%singleChar%" eq "" (set singleChar= ``)
        REM echo singlechar is '%singleChar'

        set   redComponent=%@FLOOR[%redComponent]
        set greenComponent=%@FLOOR[%greenComponent]
        set  blueComponent=%@FLOOR[%blueComponent]

        rem echo %singleChar% @ANSI_FG_RGB[%redComponent%,%greenComponent%,%blueComponent%]%singleChar%``
        rem echo %blink%%singleChar%%blink_off%  hue=%hue% ... %@ANSI_FG_RGB[%redComponent%,%greenComponent%,%blueComponent%]%singleChar%``
        echos %@ANSI_FG_RGB[%redComponent%,%greenComponent%,%blueComponent%]%singleChar%``

    return


    :generateTestString
        rem Generate a test string of length 1024
        rem The string consists of four-digit repetitions from 0000 to 1023
        set inputStr=
        for /l %%N in (0,1,1023) do (
            set /a number=%%N
            if %number% lss 10   (set number=000%number%)
            if %number% lss 100  (set number=00%number%)
            if %number% lss 1000 (set number=0%number%)
            set inputStr=%inputStr%%number%
        )
    return


:eof

rem Optional: Reset ansi back (this env var is defined in set-colors.bat)
        echos %ANSI_RESET%``
 

Attachments

There is no "s" in your shortest sentence with all letters.
It should be "The quick brown fox jumps over a lazy dog."
 
A set-color.bat test gives me:
output strings ..

set-colors.bat [291] Unknown command "bigecho"

Well shoot, I forgot to include that bat file! Here it is.

I also attached some other BAT files that are probably used.

i can definitely give advice to get it to work. My stuff is heavily refactored so sometime it's hard to excise out a fully functional piece without way too many files :)

Code:
@echo off

:USAGE: optionally set COLOR_TO_USE=<command to set the color to use> prior to calling for cosmetically better background color handlin
g to avoid the cosmetic weirdness of newlines with a different background color


call validate-environment-variables BIG_TEXT_LINE_1 BIG_TEXT_LINE_2

set PARAMS=%@UNQUOTE[%*]

%COLOR_TO_USE% %+ echos %BIG_TEXT_LINE_1%%PARAMS%%BIG_TEXT_END% %+ %COLOR_NORMAL% %+ echo.
%COLOR_TO_USE% %+ echos %BIG_TEXT_LINE_2%%PARAMS%%BIG_TEXT_END% %+ %COLOR_NORMAL% %+ if %ECHOSBIG ne 1 (echo.)

echos %BIG_TEXT_END%%ANSI_RESET%

REM option should only affect it once
if defined COLOR_TO_USE (set COLOR_TO_USE=)
 

Attachments

Ahhh this is why I wrote a dependency lister for my bat files, but the complexity of it caused me to abandon it before it fully worked. I need to stop using car/nocar (which are just pointers to fuller-named files) because i made those in the 1990s when i didn't know about setdos and they're embarassing.

As long as "^" isn't your command separator (and it shouldn't be, i'm probably the only one on the planet), you should be able to just completely comment out all car/nocar ones. In fact, I'd explicitly say you don't want to run those and they could break your stuff that you run afterward.

And I'm gonna maybe.... Try to work them out of my scripts more. This is embarrassing, but this is exactly why I started posting things here. I want to learn how to make my efforts useful for others, and I have to go through this process to learn how lololol :)
 
What would be neat would be if someone had a BAT file packaging tool that would automatically convert a BAT file that calls other batfiles (i.e. heavily refactored code) into a single bat file for portability purposes.
 
My apologies, I'll have to test mine before posting them in the future!
 
Back
Top
[FOX] Ultimate Translator
Translate