struct StickFigure { pair center; real height; real headHeightRatio; real neckHeightRatio; real torsoHeightRatio; real shoulderHeightRatio; real armTorsoRatio; real armAngle; pen outline; pen fill; void operator init(pair standsOn=(0,0), real height=10mm) { this.center = standsOn+(0,height/2); this.height = height; this.headHeightRatio = 0.2; this.neckHeightRatio = 0.1; this.torsoHeightRatio = 0.28; this.shoulderHeightRatio = 0.1; this.armTorsoRatio = 1.2; this.armAngle = -70; this.outline = currentpen; this.fill = currentpen; } pair crownPos() { return this.center + (0,this.height/2); } pair chinPos() { return this.crownPos() - (0,this.height*this.headHeightRatio); } pair headPos() { return (this.crownPos() + this.chinPos())/2; } pair neckBasePos() { return this.chinPos() - (0,this.height*this.neckHeightRatio); } pair shoulderPos(bool rightSide=true) { real sign = 1; if (rightSide == false) sign = -1; return this.neckBasePos() + (sign*this.height*this.shoulderHeightRatio/2,0); } pair handPos(bool rightSide=true) { pair dArm = this.height*this.torsoHeightRatio*this.armTorsoRatio * dir(armAngle); if (rightSide == false) dArm = (-dArm.x, dArm.y); return this.shoulderPos(rightSide=rightSide) + dArm; } pair tailPos() { return this.neckBasePos() - (0,this.height*this.torsoHeightRatio); } pair footPos(bool rightSide=true) { real legHeightRatio = 1.0 - this.headHeightRatio - this.neckHeightRatio - torsoHeightRatio; pair dLeg = (this.height*this.shoulderHeightRatio/2, -this.height*legHeightRatio); if (rightSide == false) dLeg = (-dLeg.x, dLeg.y); return this.tailPos() + dLeg; } void draw(picture pic=currentpicture) { path head = shift(this.headPos()) *scale(this.height*this.headHeightRatio/2) *unitcircle; path neckAndTorso = this.chinPos() --this.neckBasePos() --this.tailPos(); path armsAndShoulders = this.handPos(rightSide=true) --this.shoulderPos(rightSide=true) --this.shoulderPos(rightSide=false) --this.handPos(rightSide=false); path legs = this.footPos(rightSide=true) --this.tailPos() --this.footPos(rightSide=false); draw(pic, armsAndShoulders, outline); draw(pic, legs, outline); draw(pic, neckAndTorso, outline); filldraw(pic, head, fill, outline); } }