Ejemplo n.º 1
0
def save_nparray_image(outfile, array):
    '''
    Save an array to an image file
    :param outfile: file path including extension
    :param array: numpy array to be saved
    :return:
    '''
    array = np.clip(array, 0, 255).astype(np.uint8)
    save_frame(outfile, array)
Ejemplo n.º 2
0
def make_nparray(outfile, paint, pixel_width, pixel_height, channels=3):
    '''
    Create a PNG file 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 channels: 1 for greyscale, 3 for rgb, 4 for rgba
    :return:
    '''
    frame = make_nparray_frame(paint, pixel_width, pixel_height, channels)
    save_frame(outfile, frame)
Ejemplo n.º 3
0
 def creator(file):
     frame = make_image_frame(draw_rgba, 400, 400, channels=4)
     save_frame(file, frame)
 def creator(file):
     frame = make_nparray_frame(draw3, 600, 400, channels=3)
     save_frame(file, frame)
 def creator(file):
     out = np.full((400, 600, 3), 128, dtype=np.uint)
     out[25:100, 50:550] = [0, 0, 0]
     frame = make_nparray_frame(draw3_nofill, 600, 400, out=out)
     save_frame(file, frame)
Ejemplo n.º 6
0
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-frame",
         1,
         3,
         size=0.2,
         color=Color('cadetblue'),
         font='Arial')


frame = make_image_frame(draw, 500, 400)
save_frame(temp_file("simple-make-image-frame.png"), frame)
 def creator(file):
     frame = make_bitmap_frame(draw, 400, 400, channels=4)
     save_frame(file, frame)
from generativepy.nparray import make_nparray_frame, save_nparray, load_nparray
from generativepy.utils import temp_file
from generativepy.movie import save_frame
'''
saving and loading nparray example
'''


def paint(array, pixel_width, pixel_height, frame_no, frame_count):
    array[10:150, 60:300] = [255, 255, 0]


frame = make_nparray_frame(paint, 500, 300)
save_nparray(temp_file("saved-nparray.dat"), frame)
frame2 = load_nparray(temp_file("saved-nparray.dat"))
save_frame(temp_file("save-reload-nparray.png"), frame2)
from generativepy.bitmap import make_bitmap_frame
from generativepy.movie import save_frame
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, 300, 150), fill=Color("tomato").as_rgbstr())


frame = make_bitmap_frame(paint, 500, 300)
save_frame(temp_file("simple-make-bitmap-frame.png"), frame)
Ejemplo n.º 10
0
from generativepy.nparray import make_nparray_frame
from generativepy.movie import save_frame
from generativepy.utils import temp_file
'''
make_nparray_frame example
'''


def paint(array, pixel_width, pixel_height, frame_no, frame_count):
    array[10:150, 60:300] = [255, 128, 0]


frame = make_nparray_frame(paint, 500, 300)
save_frame(temp_file("simple-make-nparray-frame.png"), frame)