File: faces_cone.py

package info (click to toggle)
python-visual 1%3A5.12-1.6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 7,708 kB
  • ctags: 7,635
  • sloc: cpp: 15,593; sh: 9,615; ansic: 6,631; python: 4,737; makefile: 384
file content (47 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (3)
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
from visual import *
# Example of use of faces object for building arbitrary shapes (here, a cone)
# David Scherer July 2001

f = frame()

box( size=(0.5,0.5,0.5) )

# Make a cone (smooth shading, no bottom, normals are not quite physical)

N = 20

try: # numpy
    model = faces( pos = zeros( (N*3,3), float ), frame = f )
except: # older Numeric
    model = faces( pos = zeros( (N*3,3), Float ), frame = f )

t = arange(0,2*pi+2*pi/N,2*pi/N)

# Vertex 0 of triangles
model.pos[0::3, 0] = sin(t[:-1])
model.pos[0::3, 2] = cos(t[:-1])

# Vertex 1 of triangles
model.pos[1::3, 0] = sin(t[1:])
model.pos[1::3, 2] = cos(t[1:])

# Vertex 2 of triangles (point of cone)
model.pos[2::3, 1] = 2

# Construct normals to the edges of the triangles
model.normal = model.pos
model.normal[2::3,0] = sin(t[1:])
model.normal[0::1,1] = 0.5
model.normal[2::3,2] = cos(t[1:])

# Give each face a hue running from 0 to 1
model.color = model.pos
for vertex in range(3*N):
    hue = float(vertex // 3)/N
    model.color[vertex] = color.hsv_to_rgb((hue,1,1))

##model.color = model.pos/2 + (0.5,0,0.5) # alternative coloring

while 1:
    rate(100)
    f.rotate(angle=0.01)