#!/usr/bin/env python PATH_INKSCAPE = r'C:\APP\inkscape122\bin\inkscape.exe' DIR_OUT = r'F:\gif' WIDTH_OUT = 512 SCALE = 100 N_FRAME = 10 FORMAT_SVG = '''\ <?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-10 -290 300 300"> <circle r="999" fill="#fff"/> <g fill="none" stroke="#000"> <path id="axis" d="M -9,0 H 288 m -7,-4 l 7,4 l -7,4"/> <use xlink:href="#axis" transform="matrix(0,-1 1,0 0,0)"/> <path d="{out_d}" fill="#fc0"/> <path d="M 5,-2000 Q 0,-360 50,-200 C 70,-114 114,-70 200,-50 Q 360,0 2000,-5" fill="#fff"/> </g> </svg> ''' import re, math, subprocess def system(command, cwd='./', is_verbose=False): if is_verbose: print('%s %s' % (cwd, command)) return subprocess.Popen(command, stdout=subprocess.PIPE, cwd=cwd, shell=True).communicate()[0].decode('utf-8') def fmt(string): ## string.format(**vars()) using tags {expression!format} by CMG Lee def f(tag): i_sep = tag.rfind('!'); return (re.sub('\.0$', '', str(eval(tag[1:-1]))) if (i_sep < 0) else ('{:%s}' % tag[i_sep + 1:-1]).format(eval(tag[1:i_sep]))) return (re.sub(r'(?<!{){[^{}]+}', lambda m:f(m.group()), string) .replace('{{', '{').replace('}}', '}')) path_prefix = r'%s\%s' % (DIR_OUT, os.path.basename(os.path.splitext(__file__)[0])) for n in range(N_FRAME): a = math.exp(n / 5.0 - 1) b = math.exp(n / 5.0 - 0.8) out_d = 'M %.0f,%.0f L 0,0 L %.0f,%.0f' % (SCALE * a, -SCALE / a, SCALE * b, -SCALE / b) path_svg = '%s%02d.svg' % (path_prefix, n) path_png = '%s%02d.png' % (path_prefix, n) with open(path_svg, 'w') as f: f.write(fmt(FORMAT_SVG)) system('%s -o %s -w %d %s' % (PATH_INKSCAPE, path_png, WIDTH_OUT, path_svg), is_verbose=True) for n in range(1, N_FRAME - 1): path_svg = '%s%02d.svg' % (path_prefix, n) path_png = '%s%02d.png' % (path_prefix, N_FRAME * 2 - 2 - n) system('%s -o %s -w %d %s' % (PATH_INKSCAPE, path_png, WIDTH_OUT, path_svg), is_verbose=True) ## Then drag PNGs into http://ezgif.com/maker and then Optimize at Compression ## level: 200, Eliminate local color tables, Reduce the number of colors to 4
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4