0

I am looking to do a type of text animation using python. If you have used Metasploit, during the loading a wave of text appears Example: First fIrst fiRst FirSt firsT (all of it will be on the same line) I was thinking of something using sys.stdout.write("") but I cant replace the last symbol I place down with a lowercase after it was Capitalized.

# This version is fixed and works
import sys, time
lowerstr = "buffering"
upperstr = lowerstr.upper()
for x in range(len(lowerstr)):
     s = '\r' + lowerstr[0:x] + upperstr[x] + lowerstr[x+1:] + '\r'
     sys.stdout.write(s)
     sys.stdout.flush()
     time.sleep(0.1)
RoNAPC
  • 155
  • 2
  • 9
  • This seems to be around what you are looking for http://stackoverflow.com/questions/2122385/dynamic-terminal-printing-with-python – nerdlyist Jan 23 '17 at 21:06
  • I modded it the script below and added "\r" to the begging and fixed it so it could do what I wanted, thank you guys for the help! s = '\r' + lowerstr[0:x] + upperstr[x] + lowerstr[x+1:] + '\r' – RoNAPC Jan 24 '17 at 00:32
  • newer change question! append modifications at the end. Now nobody will know what was oryginal code and oryginal problem in code. – furas Jan 24 '17 at 06:45
  • The original script wasn't close at all to the functionality of the proper script. It was more or less a far concept. But I understand your concern. :D *original* And I won't delete scripts if they had an error. – RoNAPC Jan 24 '17 at 13:54
  • If an answer helped you, mark it as accepted. I'm sure the answer author would appreciate it. :) – FamousJameous Jan 26 '17 at 17:38

4 Answers4

1
import sys
import time

data = ["b","u","f","f","e","r","i","n","g"]

# display with one upper char

for x in range(len(data)):
    # remeber lower char
    old = data[x]

    # replace with upper char
    data[x] = old.upper()

    # create full text
    text = "".join(data)

    # display full text
    sys.stdout.write("\r")
    sys.stdout.write(text)
    sys.stdout.flush()

    # put back lower char
    data[x] = old

    time.sleep(1)

# display without upper chars at the end 

text = "".join(data)

sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()

If you put extra char at then end in data which doesn't have upper version - ie. empty string "" - then you don't need code after for loop.

You can put also empty string at start to display first text without upper chars.

import sys
import time

# text with extra chars at the start and at the end
data = ["", "b","u","f","f","e","r","i","n","g", ""]

# display with one upper char

for x in range(len(data)):
    # remeber lower char
    old = data[x]

    # replace with upper char
    data[x] = old.upper()

    # create full text
    text = "".join(data)

    # display full text
    sys.stdout.write("\r")
    sys.stdout.write(text)
    sys.stdout.flush()

    # put back lower char
    data[x] = old

    time.sleep(1)
furas
  • 134,197
  • 12
  • 106
  • 148
0

This version combines the strings rather than just iterating over each character. You could do away with upperstr altogether by using .upper() on the appropriate character. Note that you should not use list as a variable name since it is a Python builtin.

import sys
import time

lowerstr = "buffering"
upperstr = lowerstr.upper()
for x in range (len(lowerstr)):
    s = lowerstr[0:x] + upperstr[x] + lowerstr[x+1:] + '\r'
    sys.stdout.write(s)
    sys.stdout.flush()
    time.sleep(1)
FamousJameous
  • 1,565
  • 11
  • 25
0

Implementing this animation using ios pythonista scene

import scene

label_text = 'abcdefghijklmnopqrstuvwxyz'

def custom_action(node, progress):
    ntext = node.text
    i = int(len(ntext)*progress)
    iminus1txt = ntext[i-1].lower() if i > 0 else ''
    ithtxt = ntext[i].capitalize() if i < len(ntext) else ''
    if i > 0:
        before_i = ntext[:(i-1)]
    else:
        before_i = ''
    if i < len(ntext):
        node.text = before_i+iminus1txt+ithtxt+ntext[(i+1):]
    else:
        node.text = label_text

class TextCapitalAnimate(scene.Scene):
    def setup(self):
        center = self.bounds.center()
        labelnode = scene.LabelNode(label_text, font=('Courier', 20),
                                position=center, parent=self)
        A = scene.Action
        animate_action = A.repeat(A.call(custom_action, 2), 0)
        labelnode.run_action(animate_action)

scene.run(TextCapitalAnimate())
abcabc
  • 61
  • 3
0
import time
import sys

string = input(str('Enter text : '))
list = []
for x in string:
 list.append(x)

while True:
 for x in range(len(list)):
  old = list[x]
  list[x] = old.upper()
  final = "".join(list)
  sys.stdout.write('\r')
  sys.stdout.write(final)
  sys.stdout.flush()
  list[x] = old
  time.sleep(0.1)
Lemon
  • 11
  • 2