
# # vary_ab.py - Written by Ted Burke, last updated 18-1-2016 # import subprocess import math centre = 0 + 0j # complex value at centre of image w,h = 400,400 # image width and height pxw = 0.02 # pixel width limit = 4.0 # once z reaches this value, iteration ceases amin,amax = 2.0,4.0 bmin,bmax = 2.0,4.0 # Create a buffer to store a row of pixel values row = w*[0] # Generate images for frame in range(100): # Open file filename = 'frame{:03d}'.format(frame) pgmfile = file(filename + '.pgm', 'w') pgmfile.write('P5\n{} {}\n255\n'.format(w,h)) for y in range(h): for x in range(w): a = ((amin+amax)/2.0) + ((amax-amin)/2)*math.cos(2*math.pi * (float(x)/w + frame/100.0)) b = ((bmin+bmax)/2.0) + ((bmax-bmin)/2)*math.sin(2*math.pi * (float(y)/h + frame/100.0)) c = centre + complex(((x-(w-1)/2.0)*pxw),(((h-1)/2.0-y)*pxw)) z = 0 n = 0 while abs(z) < limit and n < 51: try: z = (pow(z,a) + c)/(pow(z,b) - c) n = n + 1 except ZeroDivisionError: z = limit row[x] = int(255 * (0.5 + 0.5*math.cos(math.pi*n/51.0))) pgmfile.write(bytearray(row)) # Close file pgmfile.close() subprocess.call('mogrify -format png ' + filename + '.pgm', shell=True) subprocess.call('rm ' + filename + '.pgm', shell=True) print(filename + '.png written')
# # renamer.py - Written by Ted Burke, last updated 18-1-2016 # import subprocess # Create fractal image files for n in range(100): filename = 'frame{:03d}'.format(n) print(filename) subprocess.call('convert ' + filename + '.png -resize 50% ' + 'half_' + filename + '.png', shell=True)
To create an mp4 video using ffmpeg:
ffmpeg -framerate 10 -i half_frame%03d.png -c:v libx264 -pix_fmt yuv420p output.mp4
To create a looping gif using ImageMagick’s convert tool:
convert -loop 0 half_frame*.png output.gif