Monday, November 3, 2014

Data, XML, and 2D Transformations

Data:

I reviewed the importing, exporting, writing and reading from files, which was similar to what we did in AP. Like Julia, I was very confused when I got to the XML part of it.

2D Transformations

I made a waddling penguin (code in comments for motion)








1 comment:

  1. int armAngle = 0;
    int angleChange = 5;
    final int ANGLE_LIMIT = 10;

    void setup()
    {
    size(200, 200);
    smooth();
    frameRate(30);
    }

    void draw()
    {
    background(255);
    pushMatrix();
    translate(50, 50); // place robot so arms are always on screen
    drawRobot();
    armAngle += angleChange;

    // if the arm has moved past its limit,
    // reverse direction and set within limits.
    if (armAngle > ANGLE_LIMIT || armAngle < 0)
    {
    angleChange = -angleChange;
    armAngle += angleChange;
    }
    popMatrix();
    }

    void drawRobot()
    {
    noStroke();
    fill(38, 38, 200);

    ellipse(33, -10, 38, 38); // head
    ellipse(33, 32, 50, 50); // body
    drawLeftArm();
    drawRightArm();
    }

    void drawLeftArm()
    {
    pushMatrix();
    translate(12, 32);
    rotate(radians(armAngle));
    ellipse(-12, 0, 15, 37); // left arm
    popMatrix();
    }

    void drawRightArm()
    {
    pushMatrix();
    translate(66, 32);
    rotate(radians(-armAngle));
    ellipse(0, 0, 15, 37); // right arm
    popMatrix();
    }

    ReplyDelete