Skip to content

Instantly share code, notes, and snippets.

@ryseto
Last active January 4, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryseto/8579897 to your computer and use it in GitHub Desktop.
Save ryseto/8579897 to your computer and use it in GitHub Desktop.
visualization of 2d sheared particles by using vpython
#/Applications/VPython-Py2.7/VIDLE.app/Contents/MacOS/Python
# coding=utf-8
from visual import *
import numpy
import sys
fin = open(sys.argv[1])
scene = display(title='Simple Shear',
width=1100, height=800,
background=color.gray(0.8), fullscreen=True)
line = fin.readline()
data = line.split()
np = int(data[1])
lx = float(data[3])
ly = float(data[4])
lz = float(data[5])
scene.fov = 0.1
#scene.ambient=(0.721879,0.721748,0.295551)
scene.ambient=(0.811841,0.319825,0.097166)
scene.cursor.visible = False
scene.forward = (0,0,-1)
particles1 = [ sphere(material=materials.marble ) for i in range(np) ]
rotaxis = [0,0,-1]
cnt = 0
angles = numpy.zeros(np)
while True:
line = fin.readline()
data = line.split()
if len(data)==0:
break
disp = float(data[1])
particle_data = numpy.fromfile(fin, dtype=float, sep=' ', count=(5*np))
particle_data = particle_data.reshape((np, 5))
positions_data = particle_data[:,[1,2]]
if cnt == 0:
radii = particle_data[:,4]
for particle, position, radius in zip(particles1, positions_data, radii):
particle.radius = radius
particle.pos = [position[0], position[1], 0]
else:
angles = particle_data[:,3]-angles;
for particle, position, ang in zip(particles1, positions_data, angles):
particle.pos = [position[0], position[1], 0]
particle.rotate(angle=ang, axis=(rotaxis))
rate(15)
cnt += 1
angles = particle_data[:,3];
# raw_input()
fin.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment