File: faces_cone.py

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (41 lines) | stat: -rw-r--r-- 1,009 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
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

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

# All normals point outward in XZ... not quite right, but there is already a cone primitive :)
model.normal = model.pos
model.normal[2::3,0] = sin((t[:-1]+t[1:])/2)
model.normal[2::3,1] = 0
model.normal[2::3,2] = cos((t[:-1]+t[1:])/2)

model.color = model.pos/2 + (0.5,0,0.5)
model.smooth_shade(doublesided=0)

##model.color[0::3] = (1,1,1)   # show where the triangles are

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