File: convex.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 (51 lines) | stat: -rw-r--r-- 1,138 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
48
49
50
51
from visual import *
from random import uniform

a = convex(color=(0.5,0,0))
b = convex(color=(0,0.5,0))
c = convex(color=(0,0,0.5))
d = convex(color=(0.5,0,0.5))
e = convex(color=(0.5,0.5,0))
f = convex(color=(0,0.5,0.5))

# circle
t = arange(0,2*pi,0.1)
e.pos = transpose( (sin(t), cos(t)+2, 0*t) )

# triangle
t = arange(0,2*pi,2*pi/3)
f.pos = transpose( (sin(t)-2, cos(t)+2, 0*t) )

# disk
for t in arange(0,2*pi,0.1):
    a.append(pos = (cos(t),0,sin(t)))
    a.append(pos = (cos(t),0.2,sin(t)))

# box
for i in range(8):
    p = vector((i/4)%2 - 2.5, (i/2)%2 - 0.5, (i)%2 - 0.5)
    b.append(pos=p)

# random sphere
L = []
for i in range(1000):
    L.append(vector(2,0) + norm(vector(uniform(-1,1),uniform(-1,1),uniform(-1,1))))
c.pos = L

# lat/long sphere
L = []
for t in arange(0,2*pi,0.2):
    for s in arange(0,pi,0.1):
        L.append((cos(t)*sin(s)+2, sin(t)*sin(s)+2, cos(s)))
print len(L)
d.pos = L

# modify the disk
p = a
p.color = (p.color[0]*2, p.color[1]*2, p.color[2]*2)
while 1:
    rate(10)
    if scene.mouse.clicked:
        c = scene.mouse.getclick()
        p.append(pos=c.pos)
    p.pos[-1] = scene.mouse.pos