Skip to content

Commit 333e5a2

Browse files
committed
Move to settings dropdown instead of category buttons, add Buffalo Fractal, fix settings issue
1 parent 81e60e5 commit 333e5a2

File tree

6 files changed

+65
-20
lines changed

6 files changed

+65
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Fractal viewer in Python using compute shaders and the Arcade and Pyglet modules.
22

3-
Currently supports Julia, multi-Julia, Mandelbrot, Multibrot, Mandelbar, multi-Mandelbar, Phoenix Fractal, Lambda Fractal, Burning Ship, Newton Fractal and the Sierpinsky Carpet.
3+
Currently supports Julia, multi-Julia, Mandelbrot, Multibrot, Mandelbar, multi-Mandelbar, Buffalo Fractal, Phoenix Fractal, Lambda Fractal, Burning Ship, Newton Fractal and the Sierpinsky Carpet.

game/iter_fractal_viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def on_show_view(self):
3535
int(self.settings_dict.get(f"{self.fractal_name}_escape_radius", 2)),
3636
self.settings_dict.get("julia_type", "Classic swirling")
3737
)
38-
38+
3939
self.fractal_sprite = pyglet.sprite.Sprite(img=self.fractal_image)
4040

4141
self.create_image()

game/shader.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,39 @@
206206
}}
207207
"""
208208

209+
buffalo_fractal_calc = """int calculate_iters({vec2type} c) {{
210+
int iters = 0;
211+
{vec2type} z = {vec2type}(0.0, 0.0);
212+
{floattype} R = {escape_radius};
213+
while (dot(z, z) < R * R && iters < u_maxIter) {{
214+
{floattype} z_squared_real = z.x * z.x - z.y * z.y;
215+
{floattype} z_squared_imag = 2.0 * z.x * z.y;
216+
z = {vec2type}(abs(z_squared_real) + c.x, abs(z_squared_imag) + c.y);
217+
iters++;
218+
}}
219+
return iters;
220+
}}
221+
"""
222+
223+
multi_buffalo_fractal_calc = """int calculate_iters(vec2 c) {{
224+
int iters = 0;
225+
vec2 z = vec2(0.0);
226+
float n = {multi_n};
227+
float R = {escape_radius};
228+
while (dot(z, z) < R * R && iters < u_maxIter) {{
229+
float r = length(z);
230+
float theta = atan(z.y, z.x);
231+
float r_n = pow(r, n);
232+
float theta_n = n * theta;
233+
float zn_real = r_n * cos(theta_n);
234+
float zn_imag = r_n * sin(theta_n);
235+
z = vec2(abs(zn_real) + c.x, abs(zn_imag) + c.y);
236+
iters++;
237+
}}
238+
return iters;
239+
}}
240+
"""
241+
209242
burning_ship_calc = """int calculate_iters({vec2type} c) {{
210243
int iters = 0;
211244
{vec2type} z = {vec2type}(0.0, 0.0);
@@ -375,6 +408,13 @@ def create_iter_calc_shader(fractal_type, width, height, precision="single", mul
375408
else:
376409
replacements["iter_calc_func"] = multi_julia_calc.format_map(replacements)
377410

411+
elif fractal_type == "buffalo_fractal":
412+
replacements["coloring_func"] = fire_coloring.format_map(replacements)
413+
if int(multi_n) == 2:
414+
replacements["iter_calc_func"] = buffalo_fractal_calc.format_map(replacements)
415+
else:
416+
replacements["iter_calc_func"] = multi_buffalo_fractal_calc.format_map(replacements)
417+
378418
elif fractal_type == "burning_ship":
379419
replacements["coloring_func"] = fire_coloring.format_map(replacements)
380420
replacements["iter_calc_func"] = burning_ship_calc.format_map(replacements)

menus/fractal_chooser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, pypresence_client):
1616

1717
self.grid = self.add_widget(arcade.gui.UIGridLayout(row_count=4, column_count=3, horizontal_spacing=10, vertical_spacing=10))
1818
self.anchor.add(self.grid, anchor_x="center", anchor_y="center")
19-
19+
2020
def on_show_view(self):
2121
super().on_show_view()
2222

menus/settings.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,16 @@ def on_show_view(self):
5656
self.display_category(settings_start_category)
5757

5858
def display_categories(self):
59-
for category in settings:
60-
category_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=category, style=button_style, width=self.window.width / 13, height=50)
61-
62-
if not category == "Credits":
63-
category_button.on_click = lambda e, category=category: self.display_category(category)
64-
else:
65-
category_button.on_click = lambda e: self.credits()
66-
67-
self.top_box.add(category_button)
59+
self.settings_dropdown = self.anchor.add(arcade.gui.UIDropdown(options=list(settings.keys()), default=settings_start_category, primary_style=dropdown_style, active_style=dropdown_style, dropdown_style=dropdown_style, width=self.window.width / 1.5, height=self.window.height / 20), anchor_x="center", anchor_y="top", align_y=-10)
60+
self.settings_dropdown.on_change = lambda event: self.display_category(event.new_value)
6861

6962
self.anchor.detect_focusable_widgets()
7063

7164
def display_category(self, category):
65+
if category == "Credits":
66+
self.credits()
67+
return
68+
7269
if hasattr(self, 'apply_button'):
7370
self.anchor.remove(self.apply_button)
7471
del self.apply_button
@@ -94,7 +91,7 @@ def display_category(self, category):
9491
self.value_layout.add(dropdown)
9592

9693
elif setting_dict['type'] == "bool":
97-
button_layout = self.value_layout.add(arcade.gui.arcade.gui.UIBoxLayout(space_between=50, vertical=False))
94+
button_layout = self.value_layout.add(arcade.gui.UIBoxLayout(space_between=50, vertical=False))
9895

9996
on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50)
10097
self.on_radiobuttons[setting] = on_radiobutton

