Stray_Tom

Weird Julia 3d Fractal in Blender

Dec 28th, 2022
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import bpy
  2. import math
  3.  
  4. # Set the resolution of the point cloud
  5. resolution = 400
  6.  
  7. # Set the maximum number of iterations
  8. max_iter = 10
  9.  
  10. # Set the escape radius
  11. escape_radius = 2
  12.  
  13. # Set the minimum and maximum values for the x, y, and z coordinates
  14. min_coord = -2
  15. max_coord = 2
  16.  
  17. # Initialize the point cloud data
  18. points = []
  19.  
  20. # Iterate over the x, y, and z coordinates
  21. for x in range(resolution):
  22. for y in range(resolution):
  23. for z in range(resolution):
  24. # Convert the x, y, and z indices to coordinates in the range [min_coord, max_coord]
  25. coord_x = min_coord + (x / resolution) * (max_coord - min_coord)
  26. coord_y = min_coord + (y / resolution) * (max_coord - min_coord)
  27. coord_z = min_coord + (z / resolution) * (max_coord - min_coord)
  28.  
  29. # Initialize the coordinates and the iteration count
  30. c = complex(coord_x, coord_y)
  31. z = complex(coord_x, coord_y)
  32. iteration = 0
  33.  
  34. # Iterate the Mandelbrot function until the escape radius is reached or the maximum number of iterations is reached
  35. while abs(z) < escape_radius and iteration < max_iter:
  36. z = z**2 + c + complex(0, coord_z)
  37. iteration += 1
  38.  
  39. # If the maximum number of iterations was reached, add the coordinates to the point cloud data
  40. if iteration == max_iter:
  41. points.append((coord_x, coord_y, coord_z))
  42.  
  43. # Create a new mesh and add it to the scene
  44. mesh = bpy.data.meshes.new("Julia")
  45. obj = bpy.data.objects.new("Julia", mesh)
  46. bpy.context.collection.objects.link(obj)
  47.  
  48. # Set the vertices of the mesh using the point cloud data
  49. mesh.from_pydata(points, [], [])
  50. mesh.update()
Advertisement
Add Comment
Please, Sign In to add comment