Stray_Tom

HCP Pattern in Blender

Dec 28th, 2022
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import bpy
  2. from math import sqrt
  3.  
  4. # Set the dimensions of the HCP pattern
  5. dim_x = 5
  6. dim_y = 5
  7. dim_z = 5
  8.  
  9. # Set the radius of the spheres
  10. radius = 1
  11.  
  12. # Set the distance between the spheres
  13. spacing = radius * sqrt(2)
  14.  
  15. # Set the starting position for the first sphere
  16. start_x = -dim_x * spacing / 2
  17. start_y = -dim_y * spacing / 2
  18. start_z = -dim_z * spacing / 2
  19.  
  20. # Create a list to store the spheres
  21. spheres = []
  22.  
  23. # Create the spheres
  24. for i in range(dim_x):
  25. for j in range(dim_y):
  26. for k in range(dim_z):
  27. x = start_x + i * spacing
  28. y = start_y + j * spacing
  29. z = start_z + k * spacing
  30. if (i + j + k) % 2 == 0:
  31. bpy.ops.mesh.primitive_uv_sphere_add(location=(x, y, z), radius=radius)
  32. spheres.append(bpy.context.active_object)
  33.  
Advertisement
Add Comment
Please, Sign In to add comment