def draw(self, image, context, palette): colors = palette.generate(exactly=2) steps = random.randint(10, 50) smallest_dim = min(image.width(), image.height()) step = smallest_dim / steps vertices = [ imgen.Point(0.2, 0) * step, imgen.Point(0.8, 0) * step, imgen.Point(1.0, 0.5) * step, imgen.Point(0.8, 1.0) * step, imgen.Point(0.2, 1.0) * step, imgen.Point(0.0, 0.5) * step ] comb = imgen.Path(2) top_color = colors.pop(random.randint(0, len(colors) - 1)) bottom_color = colors.pop(random.randint(0, len(colors) - 1)) for i, vertex in enumerate(vertices): if i == 0: comb.move_to(vertex) else: comb.line_to(vertex) start = -0.5 * step x_step = 0.8 * step column = 0 pos = imgen.Point(start, start) bottom_edge = ( imgen.Point(0, image.height()), imgen.Point(image.width(), image.height()) ) context.clear() context.translate(start, start) while pos.x <= (image.width() + step): pos.x += x_step pos.y = start column += 1 if column % 2 == 0: context.translate(0, 0.5 * step) pos.y += 0.5 * step while pos.y <= (image.height() + step): distance = imgen.distance(pos, bottom_edge) t = (distance / image.height()) + random.uniform(0, 1) color = imgen.blend(bottom_color, top_color, t) context.set_color(0, 0, 0) comb.stroke(context) context.set_color(color) comb.fill(context) context.translate(0, step) pos.y += step context.translate(x_step, -(pos.y + abs(start)))
def draw(self, image, context, palette): colors = palette.generate(exactly=2) steps = random.randint(10, 50) smallest_dim = min(image.width(), image.height()) step = smallest_dim / steps vertices = [ imgen.Point(0.2, 0) * step, imgen.Point(0.8, 0) * step, imgen.Point(1.0, 0.5) * step, imgen.Point(0.8, 1.0) * step, imgen.Point(0.2, 1.0) * step, imgen.Point(0.0, 0.5) * step ] comb = imgen.Path(2) top_color = colors.pop(random.randint(0, len(colors) - 1)) bottom_color = colors.pop(random.randint(0, len(colors) - 1)) for i, vertex in enumerate(vertices): if i == 0: comb.move_to(vertex) else: comb.line_to(vertex) start = -0.5 * step x_step = 0.8 * step column = 0 pos = imgen.Point(start, start) bottom_edge = (imgen.Point(0, image.height()), imgen.Point(image.width(), image.height())) context.clear() context.translate(start, start) while pos.x <= (image.width() + step): pos.x += x_step pos.y = start column += 1 if column % 2 == 0: context.translate(0, 0.5 * step) pos.y += 0.5 * step while pos.y <= (image.height() + step): distance = imgen.distance(pos, bottom_edge) t = (distance / image.height()) + random.uniform(0, 1) color = imgen.blend(bottom_color, top_color, t) context.set_color(0, 0, 0) comb.stroke(context) context.set_color(color) comb.fill(context) context.translate(0, step) pos.y += step context.translate(x_step, -(pos.y + abs(start)))
def draw(self, image, context, palette): colors = palette.generate(at_least=2, at_most=5) steps = random.randint(10, 50) smallest_dim = min(image.width(), image.height()) step = smallest_dim / steps grid = [] y = random.uniform(-0.5, 0) * step start_x = random.uniform(-0.5, 0) * step while y <= (image.height() + step): x = start_x row = [] while x <= (image.width() + step): row.append(imgen.Point(x, y)) x += step grid.append(row) y += step context.clear() breakpoints = len(colors) origin = imgen.Point( random.uniform(0, image.width()), random.uniform(0, image.height()) ) for r, row in enumerate(grid[:-1]): next_row = grid[r + 1] for p, point in enumerate(row[:-1]): corners = [ point, row[p + 1], next_row[p], next_row[p + 1] ] for triangle in (corners[0:3], corners[1:4]): path = imgen.Path() distance = (triangle[0] - origin).length() / smallest_dim t = random.uniform(0.0, 1.0) * distance index = math.floor(distance / breakpoints) color = imgen.blend(colors[index], colors[index + 1], t) context.set_color(color) path.move_to(triangle[0]) path.line_to(triangle[1]) path.line_to(triangle[2]) path.fill(context) path.stroke(context)
def draw(self, image, context, palette): colors = palette.generate(at_least=2, at_most=5) steps = random.randint(10, 50) smallest_dim = min(image.width(), image.height()) step = smallest_dim / steps grid = [] y = random.uniform(-0.5, 0) * step start_x = random.uniform(-0.5, 0) * step while y <= (image.height() + step): x = start_x row = [] while x <= (image.width() + step): row.append(imgen.Point(x, y)) x += step grid.append(row) y += step context.clear() breakpoints = len(colors) origin = imgen.Point(random.uniform(0, image.width()), random.uniform(0, image.height())) for r, row in enumerate(grid[:-1]): next_row = grid[r + 1] for p, point in enumerate(row[:-1]): corners = [point, row[p + 1], next_row[p], next_row[p + 1]] for triangle in (corners[0:3], corners[1:4]): path = imgen.Path() distance = (triangle[0] - origin).length() / smallest_dim t = random.uniform(0.0, 1.0) * distance index = math.floor(distance / breakpoints) color = imgen.blend(colors[index], colors[index + 1], t) context.set_color(color) path.move_to(triangle[0]) path.line_to(triangle[1]) path.line_to(triangle[2]) path.fill(context) path.stroke(context)