diff options
Diffstat (limited to 'model.py')
-rw-r--r-- | model.py | 53 |
1 files changed, 36 insertions, 17 deletions
@@ -17,7 +17,7 @@ import kinematic class KeyFrame: def __init__(self): - self.clear() + pass def empty(self): return self.joints == None @@ -26,13 +26,7 @@ class KeyFrame: self.middle = x.middle self.parts = x.parts.copy() self.sticks = x.sticks.copy() - self.scaled_sticks = x.sticks.copy() self.joints = x.joints.copy() - self.scaled_joints = initjoints() - - scalesticks(self.scaled_sticks, .2) - setjoints(self.scaled_joints, self.scaled_sticks, - (self.x, int(theme.KEYFRAMEHEIGHT/2.0))) def clear(self): self.parts = None @@ -41,28 +35,46 @@ class KeyFrame: self.joints = None self.scaled_joints = None +class StoredKeyFrame(KeyFrame): + def __init__(self): + KeyFrame.__init__(self) + self.clear() + + def assign(self, x): + KeyFrame.assign(self, x) + self.scaled_sticks = x.sticks.copy() + self.scaled_joints = _initjoints() + _scalesticks(self.scaled_sticks, .2) + _setjoints(self.scaled_joints, self.scaled_sticks, + (self.x, int(theme.KEYFRAMEHEIGHT/2.0))) + +class CurrentKeyFrame(KeyFrame): + def __init__(self): + KeyFrame.__init__(self) + self.parts = theme.PARTS.copy() + self.sticks = theme.STICKS.copy() + self.joints = _initjoints() + self.middle = (int(theme.DRAWWIDTH/2.0), int(theme.DRAWHEIGHT/2.0)) + + def assign(self, x): + KeyFrame.assign(self, x) + _setjoints(self.joints, self.sticks, self.middle) + keys = [] for i in range(5): - key = KeyFrame() + key = StoredKeyFrame() keyframe_width = theme.KEYFRAMEWIDTH/5 key.x = keyframe_width/2 + i*keyframe_width keys.append(key) -def initjoints(): - joints = {} - for stickname in theme.JOINTS: - jname = theme.JOINTS[stickname] - joints[jname] = (0,0) - return joints - -def scalesticks(stickdict, i): +def _scalesticks(stickdict, i): for key in stickdict: (angle,len) = stickdict[key] newlen = int(len * i) stickdict[key] = (angle,newlen) -def setjoints(joints, sticks, middle): +def _setjoints(joints, sticks, middle): # have to traverse in order because # parent joints must be set right for stickname in theme.STICKLIST: @@ -76,3 +88,10 @@ def setjoints(joints, sticks, middle): panglesum += pangle (nx,ny) = kinematic.getpoints(x,y,angle+panglesum,len) joints[jname] = (nx,ny) + +def _initjoints(): + joints = {} + for stickname in theme.JOINTS: + jname = theme.JOINTS[stickname] + joints[jname] = (0,0) + return joints |