1 /* sticfigure drawings in asymptote.
3 * Copyright (C) 2008-2009 W. Trevor King <wking@drexel.edu>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 real torsoHeightRatio;
26 real shoulderHeightRatio;
32 void operator init(pair standsOn=(0,0), real height=10mm) {
33 this.center = standsOn+(0,height/2);
35 this.headHeightRatio = 0.2;
36 this.neckHeightRatio = 0.1;
37 this.torsoHeightRatio = 0.28;
38 this.shoulderHeightRatio = 0.1;
39 this.armTorsoRatio = 1.2;
41 this.outline = currentpen;
42 this.fill = currentpen;
46 return this.center + (0,this.height/2);
50 return this.crownPos() - (0,this.height*this.headHeightRatio);
54 return (this.crownPos() + this.chinPos())/2;
58 return this.chinPos() - (0,this.height*this.neckHeightRatio);
61 pair shoulderPos(bool rightSide=true) {
63 if (rightSide == false)
65 return this.neckBasePos() + (sign*this.height*this.shoulderHeightRatio/2,0);
68 pair handPos(bool rightSide=true) {
69 pair dArm = this.height*this.torsoHeightRatio*this.armTorsoRatio * dir(armAngle);
70 if (rightSide == false)
71 dArm = (-dArm.x, dArm.y);
72 return this.shoulderPos(rightSide=rightSide) + dArm;
76 return this.neckBasePos() - (0,this.height*this.torsoHeightRatio);
79 pair footPos(bool rightSide=true) {
80 real legHeightRatio = 1.0 - this.headHeightRatio - this.neckHeightRatio - torsoHeightRatio;
81 pair dLeg = (this.height*this.shoulderHeightRatio/2, -this.height*legHeightRatio);
82 if (rightSide == false)
83 dLeg = (-dLeg.x, dLeg.y);
84 return this.tailPos() + dLeg;
87 void draw(picture pic=currentpicture) {
90 *scale(this.height*this.headHeightRatio/2)
96 path armsAndShoulders =
97 this.handPos(rightSide=true)
98 --this.shoulderPos(rightSide=true)
99 --this.shoulderPos(rightSide=false)
100 --this.handPos(rightSide=false);
102 this.footPos(rightSide=true)
104 --this.footPos(rightSide=false);
105 draw(pic, armsAndShoulders, outline);
106 draw(pic, legs, outline);
107 draw(pic, neckAndTorso, outline);
108 filldraw(pic, head, fill, outline);