Commit 1277e3b1 authored by Rafael Peretti Pezzi's avatar Rafael Peretti Pezzi

Add member to dataDriver: datafile

parent efe37505
......@@ -66,13 +66,14 @@ class genDriver(animationDriver): # A driver for particle generators
return particles;
class dataDriver(animationDriver): # A driver for data from files.
def __init__(self,name,filename):
self.name = name+"_"+filename+"_"
def __init__(self,name,datafile):
self.name = name+"_"+datafile+"_"
self.datafile = datafile
def getParticles(self): # Create particles acording to parameters from file
# Count number of lines in file = number of particles
detail_file = open(filename, 'r')
detail_file = open(self.datafile, 'r')
linecount = 0
for line in open(filename).readlines( ): linecount += 1 # File must be in the same directory
for line in open(self.datafile).readlines( ): linecount += 1 # File must be in the same directory
# Set number of particles
N_particles = linecount
particles=[]
......@@ -87,9 +88,9 @@ class dataDriver(animationDriver): # A driver for data from files.
Px = lines[i].split(' ')[5]
Py = lines[i].split(' ')[6]
Pz = lines[i].split(' ')[7]
part = ParticlePropagator(i,x,y,z,charge,mass)
part.SetMagneticField()
part.SetProperties(Px,Py,Pz)
part = ParticlePropagator(i,float(x),float(y),float(z),float(charge),float(mass))
part.SetMagneticField(0.5)
part.SetProperties(float(Px),float(Py),float(Pz))
particles.append(part)
detail_file.close()
return particles;
......@@ -72,6 +72,7 @@ def createSceneParticles(particles):
# Create blender spheres (particles)
blender_particles=[]
n_particles=len(particles)
for particle in particles:
this_type=random.choice(particle_types) #TO DO: make this not random, but according to file data
print("Adding Sphere - Particle " + str(len(blender_particles))+" of "+str(n_particles-1)+" - "+this_type)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment