def make_nparrays(outfile, paint, pixel_width, pixel_height, count, channels=3): ''' Create a set of PNG files using numpy :param outfile: Name of output file :param paint: the paint function :param pixel_width: width in pixels, int :param pixel_height: height in pixels, int :param count: number of frames to create :param channels: 1 for greyscale, 3 for rgb, 4 for rgba :return: ''' frames = make_nparray_frames(paint, pixel_width, pixel_height, count, channels) save_frames(outfile, frames)
from generativepy.movie import save_frames from generativepy.drawing import make_image_frames from generativepy.color import Color ''' Create a simple movie of 20 frames The frames will be stored as PNG images in /tmp with names - movie00000000.pngmake_image_frames - movie00000001.png - movie00000002.png - etc ''' def draw(ctx, width, height, frame_no, frame_count): ctx.set_source_rgba(*Color(1).rgba) ctx.paint() # Draw a rectangle. # It's position changes for each frame. ctx.set_source_rgba(*Color(0.5, 0, 0).rgba) ctx.rectangle(50+20*frame_no, 50+10*frame_no, 100, 100) ctx.fill() frames = make_image_frames(draw, 500, 350, 20) save_frames("/tmp/movie", frames)
from generativepy.bitmap import make_bitmap_frames from generativepy.movie import save_frames from generativepy.color import Color from PIL import ImageDraw from generativepy.utils import temp_file ''' Create a simple bitmap image ''' def paint(image, pixel_width, pixel_height, frame_no, frame_count): draw = ImageDraw.Draw(image) draw.rectangle((60, 10 + frame_no * 30, 300, 150 + frame_no * 30), fill=Color("tomato").as_rgbstr()) frames = make_bitmap_frames(paint, 500, 300, 4) save_frames(temp_file("simple-make-bitmap-frames.png"), frames)
from generativepy.nparray import make_nparray_frames from generativepy.movie import save_frames from generativepy.utils import temp_file ''' make_nparray_frames example ''' def paint(array, pixel_width, pixel_height, frame_no, frame_count): array[10+frame_no*30:150+frame_no*30, 60:300] = [255, 128, 0] frames = make_nparray_frames(paint, 500, 300, 4) save_frames(temp_file("simple-make-nparray-frames.png"), frames)
from generativepy.color import Color from generativepy.utils import temp_file ''' Illustrates simple use of make_image_frame ''' def draw(ctx, pixel_width, pixel_height, frame_no, frame_count): setup(ctx, pixel_width, pixel_height, width=5, background=Color(0.4)) ctx.set_source_rgba(*Color(0.5, 0, 0)) ctx.rectangle(0.5, 0.5, 2.5, 1.5) ctx.fill() ctx.set_source_rgba(*Color(0, 0.75, 0, 0.5)) ctx.rectangle(2, 0.25, 2.5, 1) ctx.fill() text(ctx, "simple-make-image-frames {} {}".format(frame_no, frame_count), 1, 3, size=0.2, color=Color('cadetblue'), font='Arial') frames = make_image_frames(draw, 500, 400, 4) save_frames(temp_file("simple-make-image-frames.png"), frames)