Attachment 'example.py'

Download

   1 from visual import *
   2 from random import uniform
   3 
   4 # David Scherer
   5 
   6 scene.range = 3
   7 
   8 a = convex(color=(0.5,0,0))
   9 b = convex(color=(0,0.5,0))
  10 c = convex(color=(0,0,0.5))
  11 d = convex(color=(0.5,0,0.5))
  12 e = convex(color=(0.5,0.5,0))
  13 f = convex(color=(0,0.5,0.5))
  14 
  15 # circle
  16 t = arange(0,2*pi,0.1)
  17 e.pos = transpose( (sin(t), cos(t)+2, 0*t) )
  18 
  19 # triangle
  20 t = arange(0,2*pi,2*pi/3)
  21 f.pos = transpose( (sin(t)-2, cos(t)+2, 0*t) )
  22 
  23 # disk
  24 for t in arange(0,2*pi,0.1):
  25     a.append(pos = (cos(t),0,sin(t)))
  26     a.append(pos = (cos(t),0.2,sin(t)))
  27 
  28 # box
  29 for i in range(8):
  30     p = vector((i/4)%2 - 2.5, (i/2)%2 - 0.5, (i)%2 - 0.5)
  31     b.append(pos=p)
  32 
  33 # random sphere
  34 L = []
  35 for i in range(1000):
  36     L.append(vector(2,0) + norm(vector(uniform(-1,1),uniform(-1,1),uniform(-1,1))))
  37 c.pos = L
  38 
  39 # lat/long sphere
  40 L = []
  41 for t in arange(0,2*pi,0.2):
  42     for s in arange(0,pi,0.1):
  43         L.append((cos(t)*sin(s)+2, sin(t)*sin(s)+2, cos(s)))
  44 print len(L)
  45 d.pos = L
  46 
  47 # modify the disk
  48 p = a
  49 p.color = (p.color[0]*2, p.color[1]*2, p.color[2]*2)
  50 while 1:
  51     rate(10)
  52     if scene.mouse.clicked:
  53         c = scene.mouse.getclick()
  54         p.append(pos=c.pos)
  55     p.pos[-1] = scene.mouse.pos

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-10-25 16:26:17, 1.1 KB) [[attachment:example.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.