-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sphere_tut.py
58 lines (41 loc) · 1.32 KB
/
Sphere_tut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import bpy
from math import pi, sin, cos
import colorsys
from random import TWOPI
# Center of sphere.
centerz = 0.0
centery = 0.0
centerx = 0.0
# Sphere diameter.
diameter = 10.0
sz = 5.0 / diameter
latitude = 20
longitude = latitude * 2
invlatitude = 1.0 / (latitude - 1)
invlongitude = 1.0 / (longitude - 1)
iprc = 0.0
jprc = 0.0
phi = 0.0
theta = 0.0
for i in range(0, latitude, 1):
iprc = i * invlatitude
phi = pi * (i + 1) * invlatitude
sinphi = sin(phi)
cosphi = cos(phi)
rad = 0.1 + sz * abs(sinphi) * 1
z = cosphi * diameter
for j in range(0, longitude, 1):
jprc = j * invlongitude
theta = TWOPI * j / longitude
sintheta = sin(theta)
costheta = cos(theta)
x = sinphi * costheta * diameter
y = sinphi * sintheta * diameter
bpy.ops.mesh.primitive_cube_add(location=(centerx + x, centery + y, centerz + z), radius=rad)
current = bpy.context.object
current.name = 'Cube ({0:0>2d}, {1:0>2d})'.format(i, j)
current.data.name = 'Mesh ({0:0>2d}, {1:0>2d})'.format(i, j)
current.rotation_euler = (0.0, phi, theta)
mat = bpy.data.materials.new(name='Material ({0:0>2d}, {1:0>2d})'.format(i, j))
mat.diffuse_color = colorsys.hsv_to_rgb(jprc, 1.0 - iprc, 1.0)
current.data.materials.append(mat)