#! python # # $Id$ import sys sys.path.append("./py-svg") import svgscene from svgscene import point class actor: _width = 80 _depth = 48 def __init__(self, boyOrGirl, x, y, angle, inscene): self._x = x self._y = y self._angle = angle self.stored_handpos = {} self.name = boyOrGirl if boyOrGirl == "boy": self._isGirl = False self._class = "boy" else: self._isGirl = True self._class = "girl" self.scene = inscene def center(self): return point(self._x, self._y) def point(self, id): pt = self.pointrel(id).rotateorigin(self._angle).translate(self._x, self._y) pt.name = self.name + " " + id return pt def pointrel(self, id): if id == "center": return point(0, 0) elif id == "L shoulder": return point(self._width/2 - 2, 0).setzstyle("shoulder") elif id == "R shoulder": return point( - self._width/2 + 2, 0).setzstyle("shoulder") elif id == "L hip": newpoint = point(self._width/2 - 2, 0) newpoint.zstyle = "L hip" newpoint.fwangle += 180 return newpoint elif id == "R hip": return point( - self._width/2 + 2, 0).setzstyle("R hip") elif id == "mid-lower back": newpoint = point(0, -self._depth/2 + 2) newpoint.zstyle = "lower back" newpoint.fwangle += 90 return newpoint elif id == "L arm": return point(self._width/2 - 2, 0) elif id == "R arm": return point( - self._width/2 + 2, 0) elif id == "ribcage": return point(0, - self._depth / 2 + 2) elif id == "L outward": return point(self._width, self._depth) elif id == "R outward": return point(- self._width, self._depth) elif id == "L in front": return point(self._width / 2, self._depth) elif id == "R in front": return point(- self._width / 2, self._depth) elif id == "L neutral": return point(self._width / 2, self._depth / 2) elif id == "R neutral": return point(- self._width / 2, self._depth / 2) def pointloc(self, point): pt = point.rotateorigin(self._angle).translate(self._x, self._y) pt.name = self.name + " (by coordinates)" return pt def armto(self, origid, dest): orig = self.point(origid + " arm") if dest.zstyle == "L hip" or dest.zstyle == "R hip" or dest.zstyle == "lower back": self.drawlowhand(dest) self.scene.line(x1 = orig.x, y1 = orig.y, x2 = dest.x, y2 = dest.y, css = (self._class + ' arm')) if dest.zstyle == "shoulder": self.drawhand(dest) self.scene.addinfo(self.name + ": " + orig.name + " to " + dest.name) dest.name = self.name + " " + origid + " hand [" + dest.name + "]" self.stored_handpos[origid] = dest def drawhand(self, at): self.scene.circle(at.x, at.y, 7, self._class) def drawlowhand(self, at): self.scene.drawsymbol("lowhand", at, 14, 14, at.fwangle, self._class) def handpos(self, hand): dest = self.stored_handpos[hand].clone() # if we're copying another hand, don't # draw this one. dest.zstyle = None return dest def draw(self): x = self._x y = self._y if self._isGirl: symbol = "girl" else: symbol = "boy" self.scene.drawsymbol(symbol, point(self._x, self._y), self._width, self._depth, self._angle, self._class) def fileheader(filetitle): print """
$Id$
""" def filefooter(): print """ """ def main(): fileheader("working diagrams") inscene = svgscene.scene("working") boy = actor("boy", 40, 80, 250, inscene) boy.draw() girl = actor("girl", 120, 80, 135, inscene) girl.draw() boy.armto("R", girl.pointloc(point(85, -5))) boy.armto("L", girl.point("L hip")) girl.armto("R", boy.handpos("L")) girl.armto("L", boy.handpos("R")) inscene.end() filefooter() main()