def draw2DMovie(solution, t_filming_step, x_start, x_end, y_start, legend, solution_min_value, solution_max_value, t_grid_step):
#??????????, ?????????????? ????? ???? ?????(????? ??? ??????????)
time_marker_length = len(str(t_filming_step))
#!!!????? ?????????, ????? ?????? x ? ????? ?????? y ?? ????? ???????? ?????
x_slice_value = 3
y_slice_value = -1
y_end = 0
#???? ???????? ?? ?????, ??????? ???????? ?????? ? ???????? ????????? ??????:
#1: ????? ???? ???? ?? ???????
npArray = np.array(solution[0])
#2: ???? ?????? ?? ????
M = len(npArray)
x_step = (x_end - x_start) / M
x = np.arange(x_start,x_end,x_step)
x_slice_index = int((x_slice_value - x_start) / x_step) + 1
#3: ???? ?????? ?? ??????
M = len(npArray[0])
y_step = (0 - y_start) / M
y = np.arange(y_start,y_end,y_step)
y_slice_index = int((y_slice_value - y_start) / y_step) + 1
#??????? ?????, ???? ?? ?? ??????????
if not os.path.exists('img'):
os.makedirs('img')
#??????? ????? ?? ?????????? img\ ????? ????????? ????????.
files = glob.glob('img' + os.sep + '*')
for f in files:
os.remove(f)
#???? ???????????? ???, ??????, ?? ?????? ? ????, ??? ????? ???????? ???????? ??????? ???????????? ?? ?????.
#???????????? ????????????? ???? ?? ?????????? ? ?????.
#?????????? ?? ????? ????? ?????? ??? ????? ??????.
# absolute_solution_minimum = solution_min_value
# absolute_solution_maximum = solution_max_value
#???????? ????????? ?????? ?? ??????? ? ?????.
for i in range(0, solution.shape[0], t_filming_step):
#???? ???????????? ???, ?????? ?? ?????? ? ????????? ????. ???????????? ????????????? ???? ?? ?????????? ????? ????? ??????
#?????????? ?? ????? ????? ??????????? ???????? ??? ??????? ?????
absolute_solution_minimum = np.min(np.min(solution[i]))
absolute_solution_maximum = np.max(np.max(solution[i]))
draw2DSlice(solution[i], i * t_grid_step,
x_start, x_end, y_start, legend,
absolute_solution_minimum, absolute_solution_maximum,
time_marker_length)
#?????? ????? ?? ??????????? ????? img\, ????????? ?? ???? ??.
images = []
filenames = sorted(fn for fn in os.listdir(path='img' + os.sep) if fn.endswith('s.png'))
for filename in filenames:
tmp = imageio.imread('img' + os.sep + filename)
images.append(tmp)
imageio.mimsave('img' + os.sep + legend + ' movie.gif', images, duration = 0.2)
评论列表
文章目录