| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
from random import random, randrange |
| 7 |
from numpy import arange |
| 8 |
from math import pi, cos, sin |
| 9 |
|
| 10 |
from tvtk.tools.visual import curve, box, arrow, \ |
| 11 |
sphere, cylinder, show |
| 12 |
|
| 13 |
def random_box(): |
| 14 |
xx = randrange(-55,54) |
| 15 |
yy = randrange(-55,54) |
| 16 |
zz = randrange(-55,54) |
| 17 |
x = randrange(0,21) |
| 18 |
y = randrange(0,21) |
| 19 |
z = randrange(0,21) |
| 20 |
red = random() |
| 21 |
green = random() |
| 22 |
blue = random() |
| 23 |
box (pos = (xx,yy,zz), length=x, height=y, width=z, |
| 24 |
color=(red,green,blue)) |
| 25 |
|
| 26 |
def wirecube(s): |
| 27 |
c = curve(color = (1,1,1), radius=1) |
| 28 |
pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s), |
| 29 |
(-s, s, -s), (-s, -s, -s), (s, -s, -s), |
| 30 |
(s, s, -s), (-s, s, -s), (s, s, -s), |
| 31 |
(s, s, s), (-s, s, s), (s, s, s), |
| 32 |
(s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)] |
| 33 |
for pt in pts: |
| 34 |
c.append(pt) |
| 35 |
|
| 36 |
side = 150.0 |
| 37 |
cube = box(size = (side,side,side), representation = 'w' ) |
| 38 |
i = 0 |
| 39 |
while i < 100: |
| 40 |
random_box() |
| 41 |
i = i + 1 |
| 42 |
|
| 43 |
arrow(axis=(0,12,0), radius_shaft=3.5, color = (1,0,0)) |
| 44 |
|
| 45 |
ball = sphere(pos=(-side/2.,-side/2.,-side/2.),color=(1,1,0),radius=3) |
| 46 |
disk = cylinder(pos=(side/2.,side/2.,-side/2.),color=(.3,.3,1),axis=(1,1,0),radius=5) |
| 47 |
xx = arange(0,4*pi,pi/10.) |
| 48 |
spring=curve(color=(1,.7,.1), radius=0.4) |
| 49 |
for y in xx: |
| 50 |
spring.append([20+cos(2*y), y/2.-30, -20+sin(2*y)+30]) |
| 51 |
|
| 52 |
show() |