def userInput(self, *args): # function to save user input and take output from algorithm
name_of_file = 'algorithm_input'# USER INPUT FILENAME
inputFileName = os.path.join(assetsdirectory, name_of_file+'.txt') #TOTAL PATH NAME
with open(inputFileName, 'w') as f: # create file and write initial and final coordinate positions
f.write('%f\t%f\t%f\t%f' % (drawUtility.x_initial, drawUtility.y_initial, drawUtility.x_final, drawUtility.y_final))
drawUtility.canvas.clear()
particle = Particle(pos = (drawUtility.x_initial, drawUtility.y_initial), size = (10, 10)) # draw a particle at chosen initial position
drawUtility.add_widget(particle)
while os.path.isfile('algorithm_output.npy') == False: # search for output file
sleep(1)
print ("Still no file")
else:
x = np.load('mylistx.npy'); xs = np.split(x, len(x)/200, 0) # test data
y = np.load('mylisty.npy'); ys = np.split(y, len(y)/200, 0)
print ("File found!")
#x,y = np.load('algorithm_output.npy') # load in algorithm output
#xs = np.split(x, len(x)/200, 0); ys = np.split(y, len(y)/200, 0) # split x and y arrays into manageable chunks for animation
self.animate(xs, ys, 0, particle) # call animation function with output data
评论列表
文章目录