'Cfonts causing Glitch in RGB text
So I am trying to print RGB (Color Changing) Text and it has to come after the Big Text (using cfonts).
Big_Text:
from cfonts import render
from time import sleep
from os import system
import time
def Big_Text(Text, Time):
clear = lambda: system("cls")
x = 0
y = 0
color1 = ["red", "yellow", "green", "blue", "cyan", "magenta"]
color2 = ["blue", "magenta", "red", "yellow", "green", "cyan"]
t_end = time.time() + Time
Text = Text.split()
z = 0
Txt = ""
while time.time() < t_end:
clear()
if Txt.split() != Text:
Txt = Txt + f" {Text[z]}"
else:
Txt = Txt
if x == len(color1):
x = 0
y = 0
output = render(Txt, colors=[color1[x], color2[y]], align='center')
print(output)
if z < len(Text)-1:
z += 1
else:
z += 0
x += 1
y += 1
sleep(1)
Big_Text("Hello Fellow User", 3)
RGB_Text:
from time import sleep
def RGB(txt, Cycles):
def colored(r, g, b, txt):
return f"\033[38;2;{r};{g};{b}m{txt} \033[38;2;255;255;255m"
r = 255
g = 0
b = 0
x = 0
while x != Cycles:
while g != 255:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
g += 51
while r != 0:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
r -= 51
while b != 255:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
b += 51
while g != 0:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
g -= 51
while r != 255:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
r += 51
while b != 0:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
b -= 51
x += 1
print(f"\033[38;2;{r};{g};{b}m{txt} \033[38;2;255;255;255m")
RGB("Hello World", 1)
These work exactly as I want separately, but as soon as I put them together, Big_Text works fine but the RGB_Text starts Glitching
Here's how I have done it:
from cfonts import render
from time import sleep
from os import system
import time
def Big_Text(Text, Time):
clear = lambda: system("cls")
x = 0
y = 0
color1 = ["red", "yellow", "green", "blue", "cyan", "magenta"]
color2 = ["blue", "magenta", "red", "yellow", "green", "cyan"]
t_end = time.time() + Time
Text = Text.split()
z = 0
Txt = ""
while time.time() < t_end:
clear()
if Txt.split() != Text:
Txt = Txt + f" {Text[z]}"
else:
Txt = Txt
if x == len(color1):
x = 0
y = 0
output = render(Txt, colors=[color1[x], color2[y]], align='center')
print(output)
if z < len(Text)-1:
z += 1
else:
z += 0
x += 1
y += 1
sleep(1)
Big_Text("Hello Fellow User", 3)
from time import sleep
def RGB(txt, Cycles):
def colored(r, g, b, txt):
return f"\033[38;2;{r};{g};{b}m{txt} \033[38;2;255;255;255m"
r = 255
g = 0
b = 0
x = 0
while x != Cycles:
while g != 255:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
g += 51
while r != 0:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
r -= 51
while b != 255:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
b += 51
while g != 0:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
g -= 51
while r != 255:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
r += 51
while b != 0:
print(colored(r, g, b, txt), end="\r")
sleep(0.1)
b -= 51
x += 1
print(f"\033[38;2;{r};{g};{b}m{txt} \033[38;2;255;255;255m")
RGB("Hello World", 1)
This Glitch only happens when RGB_Text is printed after Big_Text. How could I fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
