def creator(file): make_nparray(file, draw1, 600, 400, channels=1)
from generativepy.nparray import make_nparray from generativepy.utils import temp_file ''' make_nparray example ''' def paint(array, pixel_width, pixel_height, frame_no, frame_count): array[10:150, 60:300] = [255, 128, 0] make_nparray(temp_file("simple-make-nparray.png"), paint, 500, 300)
# Copyright (C) 2021, Martin McBride # License: MIT from generativepy.bitmap import Scaler from generativepy.nparray import make_nparray MAX_COUNT = 256 def calc(c1, c2): x = y = 0 for i in range(MAX_COUNT): x, y = x * x - y * y + c1, 2 * x * y + c2 if x * x + y * y > 4: return i + 1 return 0 def paint(image, pixel_width, pixel_height, frame_no, frame_count): scaler = Scaler(pixel_width, pixel_height, width=3, startx=-2, starty=-1.5) for px in range(pixel_width): for py in range(pixel_height): x, y = scaler.device_to_user(px, py) count = calc(x, y) if count == 0: image[py, px] = 0 make_nparray('mandelbrot-bw.png', paint, 600, 600, channels=1)
# Author: Martin McBride # Created: 2021-12-13 # Copyright (C) 2021, Martin McBride # License: MIT from generativepy.bitmap import Scaler from generativepy.nparray import make_nparray MAX_COUNT = 100000 A = 0.9 B = -0.6013 C = 2.0 D = 0.5 def paint(image, pixel_width, pixel_height, frame_no, frame_count): scaler = Scaler(pixel_width, pixel_height, width=3, startx=-2, starty=-2) x = 0.01 y = 0.01 for i in range(MAX_COUNT): x, y = x * x - y * y + A * x + B * y, 2 * x * y + C * x + D * y px, py = scaler.user_to_device(x, y) image[py, px] = 0 make_nparray('tinkerbell-bw.png', paint, 600, 600, channels=1)
scaler = Scaler(pixel_width, pixel_height, width=3, startx=-1.5, starty=-1.5) x = 0.01 y = 0.01 for i in range(MAX_COUNT): x, y = 1 - A * x * x + y, B * x px, py = scaler.user_to_device(x, y) if 0 <= px < pixel_width and 0 <= py < pixel_height: image[py, px] = 0 make_nparray('henon.png', paint, 600, 600, channels=1) # Zoom in on the right hand loop def paint2(image, pixel_width, pixel_height, frame_no, frame_count): scaler = Scaler(pixel_width, pixel_height, width=.5, startx=0.8, starty=-0.25) x = 0.01 y = 0.01 for i in range(MAX_COUNT): x, y = 1 - A * x * x + y, B * x px, py = scaler.user_to_device(x, y)
# Author: Martin McBride # Created: 2021-12-13 # Copyright (C) 2021, Martin McBride # License: MIT from generativepy.bitmap import Scaler from generativepy.nparray import make_nparray MAX_COUNT = 1000000 def paint(image, pixel_width, pixel_height, frame_no, frame_count): scaler = Scaler(pixel_width, pixel_height, width=12, startx=-3.5, starty=-3.5) x = -0.1 y = 0.0 for i in range(MAX_COUNT): x, y = 1 - y + abs(x), x px, py = scaler.user_to_device(x, y) image[py, px] = 0 make_nparray('gingerbread.png', paint, 600, 600, channels=1)