def generate_full_image(color_string, seed): r.init_def_generator(seed) valuesx = [ 75 + current_iteration * 3, 100 + current_iteration * 2, 150 + current_iteration ] valuesy = [250, 300, 350] gridpatternx = m.FuzzyProgression(values=valuesx, positive_shifts=1, repeat_factor=3, self_length=20) parentx = m.SProg(values=gridpatternx) gridpatterny = m.RMM(values=valuesy, self_length=20) parenty = m.SProg(values=gridpatterny) gridx = m.generate_grid_lines(parentx, WIDTH) # gridy = m.generate_grid_lines(parenty,HEIGHT) gridy = [HEIGHT // 2] # print(gridx) # print(gridy) color_repository = color.build_color_repository(color_string) final_img = r.call_and_bind(generate_image, gridx, gridy, color_repository) return final_img
def generate_patch(height, width, color_dict, direction): t = r.choice([0, 1], p=[0.9, 0.1]) # t = r.choice([0,1],p=[1,0]) if t == 0: ### markov stuff pattern = m.RMM([0, 1, 2, 3, 4], self_length=100, sinks=0, reduce_sinks=5) pattern = m.SProg(values=pattern) if direction == 1: sample = m.sample_markov_hierarchy(pattern, width) sample = np.repeat(sample, repeats=r.choice([1, 2, 3, 4], size=width)) sample = sample[:width] patch = np.tile(sample, reps=height) elif direction == -1: sample = m.sample_markov_hierarchy(pattern, height) sample = np.repeat(sample, repeats=r.choice([1, 2, 3, 4, 5], size=height)) sample = sample[:height] patch = np.repeat(sample, repeats=width) patch = patch[:width * height] patch = patch.reshape(height, width) elif t == 1: if direction == 1: patch = r.choice([0, 1, 2], size=width * height) patch = np.repeat(patch, repeats=r.choice([20, 30, 40, 50], size=width * height)) patch = patch[:height * width] patch = patch.reshape(height, width) patch = np.repeat(patch, repeats=r.choice([2, 3, 10], size=height), axis=0) patch = patch[:height, :width] elif direction == -1: patch = r.choice([0, 1, 2], size=width * height) patch = patch.reshape(height, width) patch = np.repeat(patch, repeats=r.choice([2, 3, 4], size=height), axis=0) patch = patch[:height, :width] patch = np.repeat(patch, repeats=r.choice([20, 30, 40, 50], size=width), axis=1) patch = patch[:height, :width] patch = color.replace_indices_with_colors(patch, color_dict) patch[patch < 0] = 0 patch[patch > 255] = 255 return patch
### GENERATE SECTION print('GENERATE SECTION') for current_iteration in range(N): print('CURRENT_ITERATION:', current_iteration) r.init_def_generator(SEED + current_iteration) # GENERATING THE COLORS FIRST length_choices = [1, 2] lengths_1 = r.choice(length_choices, size=5) lengths_2 = r.choice(length_choices, size=5) color_row_1 = m.Processor(m.RMM(values=[0, 1, 2, 3, 4], self_length=WIDTH, lenghts=lengths_1), length_limit=WIDTH) color_row_2 = m.Processor(m.RMM(values=[10, 11, 12, 13, 14], self_length=WIDTH, lenghts=lengths_2), length_limit=WIDTH) color_parent = m.SProg(values=[color_row_1, color_row_2], start_probs=0) colors = gen_portion(color_parent, 2, WIDTH) print(colors[:, :30]) skips = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, 0] base_pattern = config.get('pattern_base', [0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
# generating the row transitions patterns = [ m.SPat(pattern=p,candidates=skips,start_probs=[0,1],lenghts=r.choice([1,2,3,4,5]),self_length=len(p)) for p in patterns_1 for _ in range(3) ] patterns += [ m.SPat(pattern=p,candidates=skips,start_probs=[0,1],lenghts=r.choice([5,10,15]*2+[30,40,50,60]),self_length=len(p)) for p in patterns_2 for _ in range(3) ] line = m.Proc( m.RMM(values=patterns, self_length=WIDTH), length_limit=[WIDTH,WIDTH//2,WIDTH-1],num_tiles=[1,3,4,5] + [20,30,40]) multi_lines = m.Proc( m.SProg(values=line,self_length=50),length_limit=[i*WIDTH for i in range(100,150)],num_tiles=[1,2]) parent = m.SProg(values=multi_lines) img_deriv = m.paint_linearly_markov_hierarchy( markov_tree=parent, width=WIDTH, height=HEIGHT) img_acum = np.cumsum(img_deriv, axis=1) img_acum = data.upscale_nearest(img_acum,UPSCALE_FACTOR) colors_acum = data.upscale_nearest(colors_acum, ny=1, nx=UPSCALE_FACTOR) if N==1: viz.start_color_editing_tool(
def generate_patch(height, width, color_dict_1, color_dict_2): patch = np.zeros((height, width, 3), dtype='float64') color_start_lengths = np.array( [int(l) for _, (_, l) in color_dict_1.items()]) num_color_samples = width // np.min(color_start_lengths) + 20 pattern = m.FuzzyProgression(values=np.arange(len(color_dict_1)), positive_shifts=3, negative_shifts=3, self_length=num_color_samples) raw_sample = m.sample_markov_hierarchy(pattern, num_color_samples) sample_start = color.replace_indices_with_colors(raw_sample, color_dict_1) sample_end = color.replace_indices_with_colors(raw_sample, color_dict_2) switch = np.array([ r.choice([0, 1], replace=False, size=(2, )) for i in range(sample_start.shape[0]) ]) sample_start_t = np.where(switch[:, 0][:, None], sample_start, sample_end) sample_end_t = np.where(switch[:, 1][:, None], sample_start, sample_end) sample_start = sample_start_t sample_end = sample_end_t start_lengths = color_start_lengths[raw_sample.astype('int32')] start_lengths = np.cumsum(start_lengths) num_vertical_reps = 2 num_vertical_samples = height // num_vertical_reps + 3 model = m.RMM(values=np.arange(0, 41, 5) - 20, self_length=num_vertical_samples) offsets = np.stack([ m.sample_markov_hierarchy(model, num_vertical_samples) for _ in range(num_color_samples) ], axis=1) offsets = np.repeat(offsets, repeats=r.choice( [num_vertical_reps + i for i in range(1)], size=(num_vertical_samples, )), axis=0) offsets = np.cumsum(offsets, axis=0) offsets += start_lengths offsets = np.hstack([np.zeros((offsets.shape[0], 1)), offsets]) i = 0 offset_index = 0 while i < height: current_lengths = offsets[offset_index] acum_max = np.maximum.accumulate(current_lengths) mask = acum_max == current_lengths diff = np.diff(current_lengths[mask]) samples_start_masked = sample_start[mask[1:]] samples_end_masked = sample_end[mask[1:]] p_switch = 0.75 switch = r.choice([0, 1], size=samples_start_masked.shape[0], p=[p_switch, 1 - p_switch]) switch = np.stack((switch, 1 - switch), axis=1) sample_start_switched = np.where(switch[:, 0][:, None], samples_start_masked, samples_end_masked) sample_end_switched = np.where(switch[:, 1][:, None], samples_start_masked, samples_end_masked) multiples = r.choice([20, 25, 35, 50, 60, 70]) gradient = generate_gradient(sample_start_switched, sample_end_switched, diff)[:width] patch[i:i + multiples] = gradient[None, :] i += multiples offset_index += 1 patch[patch < 0] = 0 patch[patch > 255] = 255 return patch
startx = 0 starty = endy final = data.upscale_nearest(img, ny=UPSCALE_FACTOR, nx=UPSCALE_FACTOR) return final.astype('uint8') ### GENERATE SECTION print('GENERATE SECTION') for current_iteration in range(N): print('CURRENT_ITERATION:', current_iteration) r.init_def_generator(SEED + current_iteration) gridpatternx = m.RMM(values=[150, 200, 250], self_length=10) parentx = m.SProg(values=gridpatternx) gridpatterny = m.RMM(values=[200, 300, 350] * 2 + [400, 450], self_length=20) parenty = m.SProg(values=gridpatterny) gridx = m.generate_grid_lines(parentx, WIDTH) gridy = m.generate_grid_lines(parenty, HEIGHT) print(gridx) print(gridy) final_img = generate_image(gridx, gridy, [COLOR_DICT_1, COLOR_DICT_2]) file.export_image(
return final.astype('uint8') ### GENERATE SECTION print('GENERATE SECTION') for current_iteration in range(N): print('CURRENT_ITERATION:', current_iteration) r.init_def_generator(SEED + current_iteration) pattern1 = m.SProg(values=config.get('grid_jump_1', 10), self_length=[2, 3]) pattern2 = m.SProg(values=config.get('grid_jump_2', 10), self_length=[2, 3]) pattern = m.RMM(values=[pattern1, pattern2], self_length=2) randomsmall = m.RMM(values=config.get('grid_jump_3', 10), self_length=[2, 3, 4]) randombig = m.RMM(values=config.get('grid_jump_4', 10), self_length=[1, 2]) parent = m.RMM(values=[pattern, randomsmall, randombig], self_length=30) parent = m.SProg(values=parent) gridx = m.sample_markov_hierarchy_with_cumsum_limit( parent, limit=WIDTH).astype('int32') gridy = m.sample_markov_hierarchy_with_cumsum_limit( parent, limit=WIDTH).astype('int32') gridx = np.cumsum(gridx) gridy = np.cumsum(gridy) gridx = gridx[gridx < WIDTH]