diff --git a/flux/flowfield_functions/__init__.py b/flux/flowfield_functions/__init__.py index b9e6cc2..85d60b6 100644 --- a/flux/flowfield_functions/__init__.py +++ b/flux/flowfield_functions/__init__.py @@ -27,9 +27,10 @@ def _setup_args(args: SimpleNamespace): dpg.add_slider_float(width=sp_width/2, label=arg, parent=ff_func_settings, default_value=prop.val, max_value=prop.max_val, min_value=prop.min_val, user_data=prop, callback= lambda sender, data, property: getattr(property, 'callback')(sender, data, property) if hasattr(property, 'callback') else setattr(property, 'val', data)) def get_flowfield_function(func): - args, noise = __ff_funcs.get(func)() + args, noise, init_flowfield = __ff_funcs.get(func)() _setup_args(args) - return noise + init_flowfield() + return SimpleNamespace(noise=noise, init_flowfield=init_flowfield) def get_flowfield_function_names(): return list(__ff_funcs.keys()) diff --git a/flux/flowfield_functions/fastnoisesimd.py b/flux/flowfield_functions/fastnoisesimd.py index d8f2d2c..591f419 100644 --- a/flux/flowfield_functions/fastnoisesimd.py +++ b/flux/flowfield_functions/fastnoisesimd.py @@ -37,4 +37,4 @@ def noise(particles, frame_count): coords[2] = np.repeat(frame_count, coords[0].size) * args.time_scale.val angles = fns_noise.genFromCoords(coords) * TAU return np.cos(angles), np.sin(angles) - return args, noise \ No newline at end of file + return args, noise, init_flowfield \ No newline at end of file diff --git a/flux/flowfield_functions/frank_lab_text.py b/flux/flowfield_functions/frank_lab_text.py index 7be4067..60767d9 100644 --- a/flux/flowfield_functions/frank_lab_text.py +++ b/flux/flowfield_functions/frank_lab_text.py @@ -24,7 +24,7 @@ def get_flowfield_function_name(): def flowfield(): previous_angles = None - w, h = (cfg.ff_width, cfg.ff_height) + w,h = (cfg.ff_width, cfg.ff_height) angle_corrector = np.random.random(size=cfg.max_particles)*0.5 + 0.01 font_coords, red, green, blue, alpha = [], None, None, None, None @@ -49,8 +49,9 @@ def set_font_path(new_path): def init_flowfield(): nonlocal text, font_size, font_path, font_coords, w, h, red, green, blue, alpha, reset_particles - cfg.reset_particles = reset_particles + w,h = (cfg.ff_width, cfg.ff_height) + cfg.reset_particles = reset_particles font = ImageFont.truetype(font_path,size=font_size, encoding='utf-8') img = Image.new(mode="RGBA", size=(w,h), color=(0, 0, 0, 0)) img = radial_gradient(img, (w//2, h//2), (0, 0, 255), (255, 255, 0), font.getbbox(text, anchor='mm')) @@ -74,11 +75,10 @@ def reset_particles(reset_indices): cfg.particles[:2, reset_indices] = font_coords[choice].T cfg.particles[2, reset_indices] = np.random.randint(cfg.min_age, cfg.max_age + 1, size=np.sum(reset_indices)) - init_flowfield() args = SimpleNamespace( text = SimpleNamespace( - val = "FLUX", + val = text, callback = lambda sender, data, property: set_text(data), type = cfg.TYPE_INPUT_TEXT ), @@ -109,4 +109,4 @@ def noise(particles, frame_count): dx = np.cos(angles) dy = np.sin(angles) return dx, dy - return args, noise \ No newline at end of file + return args, noise, init_flowfield \ No newline at end of file diff --git a/flux/flowfield_functions/quattro.py b/flux/flowfield_functions/quattro.py index 5e2d579..47a855a 100644 --- a/flux/flowfield_functions/quattro.py +++ b/flux/flowfield_functions/quattro.py @@ -41,12 +41,12 @@ def init_flowfield(): ) init_flowfield() - + def noise(particles, frame_count): nonlocal args, TAU x, y = particles[:2, :]/(args.scale.val) angles = np.cos(TAU*args.m.val*x)*np.cos(TAU*args.n.val*y)*args.a.val \ - np.cos(TAU*args.n.val*x)*np.cos(TAU*args.m.val*y)*args.b.val return np.cos(angles), np.sin(angles) - return args, noise + return args, noise, init_flowfield diff --git a/flux/flowfield_functions/swirly.py b/flux/flowfield_functions/swirly.py index 89ea7ab..131186e 100644 --- a/flux/flowfield_functions/swirly.py +++ b/flux/flowfield_functions/swirly.py @@ -21,12 +21,11 @@ def init_flowfield(): max_val = 0.5 ) ) - init_flowfield() - + def noise(particles, frame_count): nonlocal args angles = (np.cos(particles[0]*args.scale.val) + np.sin(particles[1]*args.scale.val)) * args.curviness.val return np.cos(angles), np.sin(angles) - return args, noise + return args, noise, init_flowfield diff --git a/flux/flowfield_functions/vortex.py b/flux/flowfield_functions/vortex.py index 8e1a0be..d131aaa 100644 --- a/flux/flowfield_functions/vortex.py +++ b/flux/flowfield_functions/vortex.py @@ -35,4 +35,4 @@ def noise(particles, frame_count): # Normalize the resulting angle components norm = np.maximum(np.sqrt(f_sin**2 + f_cos**2), 1e-8) return f_cos/norm, f_sin/norm - return args, noise \ No newline at end of file + return args, noise, init_flowfield \ No newline at end of file diff --git a/flux/flux.py b/flux/flux.py index 79d03f6..1d51086 100644 --- a/flux/flux.py +++ b/flux/flux.py @@ -19,7 +19,7 @@ def spawn_paricles(): def recalc_particles(): - dx, dy = cfg.ff_func(cfg.particles, dpg.get_frame_count()) + dx, dy = cfg.ff_func.noise(cfg.particles, dpg.get_frame_count()) cfg.particles[0] = np.add(cfg.particles[0], np.multiply(dx, cfg.speed)) cfg.particles[1] = np.add(cfg.particles[1], np.multiply(dy, cfg.speed)) @@ -76,6 +76,7 @@ def handle_viewport_resize(sender, data): dpg.configure_item('parameters', pos=(cfg.ff_width, 0)) # Update side panel position background(cfg.bg_color) dimmer(cfg.bg_color, cfg.d_alpha) + cfg.ff_func.init_flowfield() dpg.set_frame_callback(dpg.get_frame_count()+1, callback=lambda: dpg.output_frame_buffer(callback=init_frame_buffer))