Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit ea0aa2d9b74f2284d55e2fc0c8151a66091473cc Greg Borenstein committed Nov 18, 2011
Showing with 128 additions and 0 deletions.
  1. +69 −0 LegFrame.pde
  2. +59 −0 leg_animation.pde
69 LegFrame.pde
@@ -0,0 +1,69 @@
+class LegFrame {
+ PVector baseRibCage;
+ PVector rightHip;
+ PVector rightKnee;
+ PVector rightFibula;
+ PVector rightAnkle;
+ PVector rightHeel;
+ PVector rightMetatarsal;
+
+ float time;
+
+ int radius;
+
+ LegFrame(String csvLine) {
+ String[] positions = csvLine.split(",");
+
+ baseRibCage = new PVector(float(positions[2]), float(positions[3]));
+ rightHip = new PVector(float(positions[4]), float(positions[5]));
+ rightKnee = new PVector(float(positions[6]), float(positions[7]));
+ rightFibula = new PVector(float(positions[8]), float(positions[9]));
+ rightAnkle = new PVector(float(positions[10]), float(positions[11]));
+ rightHeel = new PVector(float(positions[12]), float(positions[13]));
+ rightMetatarsal = new PVector(float(positions[14]), float(positions[15]));
+
+ radius = 3;
+ }
+
+ void drawJoint(PVector joint, String jointName) {
+ drawJoint(joint, jointName, 0, 0);
+ }
+
+ void drawJoint(PVector joint, String jointName, int offsetX, int offsetY) {
+ ellipse(joint.x, joint.y, radius, radius);
+ if (drawText) {
+ textSize(7);
+
+ pushMatrix();
+ translate(joint.x, joint.y);
+ rotate(radians(180));
+ translate(-1 * joint.x, -1 * joint.y);
+ text(jointName, joint.x + offsetX + 5, joint.y + offsetY);
+ popMatrix();
+ }
+ }
+
+ void draw() {
+
+ drawJoint(baseRibCage, "Base Rib Cage");
+ line(baseRibCage.x, baseRibCage.y, rightHip.x, rightHip.y);
+
+ drawJoint(rightHip, "Right Hip");
+ line(rightHip.x, rightHip.y, rightKnee.x, rightKnee.y);
+
+ drawJoint(rightKnee, "Right Knee");
+ line(rightKnee.x, rightKnee.y, rightFibula.x, rightFibula.y);
+
+ drawJoint(rightFibula, "Right Fibula");
+ line(rightFibula.x, rightFibula.y, rightAnkle.x, rightAnkle.y);
+
+ drawJoint(rightAnkle, "Right Ankle", 0, -5);
+ line(rightAnkle.x, rightAnkle.y, rightHeel.x, rightHeel.y);
+
+ drawJoint(rightHeel, "Right Heel", 0, 5);
+ line(rightHeel.x, rightHeel.y, rightMetatarsal.x, rightMetatarsal.y);
+
+ drawJoint(rightMetatarsal, "Right Metatarsal", -65, 3);
+ }
+}
+
59 leg_animation.pde
@@ -0,0 +1,59 @@
+import javax.swing.JFileChooser;
+
+ArrayList<LegFrame> frames;
+
+boolean loaded = false;
+
+JFileChooser chooser = new JFileChooser();
+
+int currentFrame = 0;
+
+boolean drawText = true;
+
+void setup() {
+
+ size(800, 400);
+ frameRate(70);
+ frames = new ArrayList();
+ smooth();
+}
+
+void draw() {
+ background(255);
+ fill(0);
+ textSize(10);
+ text("frameRate: " + int(frameRate), 5, 10);
+ if (loaded) {
+ translate(width - 50, height - 50);
+ rotate(radians(180));
+ scale(2);
+ frames.get(currentFrame).draw();
+ currentFrame++;
+ if (currentFrame >= frames.size()) {
+ currentFrame = 0;
+ }
+ }
+}
+
+void mousePressed(){
+ drawText = !drawText;
+}
+
+
+void keyReleased() {
+ if (!loaded) {
+
+ chooser.setFileFilter(chooser.getAcceptAllFileFilter());
+ int returnVal = chooser.showOpenDialog(null);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ println("inside");
+ String[] lines = loadStrings(chooser.getSelectedFile().getAbsolutePath());
+ for (int i = 2; i < lines.length; i++) {
+ frames.add(new LegFrame(lines[i]));
+ }
+
+ loaded = true;
+ }
+ }
+}
+

0 comments on commit ea0aa2d

Please sign in to comment.
Something went wrong with that request. Please try again.