mirror of
https://github.com/csd4ni3l/fractal-viewer.git
synced 2026-01-01 04:13:41 +01:00
Use Roboto instead of Protest Strike, add Mandelbar, Multi Mandelbar, Phoenix and Lambda Fractal
This commit is contained in:
@@ -48,8 +48,8 @@ class IterFractalViewer(arcade.gui.UIView):
|
||||
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
||||
|
||||
self.info_box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10, vertical=False), anchor_x="center", anchor_y="top")
|
||||
self.zoom_label = self.info_box.add(arcade.gui.UILabel(text=f"Zoom: {self.zoom}", font_name="Protest Strike", font_size=16))
|
||||
self.max_iter_label = self.info_box.add(arcade.gui.UILabel(text=f"Max Iterations: {self.max_iter}", font_name="Protest Strike", font_size=16))
|
||||
self.zoom_label = self.info_box.add(arcade.gui.UILabel(text=f"Zoom: {self.zoom}", font_name="Roboto", font_size=16))
|
||||
self.max_iter_label = self.info_box.add(arcade.gui.UILabel(text=f"Max Iterations: {self.max_iter}", font_name="Roboto", font_size=16))
|
||||
|
||||
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
|
||||
self.back_button.on_click = lambda event: self.main_exit()
|
||||
|
||||
100
game/shader.py
100
game/shader.py
@@ -166,6 +166,46 @@ multibrot_calc = """int calculate_iters(vec2 c) {{
|
||||
}}
|
||||
"""
|
||||
|
||||
mandelbar_calc = """int calculate_iters({vec2type} c) {{
|
||||
int iters = 0;
|
||||
{vec2type} z = {vec2type}(0.0, 0.0);
|
||||
float R = {escape_radius};
|
||||
|
||||
while (dot(z, z) < R * R && iters < u_maxIter) {{
|
||||
z = {vec2type}(
|
||||
z.x * z.x - z.y * z.y + c.x,
|
||||
-2.0 * z.x * z.y + c.y
|
||||
);
|
||||
|
||||
iters++;
|
||||
}}
|
||||
|
||||
return iters;
|
||||
}}
|
||||
"""
|
||||
|
||||
multi_mandelbar_calc = """int calculate_iters(vec2 c) {{
|
||||
int iters = 0;
|
||||
vec2 z = vec2(0.0);
|
||||
float n = {multi_n};
|
||||
float R = {escape_radius};
|
||||
|
||||
while (dot(z, z) < R * R && iters < u_maxIter) {{
|
||||
float r = length(z);
|
||||
float theta = atan(-z.y, z.x);
|
||||
|
||||
float r_n = pow(r, n);
|
||||
float theta_n = n * theta;
|
||||
|
||||
z = r_n * vec2(cos(theta_n), sin(theta_n)) + c;
|
||||
|
||||
iters++;
|
||||
}}
|
||||
|
||||
return iters;
|
||||
}}
|
||||
"""
|
||||
|
||||
burning_ship_calc = """int calculate_iters({vec2type} c) {{
|
||||
int iters = 0;
|
||||
{vec2type} z = {vec2type}(0.0, 0.0);
|
||||
@@ -183,6 +223,54 @@ burning_ship_calc = """int calculate_iters({vec2type} c) {{
|
||||
}}
|
||||
"""
|
||||
|
||||
phoenix_fractal_calc = """int calculate_iters({vec2type} c) {{
|
||||
int iters = 0;
|
||||
{vec2type} z = {vec2type}(0.0, 0.0);
|
||||
{vec2type} z_prev = {vec2type}(0.0, 0.0);
|
||||
{floattype} p = 0.56667;
|
||||
{floattype} R = {escape_radius};
|
||||
|
||||
while (dot(z, z) < R * R && iters < u_maxIter) {{
|
||||
{vec2type} z_new = {vec2type}(
|
||||
z.x * z.x - z.y * z.y + c.x - p * z_prev.x,
|
||||
2.0 * z.x * z.y + c.y - p * z_prev.y
|
||||
);
|
||||
|
||||
z_prev = z;
|
||||
z = z_new;
|
||||
iters++;
|
||||
}}
|
||||
|
||||
return iters;
|
||||
}}
|
||||
"""
|
||||
|
||||
lambda_fractal_calc = """int calculate_iters({vec2type} c) {{
|
||||
int iters = 0;
|
||||
{vec2type} z = {vec2type}(0.5, 0.0); // Try nonzero start
|
||||
float R = {escape_radius}; // Try R = 2.0 if needed
|
||||
|
||||
while (dot(z, z) < R * R && iters < u_maxIter) {{
|
||||
{vec2type} one_minus_z = {vec2type}(1.0, 1.0) - z;
|
||||
|
||||
{vec2type} temp = {vec2type}(
|
||||
z.x * one_minus_z.x - z.y * one_minus_z.y,
|
||||
z.x * one_minus_z.y + z.y * one_minus_z.x
|
||||
);
|
||||
|
||||
z = {vec2type}(
|
||||
c.x * temp.x - c.y * temp.y,
|
||||
c.x * temp.y + c.y * temp.x
|
||||
);
|
||||
|
||||
iters++;
|
||||
}}
|
||||
|
||||
return iters;
|
||||
}}
|
||||
"""
|
||||
|
||||
|
||||
newton_fractal_calc = """vec2 cmul(vec2 a, vec2 b) {{
|
||||
return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
|
||||
}}
|
||||
@@ -269,6 +357,18 @@ def create_iter_calc_shader(fractal_type, width, height, precision="single", mul
|
||||
else:
|
||||
replacements["iter_calc_func"] = multibrot_calc.format_map(replacements)
|
||||
|
||||
elif fractal_type == "mandelbar":
|
||||
if int(multi_n) == 2:
|
||||
replacements["iter_calc_func"] = mandelbar_calc.format_map(replacements)
|
||||
else:
|
||||
replacements["iter_calc_func"] = multi_mandelbar_calc.format_map(replacements)
|
||||
|
||||
elif fractal_type == "phoenix_fractal":
|
||||
replacements["iter_calc_func"] = phoenix_fractal_calc.format_map(replacements)
|
||||
|
||||
elif fractal_type == "lambda_fractal":
|
||||
replacements["iter_calc_func"] = lambda_fractal_calc.format_map(replacements)
|
||||
|
||||
elif fractal_type == "julia":
|
||||
if int(multi_n) == 2:
|
||||
replacements["iter_calc_func"] = normal_julia_calc.format_map(replacements)
|
||||
|
||||
@@ -38,8 +38,8 @@ class SierpinskyCarpetViewer(arcade.gui.UIView):
|
||||
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
||||
|
||||
self.info_box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10, vertical=False), anchor_x="center", anchor_y="top")
|
||||
self.zoom_label = self.info_box.add(arcade.gui.UILabel(text=f"Zoom: {self.zoom}", font_name="Protest Strike", font_size=16))
|
||||
self.depth_label = self.info_box.add(arcade.gui.UILabel(text=f"Depth: {self.depth}", font_name="Protest Strike", font_size=16))
|
||||
self.zoom_label = self.info_box.add(arcade.gui.UILabel(text=f"Zoom: {self.zoom}", font_name="Roboto", font_size=16))
|
||||
self.depth_label = self.info_box.add(arcade.gui.UILabel(text=f"Depth: {self.depth}", font_name="Roboto", font_size=16))
|
||||
|
||||
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
|
||||
self.back_button.on_click = lambda event: self.main_exit()
|
||||
|
||||
Reference in New Issue
Block a user