Initial commit
[animate-ascii.git] / animate.py
1 '''
2 (c) 2015 Cameron Ball, Ash Williams
3 All rights reserved.
4
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, and/or sell copies of the Software, and to permit persons to
10 whom the Software is furnished to do so, provided that the above
11 copyright notice(s) and this permission notice appear in all copies of
12 the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
17 THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
18 INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
19 OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20 OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 PERFORMANCE OF THIS SOFTWARE.
23 '''
24
25 import time
26
27 def pad(output, numLines):
28 for i in range(0, numLines):
29 output += "\n"
30
31 return output
32
33 def load(filename, text = ''):
34 lines = [];
35 with open(filename) as f:
36 for line in f:
37 lines.append(line.rstrip())
38
39 linesPerFrame = int(lines[0])
40 numLines = len(lines) - 1
41 offset = 1
42
43 while True:
44 output = pad('', 100)
45 for i in range(offset, linesPerFrame+offset):
46 output += lines[i]+"\n"
47
48 offset = (i+2) % numLines
49 time.sleep(1)
50 print(output + "\n" + text)
51