def scene1(duration): position = TweenVector((0, 0)).to((200, 300), t2f(duration)) def draw(ctx, pixel_width, pixel_height, fn, frame_count): setup(ctx, pixel_width, pixel_height, width=OUTPUTWIDTH, height=OUTPUTHEIGHT, background=Color(0.5)) Circle(ctx).of_center_radius(position[fn], 30).fill(Color("red")) return make_image_frames(draw, WIDTH, HEIGHT, t2f(duration)), duration
def scene2(duration): position = TweenVector((0, 0)).to((200, 300), t2f(duration)) def draw(ctx, pixel_width, pixel_height, fn, frame_count): setup(ctx, pixel_width, pixel_height, width=OUTPUTWIDTH, height=OUTPUTHEIGHT, background=Color(0.5)) Rectangle(ctx).of_corner_size(position[fn], 50, 50).fill(Color("green")) return make_image_frames(draw, WIDTH, HEIGHT, t2f(duration)), duration
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)
width = 32 setup(ctx, pixel_width, pixel_height, width=width, startx=-width/2, starty=-width/2, background=Color(1)) a = 14 b = 6 d = 4 angle = (frame_no/frame_count)*2*math.pi*b/math.gcd(a, b) print(angle) Origin = (0, 0) A = (-a, 0) B = ((a-b)*math.cos(angle), (a-b)*math.sin(angle)) x = (a - b) * math.cos(angle) + d * math.cos((a - b) / b * angle) y = (a - b) * math.sin(angle) - d * math.sin((a - b) / b * angle) D = (x, y) Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('skyblue'), line_width=0.2) Polygon(ctx).of_points(create_spiro(a, b, d, 0.01, angle)).open().stroke(Color('red'), line_width=0.2) Circle(ctx).of_center_radius(Origin, a).stroke(Color('darkgreen'), line_width=0.2) Circle(ctx).of_center_radius(B, b).stroke(Color('blue'), line_width=0.2) Circle(ctx).of_center_radius(B, 0.3).fill(Color('blue')) Circle(ctx).of_center_radius(D, 0.3).fill(Color('black')) Line(ctx).of_start_end(B, D).stroke(Color('black'), line_width=0.2) frames = make_image_frames(draw3, 400, 400, 100) save_animated_gif("spirograph-animation.gif", frames, 0.1)
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)