utils/constants.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"mandelbar": (-2.0, 1.0, -1.0, 1.0),
1313
"phoenix_fractal": (-2.0, 1.0, -1.0, 1.0),
1414
"lambda_fractal": (-2.0, 1.0, -1.0, 1.0),
15+
"buffalo_fractal": (-2.0, 1.5, -2.0, 1.0),
1516
"burning_ship": (-2.0, 1.5, -2.0, 1.0),
1617
"newton_fractal": (-2.0, 2.0, -2.0, 2.0)
1718
}
@@ -23,7 +24,7 @@
2324
"Snowflake": (-0.8, 0.156)
2425
}
2526

26-
iter_fractals = ["mandelbrot", "mandelbar", "phoenix_fractal", "lambda_fractal", "julia", "burning_ship", "newton_fractal"]
27+
iter_fractals = ["mandelbrot", "mandelbar", "phoenix_fractal", "lambda_fractal", "julia", "burning_ship", "buffalo_fractal", "newton_fractal"]
2728

2829
button_style = {'normal': UITextureButtonStyle(font_name="Roboto", font_color=arcade.color.BLACK), 'hover': UITextureButtonStyle(font_name="Roboto", font_color=arcade.color.BLACK),
2930
'press': UITextureButtonStyle(font_name="Roboto", font_color=arcade.color.BLACK), 'disabled': UITextureButtonStyle(font_name="Roboto", font_color=arcade.color.BLACK)}
@@ -53,6 +54,19 @@
5354
"Zoom Increase Per Click": {"type": "slider", "min": 2, "max": 100, "config_key": "mandelbar_zoom_increase", "default": 2},
5455
"Max Iterations": {"type": "slider", "min": 100, "max": 10000, "config_key": "mandelbar_max_iter", "default": 200, "step": 100}
5556
},
57+
"Burning Ship": {
58+
"Float Precision": {"type": "option", "options": ["Single", "Double"], "config_key": "burning_ship_precision", "default": "Single"},
59+
"Escape Radius": {"type": "slider", "min": 1, "max": 10, "config_key": "burning_ship_escape_radius", "default": 2, "step": 0.1},
60+
"Zoom Increase Per Click": {"type": "slider", "min": 2, "max": 100, "config_key": "burning_ship_zoom_increase", "default": 2},
61+
"Max Iterations": {"type": "slider", "min": 100, "max": 10000, "config_key": "burning_ship_max_iter", "default": 200, "step": 100}
62+
},
63+
"Buffalo Fractal": {
64+
"Float Precision": {"type": "option", "options": ["Single", "Double"], "config_key": "buffalo_fractal_precision", "default": "Single"},
65+
"N": {"type": "slider", "min": 1, "max": 10, "config_key": "buffalo_fractal_n", "default": 2, "step": 1},
66+
"Escape Radius": {"type": "slider", "min": 1, "max": 10, "config_key": "buffalo_fractal_escape_radius", "default": 2, "step": 0.1},
67+
"Zoom Increase Per Click": {"type": "slider", "min": 2, "max": 100, "config_key": "buffalo_fractal_zoom_increase", "default": 2},
68+
"Max Iterations": {"type": "slider", "min": 100, "max": 10000, "config_key": "buffalo_fractal_max_iter", "default": 200, "step": 100}
69+
},
5670
"Phoenix Fractal": {
5771
"Float Precision": {"type": "option", "options": ["Single", "Double"], "config_key": "phoenix_fractal_precision", "default": "Single"},
5872
"Escape Radius": {"type": "slider", "min": 1, "max": 10, "config_key": "phoenix_fractal_escape_radius", "default": 2, "step": 0.1},
@@ -65,12 +79,6 @@
6579
"Zoom Increase Per Click": {"type": "slider", "min": 2, "max": 100, "config_key": "phoenix_fractal_zoom_increase", "default": 2},
6680
"Max Iterations": {"type": "slider", "min": 100, "max": 10000, "config_key": "phoenix_fractal_max_iter", "default": 200, "step": 100}
6781
},
68-
"Burning Ship": {
69-
"Float Precision": {"type": "option", "options": ["Single", "Double"], "config_key": "burning_ship_precision", "default": "Single"},
70-
"Escape Radius": {"type": "slider", "min": 1, "max": 10, "config_key": "burning_ship_escape_radius", "default": 2, "step": 0.1},
71-
"Zoom Increase Per Click": {"type": "slider", "min": 2, "max": 100, "config_key": "burning_ship_zoom_increase", "default": 2},
72-
"Max Iterations": {"type": "slider", "min": 100, "max": 10000, "config_key": "burning_ship_max_iter", "default": 200, "step": 100}
73-
},
7482
"Sierpinsky Carpet": {
7583
"Float Precision": {"type": "option", "options": ["Single", "Double"], "config_key": "sierpinsky_precision", "default": "Single"},
7684
"Zoom Increase Per Click": {"type": "slider", "min": 2, "max": 100, "config_key": "sierpinsky_zoom_increase", "default": 2},

0 commit comments

Comments
 (0)