Welcome, guest | Sign In | My Account | Store | Cart

module to anamate text using a simple hack def clear(): print "\n"*1000

Python, 71 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import time
class ascii:
    def __init__(self):
        self.clear()
    def clear():
        print "\n"*1000
    def pause(i):
        time.sleep(i)
    def roll_film(film, repi=1):
        for k in range(1, repi):
            for j in film:
                print j
                pause(1)
                clear()
            clear()
    def example():
        listf=['.  ',  ' . ', '  .']
        roll_film(listf, 4)
    def create_film(film):
        return film
class Txt_sprite:
    def __init__(self, surface, pic, ssl):
        self.screen=surface
        self.start_location=ssl
        self.image=pic
        self.screen[self.start_location]=self.image
        self.cur_loc=self.start_location
    def move(self, new_loc):
        self.screen[self.cur_loc]=' '
        self.screen[new_loc]=self.image
        self.cur_loc=new_loc
    def hide(self):
        self.screen[self.cur_loc]=' '
    def show(self):
        self.screen[self.cur_loc]=self.image
    def checkin(self, obj_loc):
        if self.cur_loc == obj_loc:
            return True
        else:
            return False
    def change_pic(self, new):
        self.image=new

def test_1():
    a=Ascii()
    screen=a.create_screen()
    sprite=Txt_sprite(screen, 'O', 0)
    x1=0
    x2=1
    hit=0
    while True:
        render(screen)
        a.pause(0.1)
        a.clear()
        if sprite.cur_loc == 19:
            hit=1
        elif sprite.cur_loc == 0:
            hit=0

        if hit == 0:
            sprite.move(x2)
        
            x1=x1+1
            x2=x2+1
        else:
            sprite.move(x1)
            x1=x1-1
            x2=x2-1
if __name__ == "__main__":
    a=ascii()
    a.example()
    

You would want to use this to animate small video games that do not need such fancy graphics.

__/^__ (^_^) /||o||\ |||o||| ()||o||() ===== || || || || == == /%||%\ <__||__>

3 comments

Andrew Wayne Teesdale Jr. (author) 10 years, 9 months ago  # | flag

module to anamate text using a simple hack def clear(): print "\n"*1000

Martin Miller 10 years, 7 months ago  # | flag

It's spelled "animation".

Andrew Wayne Teesdale Jr. (author) 10 years, 7 months ago  # | flag

ok ok