Skip to content

Commit

Permalink
Fixed logistic mandelbrot for vispy==0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyhyman committed Feb 8, 2023
1 parent 426085e commit 9d05453
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ This is not a library, but rather a collection of standalone scripts! As such, t

#### If you run into problems
0. Google the problem you're running into
1. If it seems to be a problem with **this** code, post in "Issues"
1. If it seems to be a problem with **this** code, check if others are having the same problem in "Issues"
2. Post an issue if no one else has encountered the same thing

----

Expand Down
Binary file modified data/fractal_mandelbrot_data100_iter1500_ovs1.npz
Binary file not shown.
62 changes: 29 additions & 33 deletions logistic_mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from vispy.color import get_colormaps, BaseColormap
from vispy import app, scene, io
import vispy.visuals.volume
import vispy

from numba import jit, njit, prange
Expand Down Expand Up @@ -313,7 +314,8 @@ def make_triplebrot(mask, width, height, depth, max_iterations,

I = 1500 # maximum iterations in the mandelbrot calculation

rec_size = (2538, 1080) # frame resolution
# rec_size = (2538, 1080) # frame resolution, that we used in the video
rec_size = (1280, 720) # a better resolution for most screens

# where to put the frames
rec_prefix = './frames'
Expand Down Expand Up @@ -410,50 +412,44 @@ def make_triplebrot(mask, width, height, depth, max_iterations,
# Modify the vispy `transclucent` volume OpenGL shader

NEW_TRANSLUCENT_SNIPPETS = dict(
before_loop="""
vec4 integrated_color = vec4(0., 0., 0., 0.);
""",
in_loop="""
before_loop="""vec4 integrated_color = vec4(0., 0., 0., 0.); """,
in_loop =("""color = $cmap(val);
float a1 = integrated_color.a;
color = $cmap(val);
float a1 = integrated_color.a;
// MODIFIED color.r -> val because we have no alpha info
float a2 = val * (1 - a1);
// MODIFIED color.r -> val because we have no alpha info
float a2 = val * (1 - a1);
float alpha = max(a1 + a2, 0.001);
float alpha = max(a1 + a2, 0.001);
// Doesn't work.. GLSL optimizer bug?
//integrated_color = (integrated_color * a1 / alpha) +
// (color * a2 / alpha);
// This should be identical but does work correctly:
integrated_color *= a1 / alpha;
integrated_color += color * a2 / alpha;
// Doesn't work.. GLSL optimizer bug?
//integrated_color = (integrated_color * a1 / alpha) +
// (color * a2 / alpha);
// This should be identical but does work correctly:
integrated_color *= a1 / alpha;
integrated_color += color * a2 / alpha;
integrated_color.a = alpha;
integrated_color.a = alpha;
if( alpha > 0.99 ){
// stop integrating if the fragment becomes opaque
iter = nsteps;
}
""",
after_loop="""
gl_FragColor = integrated_color;
""",
if( alpha > 0.99 ){
// stop integrating if the fragment becomes opaque
iter = nsteps;
}"""),
after_loop="""gl_FragColor = integrated_color;""",
)

NEW_TRANSLUCENT_FRAG_SHADER = vispy.visuals.volume.FRAG_SHADER.format(
**NEW_TRANSLUCENT_SNIPPETS)

vispy.visuals.volume.frag_dict['translucent'] = NEW_TRANSLUCENT_FRAG_SHADER
class NewVolume(scene.visuals.Volume):
def __init__(self, *args, **kwargs):
self._rendering_methods['translucent'] = NEW_TRANSLUCENT_SNIPPETS
super().__init__(*args, **kwargs)

# Create the volume visuals, only one is visible
volume1 = scene.visuals.Volume(vol, parent = view.scene,
volume1 = NewVolume(vol, parent = view.scene,
cmap = 'nipy_spectral_r', # colormap
method = 'translucent', # shader method
relative_step_size = stepsize)



# rescale the volume to look like a `normal` mandelbrot set
volume1.transform = scene.MatrixTransform()
volume1.transform.scale([1,2/3,1])
Expand All @@ -466,7 +462,7 @@ def make_triplebrot(mask, width, height, depth, max_iterations,
volume1.transform.translate([0, (2/3-.4)*vol.shape[1], vol.shape[0]])


cam = scene.cameras.TurntableCamera(parent=view.scene, fov=1,
cam = scene.cameras.TurntableCamera(parent=view.scene, fov=2.0,
name='Turntable')

# Start distance (empircally determined)
Expand Down

0 comments on commit 9d05453

Please sign in to comment.