Skip to content

Commit

Permalink
Fix viewport resize
Browse files Browse the repository at this point in the history
  • Loading branch information
harshkaso committed Dec 25, 2024
1 parent 9088d6a commit f1af231
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions flux/flowfield_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
2 changes: 1 addition & 1 deletion flux/flowfield_functions/fastnoisesimd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return args, noise, init_flowfield
10 changes: 5 additions & 5 deletions flux/flowfield_functions/frank_lab_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'))
Expand All @@ -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
),
Expand Down Expand Up @@ -109,4 +109,4 @@ def noise(particles, frame_count):
dx = np.cos(angles)
dy = np.sin(angles)
return dx, dy
return args, noise
return args, noise, init_flowfield
4 changes: 2 additions & 2 deletions flux/flowfield_functions/quattro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 2 additions & 3 deletions flux/flowfield_functions/swirly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion flux/flowfield_functions/vortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return args, noise, init_flowfield
3 changes: 2 additions & 1 deletion flux/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))


Expand Down

0 comments on commit f1af231

Please sign in to comment.