Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created November 26, 2015 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/e423edc9fa8e664db208 to your computer and use it in GitHub Desktop.
Save zeffii/e423edc9fa8e664db208 to your computer and use it in GitHub Desktop.
spiral_sphere.py not parametric
import bpy
import math
import random
def fibonacci_sphere(samples, rseed, granularity):
# http://stackoverflow.com/a/26127012/1243487
rnd = 1.
random.seed(rseed)
rnd = random.random() * samples
points = []
offset = 2. / samples
increment = math.pi * (3. - math.sqrt(5.)) / granularity
for i in range(samples):
y = ((i * offset) - 1) + (offset / 2)
r = math.sqrt(1 - pow(y, 2))
phi = ((i + rnd) % samples) * increment
x = math.cos(phi) * r
z = math.sin(phi) * r
points.append([x, y, z])
return points
def make_spiral_sphere(obj_name, rseed=279, samples=1101, granularity=20):
verts = fibonacci_sphere(samples, rseed, granularity)
edges = [[i, i + 1] for i in range(len(verts) - 1)]
mesh = bpy.data.meshes.new(obj_name + "_mesh")
mesh.from_pydata(verts, edges, [])
mesh.update()
obj = bpy.data.objects.new(obj_name, mesh)
scene = bpy.context.scene
scene.objects.link(obj)
make_spiral_sphere("sphere_spiral")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment