def pickFile(evt): #use VPython's file explorer function to find all python files and set f to the file selected by the user f = get_file(".py") #find the address of the file and replace all occurences of \ with a / for compatability path = f.name.replace("\\", "/") #fill this path in to the text box location.SetValue(path) #the name of the file is string following the final / in the address. name = path.split("/") name = name[len(name) - 1] #remove the .py from the end name = name[:-3] #fill this name into the text box progName.SetValue(name)
def getConfig(): d = {} fd = get_file(file_extensions=['.conf']) if fd: i = 0 #fd.read() or fd.readlines() for line in fd: d = dict(eval(line)) if i == 0: retain = d['retain'] i+= 1 else: if retain == True: temp = sphere(make_trail=d['make_trail'], display=scene1, pos=d['pos']*1, vel=d['vel']*1, acc=vector(0,0,0), mass=d['mass'], color=(.75,.75,.75), retain=10000, radius=newRadius(d['mass']) ) bodies.append( temp ) else: temp = sphere(make_trail=d['make_trail'], display=scene1, pos=d['pos']*1, vel=d['vel']*1, acc=vector(0,0,0), mass=d['mass'], color=(.75,.75,.75), retain=10000, radius=newRadius(d['mass']) ) bodies.append( temp ) fd.close() del fd
alg4Text = text(display=Alg, text="Reduced", align="center", depth=-0.3, color=color.yellow, pos=(0, -1.2, 0)) alg4Text.visible = False scene1 = display(title="N-Body Gravity", x=700, y=200, width=500, height=500) scene1.autoscale = True # Comment this out to see visualization of planetary motion. Uncomment for simulation runs needing to produce data # scene1.visible = False ## Make Scene Red Blue 3D # scene1.stereo = 'redcyan' ## Get Configuration From File d = {} fd = get_file(file_extensions=[".conf"]) if fd: i = 0 # fd.read() or fd.readlines() for line in fd: d = dict(eval(line)) if i == 0: retain = d["retain"] i += 1 else: if retain == True: temp = sphere( make_trail=d["make_trail"], display=scene1, pos=d["pos"], vel=d["vel"],
def loadObjects(self, reload_file=False): self.objects = {} if self.filename is None or reload_file is False: self.file = get_file(file_extensions=['.sim']) if self.file == None: # user hits cancel return None, Loader.OBJECTS_NOT_LOADED self.filename = self.file.name else: try: self.file = open(self.filename, 'r') except IOError as err: self.error_logger.write(" Error opening file: {}\n".format(str(err))) self.error_logger.finish() return None, Loader.FILE_NOT_OPENED self.file.seek(0) self.lines = self.file.readlines() self.file.close() errors = Loader.OBJECTS_LOADED line_number = 0 for line in self.lines: line_number += 1 position = None velocity = None mass = None shape = None radius = 0 texture = '' name = '' object_type = None try: line_segments = line.split(' ') for segment in line_segments: segment_parts = segment.split(':') if segment_parts[0] == 'name': name = segment_parts[1] elif segment_parts[0] == 'texture': try: texture = segment_parts[1] if segment_parts[1] not in self.textures: # make sure that each texture is loaded only once temp = self.loadTexture(segment_parts[1]) if temp is not None: # check that the texture was loaded succesfully self.textures[segment_parts[1]] = temp except IOError: errors = Loader.ERRORS_OCCURRED self.error_logger.write(" Could not load texture '{}' on line {}.\n".format(texture, line_number)) elif segment_parts[0] == 'pos': position = vector(float(segment_parts[1]), float(segment_parts[2]), float(segment_parts[3])) elif segment_parts[0] == 'mass': mass = float(segment_parts[1]) elif segment_parts[0] == 'radius': radius = float(segment_parts[1]) elif segment_parts[0] == 'velocity': velocity = vector(float(segment_parts[1]), float(segment_parts[2]), float(segment_parts[3])) elif segment_parts[0] == 'type': if segment_parts[1] in Loader.OBJECT_TYPES: object_type = segment_parts[1] else: self.error_logger.write(' Error. Invalid object type {} on line {}.\n'.format(segment_parts[1], line_number)) errors = Loader.ERRORS_OCCURRED except (ValueError,IndexError) as a: # invalid value in text file, print error message and skip the current line self.error_logger.write(' Error on line {}: {}. Object {} was not created.\n'.format(line_number, str(a), name)) errors = Loader.ERRORS_OCCURRED continue self.createObject(name,position,velocity,mass,object_type, radius, texture) if errors != 0: self.error_logger.finish() del self.lines[:] gc.collect() return (self.objects, errors)
# file i/o section: read in the .csv file created by Raven from our .WAV files # # In Raven, make the waveform window active, then go to File/Export Sound Samples... and save as a .csv file # These files contain no time information apart from the row number (you need to convert using the sampling frequency, # which is available in Raven under the file's information); the file is just a 4-column spreadsheet of the 4 channels' sound waveforms # and digest it to get (time, Ch1, Ch2, Ch3, Ch4) waveform # Be sure to prefilter files in Raven Pro 1.4 before analyzing them with this program. For our swallow mobbing cries, put them through # the Tools/Batch Band Filter using the Band Pass Filter from 1.5 KHz to 9kHz. You need to create a directory for the input and output files # for a batch process, so be careful not to overwrite the original files! Failing to bandpass filter the files will widen the cross-correlations # due to the much lower signal-to-noise ratio for unfiltered files. For other calls, be sure to get the correct bandpass filter values. # print "Get multichannel sound data now (as .CSV file)" fd = get_file() print fd.name start = time.time() ifile = open(fd.name, "rb") reader = csv.reader( ifile ) # reader = object that iteratures over lines in the .csv file being read in; this is an ongoing process reader_length = reader.line_num # the number of lines read in from the file print "time to read in multichannel sound file = ", (time.time() - start), " s" ###### Save a file of probablities vs. grid location: (time, x,y,z, prob) #####################################################
for n in range(3): triNor.append( [ float(FileLine[2]), float(FileLine[3]), float(FileLine[4]) ] ) elif FileLine[0] == 'vertex': triPos.append( [ float(FileLine[1]), float(FileLine[2]), float(FileLine[3]) ] ) triPos = array(triPos) triNor = array(triNor) # Compose faces in default frame f = frame() return faces(frame=f, pos=triPos, normal=triNor) if __name__ == '__main__': print "Choose an stl file to display. Rotate!" # Open .stl file while True: fd = get_file() if not fd: continue scene.width = scene.height = 800 scene.autocenter = True newobject = stl_to_faces(fd) newobject.smooth() # average normals at a vertex # Examples of modifying the returned object: ## newobject.frame.pos = (-1,-1,-0.5) ## newobject.frame.axis = (0,1,0) newobject.color = color.orange newobject.material = materials.wood break
def main(): xc = 0 yc = 0 zc = -0.5 vn = " A" vis = True res = 0 allcodes = "" codelist = [] code = "" letter = "" typein = 0 rowin = 0 xint = 0 m = 1 t = 2 ink = 0.1 scene.width = 800 scene.height = 600 scene.title = "2D CNC" scene.forward = (0, 1, 0) scene.background = color.white center = (0, 0, 0) lamp = local_light(pos=(0, -2.5, 1.5), color=color.white) blackyellow = ((0, 1, 0, 1, 0, 1, 0, 1), (0, 1, 0, 1, 0, 1, 0, 1)) blackyellow2 = ((0, 0), (1, 1), (0, 0), (1, 1), (0, 0), (1, 1), (0, 0), (1, 1)) horlines = materials.texture(data=blackyellow, mapping="rectangular", interpolate=False) verlines = materials.texture(data=blackyellow2, mapping="rectangular", interpolate=False) pen = cylinder(pos=(0, 0, -0.5), axis=(0, 0, 1), radius=0.25) pen.length = 4 pen.material = materials.shiny pen.color = color.black peak = cone(pos=(0, 0, -0.5), axis=(0, 0, -1), radius=0.25) peak.color = color.black peak.material = materials.shiny peak.length = 1 ballpoint = sphere(pos=vector(0, 0, -5), color=color.blue, radius=0.05) ballpoint.visible = False pole1 = box(pos=(-5, -5, 0), size=(1, 1, 5), color=color.yellow, material=horlines) pole2 = box(pos=(5, -5, 0), size=(1, 1, 5), color=color.yellow, material=horlines) pole3 = box(pos=(-5, 5, 0), size=(1, 1, 5), color=color.yellow, material=horlines) pole4 = box(pos=(5, 5, 0), size=(1, 1, 5), color=color.yellow, material=horlines) bridge12 = box(pos=(-5, 0, 2), size=(1, 9, 1), material=materials.blazed) bridge34 = box(pos=(5, 0, 2), size=(1, 9, 1), material=materials.blazed) hormet1 = cylinder(pos=(-4.25, 0.75 + yc, 3), axis=(1, 0, 0), length=8.5, radius=0.25, material=materials.shiny) hormet2 = cylinder(pos=(-4.25, -0.75 + yc, 3), axis=(1, 0, 0), length=8.5, radius=0.25, material=materials.shiny) xaxisbox = box(pos=(0, 0, 3), size=(1.5, 3, 1.1), color=color.yellow, material=verlines) yaxisbridge12 = box(pos=(-5, 0, 2.375), size=(1.5, 2.5, 2.75), color=color.yellow, material=verlines) yaxisbridge34 = box(pos=(5, 0, 2.375), size=(1.5, 2.5, 2.75), color=color.yellow, material=verlines) platform = box(pos=(0, 0, -2.5), size=(12, 12, 0.125), material=materials.wood) sheet = box(pos=(0, 0, -2.375), size=(10, 10, 0.125), material=materials.plastic) xcoord = label(yoffset=260, xoffset=265, line=0, text="", color=color.black) ycoord = label(yoffset=230, xoffset=265, line=0, text="", color=color.black) zcoord = label(yoffset=200, xoffset=265, line=0, text="PEN UP", color=color.black) viewn = label(yoffset=170, xoffset=265, line=0, text="", color=color.black) thickness = label(yoffset=140, xoffset=265, line=0, text="", color=color.black) while True: rate(1000) if scene.kb.keys: key = scene.kb.getkey() if key == "d" or key == "D": xc = xc + ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "a" or key == "A": xc = xc - ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "w" or key == "W": yc = yc + ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "x" or key == "X": yc = yc - ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "e" or key == "E": xc = xc + ink * m yc = yc + ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "q" or key == "Q": xc = xc - ink * m yc = yc + ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "z" or key == "Z": yc = yc - ink * m xc = xc - ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "c" or key == "C": xc = xc + ink * m yc = yc - ink * m if zc == -1.25: if (-3.5 <= xc <= 3.5) and (-3.3 <= yc <= 3.3): box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, 0.1), color=color.black) if key == "s" or key == "S": if zc == -0.5: zc = -1.25 zcoord.text = "PEN DOWN" else: zc = -0.5 zcoord.text = "PEN UP" if key == "1": scene.forward = (0, 1, 0) vn = 1 if key == "2": scene.forward = (0, 1, -1) vn = 2 if key == "3": scene.forward = (0, 0, -1) vn = 3 if key == "4": if vis == True: vis = False else: vis = True if key == "r" or key == "R": xc = 0 yc = 0 zc = -0.5 pen.pos.x = xc peak.pos.x = xc xaxisbox.pos.x = xc pen.pos.y = yc peak.pos.y = yc xaxisbox.pos.y = yc yaxisbridge12.pos.y = yc yaxisbridge34.pos.y = yc hormet1.pos.y = yc + 0.75 hormet2.pos.y = yc - 0.75 pen.pos.z = zc peak.pos = (xc, yc, zc) ballpoint.pos.x = xc ballpoint.pos.y = yc ballpoint.pos.z = -2.25 t = 2 ink = 0.1 m = 1 if key == "v" or key == "V": xc = -3.5 yc = 3.3 zc = -0.5 pen.pos.x = xc peak.pos.x = xc xaxisbox.pos.x = xc pen.pos.y = yc peak.pos.y = yc xaxisbox.pos.y = yc yaxisbridge12.pos.y = yc yaxisbridge34.pos.y = yc hormet1.pos.y = yc + 0.75 hormet2.pos.y = yc - 0.75 pen.pos.z = zc peak.pos = (xc, yc, zc) ballpoint.pos.x = xc ballpoint.pos.y = yc ballpoint.pos.z = -2.25 t = 2 ink = 0.1 m = 1 if key == "m" or key == "M": m = m + 1 if m > 5: m = 1 if key == "t" or key == "T": t = t + 1 if t == 2: ink = 0.1 if t == 3: ink = 1 if t > 3: t = 1 ink = 0.01 if key == "n" or key == "N": xint = xc design = get_file() allcodes = design.read() codelist = allcodes.split() rowin = len(codelist) res = len(codelist[0]) #print allcodes #print rowin #print res for i in range(rowin): code = codelist[i] for j in range(res - 1): letter = code[j] typein = int(letter) #print letter #print "typein" + str(typein) if typein == 1: zc = -1.25 if typein == 0: zc = -0.5 for k in range(3): pen.pos.z = zc #print pen.pos.x #print pen.pos.z xc = xc + ink * m pen.pos.x = xc peak.pos.x = xc xaxisbox.pos.x = xc pen.pos.y = yc peak.pos.y = yc xaxisbox.pos.y = yc yaxisbridge12.pos.y = yc yaxisbridge34.pos.y = yc hormet1.pos.y = yc + 0.75 hormet2.pos.y = yc - 0.75 ballpoint.pos.x = xc ballpoint.pos.y = yc if typein == 1: box(pos=(xc, yc, zc - 1), size=(ink * m, ink * m, ink * m), color=color.black) if xc >= 3.5: xc = 3.5 if xc <= -3.5: xc = -3.5 if yc >= 3.3: yc = 3.3 if yc <= -3.3: yc = -3.3 yc = yc - ink * m xc = xint if xc >= 3.5: xc = 3.5 if xc <= -3.5: xc = -3.5 if yc >= 3.3: yc = 3.3 if yc <= -3.3: yc = -3.3 if vis == False: pen.opacity = 0.1 peak.opacity = 0.1 hormet1.opacity = 0.1 hormet2.opacity = 0.1 xaxisbox.opacity = 0.1 ballpoint.visisble = True else: pen.opacity = 1 peak.opacity = 1 hormet1.opacity = 1 hormet2.opacity = 1 xaxisbox.opacity = 1 ballpoint.visible = False pen.pos.x = xc peak.pos.x = xc xaxisbox.pos.x = xc pen.pos.y = yc peak.pos.y = yc xaxisbox.pos.y = yc yaxisbridge12.pos.y = yc yaxisbridge34.pos.y = yc hormet1.pos.y = yc + 0.75 hormet2.pos.y = yc - 0.75 ballpoint.pos.x = xc ballpoint.pos.y = yc ballpoint.pos.z = -2.25 xcoord.text = "x-coordinate:" + str(xc) ycoord.text = "y-coordinate:" + str(yc) viewn.text = "View:" + str(vn) thickness.text = str(ink) + " x " + str(m)