def interpolate(frame, total_time, frame_len): start_fid = frames_model.get_frame_from_pos(frame)['id'] end_fid = frames_model.get_frame_from_pos(frame + 1)['id'] start_pieces = pieces_model.pieces[start_fid] end_pieces = pieces_model.pieces[end_fid] fc = int(total_time / frame_len + 0.999) frame_len = int(total_time / fc + 0.5) for fi in range(0, fc - 1): pieces = [] for i in range(0, len(start_pieces)): d = (fi + 1) / fc piece = dict(start_pieces[i]) goal = end_pieces[i] for k in filter(lambda v: v not in ['id', 'img'], piece.keys()): piece[k] += (goal[k] - piece[k]) * d pieces.append(piece) frame = frames_model.get_new_frame() frame['length'] = frame_len frames_model.frames.insert(frames_model.get_frame_position(end_fid), frame) pieces_model.pieces[frame['id']] = pieces frames_controller.update_view() pieces_controller.update_view()
def apply(frame, total_time, frame_len): if frame not in range(0, len(frames_model.frames) - 1): view_util.error('Invalid frame') return start_fid = frames_model.get_frame_from_pos(frame)['id'] end_fid = frames_model.get_frame_from_pos(frame + 1)['id'] start_pieces = pieces_model.pieces[start_fid] end_pieces = pieces_model.pieces[end_fid] sid_list = [p['id'] for p in start_pieces] eid_list = [p['id'] for p in end_pieces] if sid_list != eid_list: view_util.error( 'Interpolating between frames requires that they are clones of one another\n' 'Images can not be added or removed, only modified\n' 'Image order must be the same (no moving up or down)') return fc = int(total_time / frame_len + 0.999) - 1 res = view_util.yesnobox( 'This will create {} frames. Continue?'.format(fc)) if res == tk.YES: actions_controller.interpolate_action(start_fid, end_fid, total_time, frame_len) interpolate(frame, total_time, frame_len)
def batch_shift(piece_id, start_frame, end_frame, frame_len, xpos, ypos, xscale, yscale, alpha, rot): xscale /= 100 yscale /= 100 for fi in range(start_frame, end_frame + 1): if frame_len > 0: frames_model.frames[fi]['length'] = frame_len fid = frames_model.get_frame_from_pos(fi)['id'] if fid in pieces_model.pieces.keys(): for i in range(0, len(pieces_model.pieces[fid])): if pieces_model.pieces[fid][i][ 'id'] == piece_id or not piece_id: nxs = pieces_model.pieces[fid][i]['x_scale'] + xscale nxs = 0.1 if nxs <= 0 else nxs nys = pieces_model.pieces[fid][i]['y_scale'] + yscale nys = 0.1 if nys <= 0 else nys na = pieces_model.pieces[fid][i]['alpha'] + alpha na = 0 if na < 0 else na na = 255 if na > 255 else na nr = int(pieces_model.pieces[fid][i]['rotation'] + rot) % 360 pieces_model.pieces[fid][i]['x'] += xpos pieces_model.pieces[fid][i]['y'] += ypos pieces_model.pieces[fid][i]['x_scale'] = nxs pieces_model.pieces[fid][i]['y_scale'] = nys pieces_model.pieces[fid][i]['alpha'] = na pieces_model.pieces[fid][i]['rotation'] = nr pieces_controller.update_view() frames_controller.update_view()
def update_view(): i = model.get_frame_position(model.active_frame()) if i is None: i = 0 model._active_frame = model.frames[0]['id'] length = model.get_frame_from_pos(i)['length'] view_options.set_frame_count(len(model.frames)) view_options.set_active(i) view_options.set_length(length) loop_view.set_is_loop(model.is_loop)
def move_frame_down(): i = model.get_frame_position(model.active_frame()) ni = i + 1 if ni < len(model.frames): actions_controller.move_frame_action( model.get_frame_from_pos(i)['id'], 1) temp = model.frames[ni] model.frames[ni] = model.frames[i] model.frames[i] = temp update_view()
def move_frame_up(): i = model.get_frame_position(model.active_frame()) ni = i - 1 if ni >= 0: actions_controller.move_frame_action( model.get_frame_from_pos(i)['id'], -1) temp = model.frames[ni] model.frames[ni] = model.frames[i] model.frames[i] = temp update_view()
def percent_shift(piece_id, start_frame, end_frame, frame_len, xscale, yscale, alpha, rot): frame_len /= 100 xscale /= 100 yscale /= 100 alpha /= 100 rot /= 100 for fi in range(start_frame, end_frame + 1): fl = frames_model.frames[fi]['length'] frames_model.frames[fi]['length'] = fl + int(fl * frame_len) if frames_model.frames[fi]['length'] < 5: frames_model.frames[fi]['length'] = 5 fid = frames_model.get_frame_from_pos(fi)['id'] if fid in pieces_model.pieces.keys(): for i in range(0, len(pieces_model.pieces[fid])): if pieces_model.pieces[fid][i][ 'id'] == piece_id or not piece_id: nxs = pieces_model.pieces[fid][i][ 'x_scale'] + pieces_model.pieces[fid][i][ 'x_scale'] * xscale nxs = 0.1 if nxs <= 0 else nxs nys = pieces_model.pieces[fid][i][ 'y_scale'] + pieces_model.pieces[fid][i][ 'y_scale'] * yscale nys = 0.1 if nys <= 0 else nys na = pieces_model.pieces[fid][i]['alpha'] + int( pieces_model.pieces[fid][i]['alpha'] * alpha) na = 0 if na < 0 else na na = 255 if na > 255 else na nr = (pieces_model.pieces[fid][i]['rotation'] + int( pieces_model.pieces[fid][i]['rotation'] * rot)) % 360 pieces_model.pieces[fid][i]['x_scale'] = nxs pieces_model.pieces[fid][i]['y_scale'] = nys pieces_model.pieces[fid][i]['alpha'] = na pieces_model.pieces[fid][i]['rotation'] = nr pieces_controller.update_view() frames_controller.update_view()
def delete_frame(): if len(model.frames) > 1: i = model.get_frame_position(model.active_frame()) frame = model.get_frame(model.active_frame()) actions_controller.delete_frame_action( frame, i, pieces_model.pieces[frame['id']]) ni = i + 1 if ni >= len(model.frames): ni = len(model.frames) - 2 # Deleting last, next is second last model._active_frame = model.get_frame_from_pos(ni)['id'] pieces_controller.change_active_frame(frame['id'], model.active_frame()) model.frames.remove(frame) if frame['id'] in pieces_model.pieces.keys(): del pieces_model.pieces[frame['id']] update_view() else: util.error('You need to have at least one frame, jackass')
def undo(): if model.current_action is not None and model.current_action in range( 1, len(model.actions)): action = model.actions[model.current_action] data = action['data'] if action['type'] == 'add_piece': pieces_model.remove_piece(data['frame_id'], data['piece']['id']) pieces_controller.update_view() elif action['type'] == 'update_piece': pieces_model.update_piece(data['frame_id'], data['old']) pieces_controller.update_view() elif action['type'] == 'delete_piece': pieces_model.pieces[data['frame_id']].append(data['piece']) pieces_controller.update_view() elif action['type'] == 'move_piece': i = 0 for p in pieces_model.pieces[data['frame_id']]: if p['id'] == data['piece_id']: break i += 1 ni = i - data['index_change'] temp = pieces_model.pieces[data['frame_id']][i] pieces_model.pieces[data['frame_id']][i] = pieces_model.pieces[ data['frame_id']][ni] pieces_model.pieces[data['frame_id']][ni] = temp pieces_controller.update_view() elif action['type'] == 'add_image': images_model.remove_image(data['id']) images_controller.update_view() elif action['type'] == 'delete_image': view_util.error('This cannot be undone') elif action['type'] == 'add_frame': if data['frame']['id'] in pieces_model.pieces.keys(): del pieces_model.pieces[data['frame']['id']] del frames_model.frames[data['index']] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'update_frame': i = frames_model.get_frame_position(data['frame_id']) frames_model.frames[i]['length'] = data['old_len'] frames_controller.update_view() elif action['type'] == 'move_frame': i = frames_model.get_frame_position(data['frame_id']) ni = i - data['index_change'] temp = frames_model.frames[i] frames_model.frames[i] = frames_model.frames[ni] frames_model.frames[ni] = temp frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'delete_frame': frames_model.frames.insert(data['index'], data['frame']) pieces_model.pieces[data['frame']['id']] = data['pieces'] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'save': view_util.popup('Oh F**k', 'Your Peoplemon game save has been deleted') elif action['type'] == 'batch': if data['percent'] == 0: batch_controller.batch_shift(data['piece_id'], data['start_frame'], data['end_frame'], 0, -data['xpos'], -data['ypos'], -data['xscale'], -data['yscale'], -data['alpha'], -data['rot']) else: xs = (-data['xscale']) / (100 + data['xscale']) * 100 ys = (-data['yscale']) / (100 + data['yscale']) * 100 a = (-data['alpha']) / (100 + data['alpha']) * 100 r = (-data['rot']) / (100 + data['rot']) * 100 fl = (-data['frame_len']) / (100 + data['frame_len']) * 100 batch_controller.percent_shift(data['piece_id'], data['start_frame'], data['end_frame'], fl, xs, ys, a, r) elif action['type'] == 'interpolate': s = frames_model.get_frame_position(data['start_frame']) + 1 e = frames_model.get_frame_position(data['end_frame']) fids = [ frames_model.get_frame_from_pos(i)['id'] for i in range(s, e) ] for fid in fids: i = frames_model.get_frame_position(fid) if fid in pieces_model.pieces.keys(): del pieces_model.pieces[fid] del frames_model.frames[i] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'toggle_loop': frames_model.is_loop = not frames_model.is_loop frames_controller.update_view() model.current_action -= 1 controller.update_view()
def change_active_frame(): old = model.active_frame() model._active_frame = model.get_frame_from_pos( view_options.get_selected_index())['id'] pieces_controller.change_active_frame(old, model.active_frame()) update_view()