sort_routines_ani.html
001|
002| from sys import argv
003| from os import path, listdir, remove, mkdir, rmdir
004| from animation import dispatch as AniDispatch
005|
006| BasePath = r'C:\CJS\prj\Python\blog\hcc\source\sorts'
007| DataPath = path.join(BasePath, 'dat')
008| ImgsPath = path.join(BasePath, 'img')
009| AnimBase = path.join(BasePath, 'ani')
010|
011| Directories = [
012| '1a','1','1z',
013| '2a','2','2z',
014| '3a','3','3z',
015| '4a','4','4z',
016| '5a','5','5z',
017| '6a','6','6z',
018| '7a','7','7z',
019| '8a','8','8z',
020| ]
021|
022|
023| def make_directories ():
024| '''Create project directories.'''
025| for name in Directories:
026| dirname = path.join(AnimBase, name)
027|
028| if path.exists(dirname):
029| print('Directory already exists: %s' % dirname)
030| else:
031| mkdir(dirname)
032| print('Created: %s' % dirname)
033|
034|
035| def remove_directories ():
036| '''Remove project directories.'''
037| for name in Directories:
038| dirname = path.join(AnimBase, name)
039|
040| if path.exists(dirname):
041|
042| fns = listdir(dirname)
043| for fn in fns:
044| ffn = path.join(dirname, fn)
045| remove(ffn)
046| print('Files Deleted: %s' % len(fns))
047|
048| rmdir(dirname)
049| else:
050| print('Directory doesn\'t exist: %s' % dirname)
051|
052|
053| def do_file_cleanup ():
054| '''Remove animation files from project directories.'''
055|
056| def remove_files (pathname):
057| if path.exists(pathname):
058|
059|
060| fns = listdir(pathname)
061| for fn in fns:
062| print(f'Filename: {fn}')
063| remove(path.join(pathname, fn))
064| print(f'Files Deleted: {len(fns)}')
065|
066| else:
067| print(f'Directory does not exist: {dirname}')
068|
069| for dirname in Directories:
070| print(f'Directory: {dirname}')
071| remove_files(path.join(AnimBase, dirname))
072|
073|
074|
075| def build ():
076|
077|
078| cfg = {
079| 'spath':path.join(AnimBase, '1'), 'sname':'img_0000.png',
080| 'dpath':path.join(AnimBase, '1a'), 'dname':'img_%04d.png',
081| 'start':'0', 'count':'75',
082| 'codes':'/fi:10/ti:15,0/to:25,10/fo:0',
083| 'title':'Bubble Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/',
084| 'title2':'100 items/:/s:72/a:center/ha:0.5/va:0.62/pad:0,0,0,0/',
085| }
086| AniDispatch(command='ttls', **cfg)
087| cfg['sname'] = 'img_2247.png'
088| cfg['dpath'] = path.join(AnimBase, '1z')
089| AniDispatch(command='fobs', **cfg)
090|
091|
092| cfg['spath'] = path.join(AnimBase, '2')
093| cfg['sname'] = 'img_0000.png'
094| cfg['dpath'] = path.join(AnimBase, '2a')
095| cfg['title'] = 'Shaker Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/'
096| AniDispatch(command='ttls', **cfg)
097| cfg['sname'] = 'img_2247.png'
098| cfg['dpath'] = path.join(AnimBase, '2z')
099| AniDispatch(command='fobs', **cfg)
100|
101|
102| cfg['spath'] = path.join(AnimBase, '3')
103| cfg['sname'] = 'img_0000.png'
104| cfg['dpath'] = path.join(AnimBase, '3a')
105| cfg['title'] = 'Insertion Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/'
106| AniDispatch(command='ttls', **cfg)
107| cfg['sname'] = 'img_2247.png'
108| cfg['dpath'] = path.join(AnimBase, '3z')
109| AniDispatch(command='fobs', **cfg)
110|
111|
112| cfg['spath'] = path.join(AnimBase, '4')
113| cfg['sname'] = 'img_0000.png'
114| cfg['dpath'] = path.join(AnimBase, '4a')
115| cfg['title'] = 'Selection Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/'
116|
117| AniDispatch(command='ttls', **cfg)
118| cfg['sname'] = 'img_0097.png'
119| cfg['dpath'] = path.join(AnimBase, '4z')
120| AniDispatch(command='fobs', **cfg)
121|
122|
123|
124|
125| cfg['spath'] = path.join(AnimBase, '6')
126| cfg['sname'] = 'img_0000.png'
127| cfg['dpath'] = path.join(AnimBase, '6a')
128| cfg['title'] = 'Heap Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/'
129| AniDispatch(command='ttls', **cfg)
130| cfg['sname'] = 'img_0490.png'
131| cfg['dpath'] = path.join(AnimBase, '6z')
132| AniDispatch(command='fobs', **cfg)
133|
134|
135|
136|
137| cfg['spath'] = path.join(AnimBase, '8')
138| cfg['sname'] = 'img_0000.png'
139| cfg['dpath'] = path.join(AnimBase, '8a')
140| cfg['title'] = 'Shell Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/'
141| AniDispatch(command='ttls', **cfg)
142| cfg['sname'] = 'img_0361.png'
143| cfg['dpath'] = path.join(AnimBase, '8z')
144| AniDispatch(command='fobs', **cfg)
145|
146|
147|
148| config_sf = {
149| 'command':'_f',
150| 'dpath':path.join(AnimBase, '9'), 'dname':'img_%04d.png', 'start':'0',
151| 'count':'75',
152| }
153| config_ff = {
154| 'command':'ff',
155| 'spath':r'C:\CJS\prj\Python\ws\PIL\ani\_res', 'sname':'black_hd.png',
156| 'dpath':path.join(AnimBase, '0'), 'dname':'img_%04d.png', 'start':'0',
157| 'count':'75',
158| }
159| config_fibs = {
160| 'command':'fibs',
161| 'spath':path.join(AnimBase, '8'), 'sname':'img_0000.png',
162| 'dpath':path.join(AnimBase, '8a'), 'dname':'img_%04d.png', 'start':'0',
163| 'count':'75',
164| }
165| config_fobs = {
166| 'command':'fobs',
167| 'spath':path.join(AnimBase, '8'), 'sname':'img_1198.png',
168| 'dpath':path.join(AnimBase, '8z'), 'dname':'img_%04d.png', 'start':'0',
169| 'count':'75',
170| }
171| config_ttls = {
172| 'command':'ttls',
173| 'spath':path.join(AnimBase, '8'), 'sname':'img_0000.png',
174| 'dpath':path.join(AnimBase, '8a'), 'dname':'img_%04d.png', 'start':'0',
175| 'count':'1',
176| 'codes':'/fi:0/ti:5,0/to:15,10/fo:0',
177| 'title':'Shell Sort/:/s:128/a:center/ha:0.5/va:0.5/pad:20,30,150,30/',
178| 'title2':'250 items/:/s:72/a:center/ha:0.5/va:0.62/pad:0,0,0,0/',
179| }
180|
181|
182|
183| def main ():
184|
185|
186|
187|
188|
189|
190|
191|
192|
193|
194| do_file_cleanup()
195|
196|
197| if __name__ == '__main__':
198| main()
199|
200| '''eof'''
201|