how to make a stickman's arms/legs move?

edited October 2013 in Questions about Code

Hi,

I am new to processing.

I have drawn the stickman, but i need help to make his arms and legs move when i move the mouse in different directions. The body and head should stay at the same place.

This is my code:

void setup() {
size (300,300);

}


void draw() {
ellipseMode (CENTER);
rectMode (CENTER);

//Head
ellipse (150,60,50,50);
point (140,60);
point (160,60);


//Body
rect (150,135,50,100);

//Arms
line (125,85,100,160);
line (175,85,200,160);

//Legs
line (130,185,130,250);
line (130,250,125,250);
line (170,185,170,250);
line (170,250,175,250);
}

Answers

  • You should at least use variables in place of hard numbers. So you can change its length & position!

  • Answer ✓
    void setup() {
      size (300, 300);
      ellipseMode (CENTER);
      rectMode (CENTER);
    }
    
    void draw() {
      background(100,100,255);
      //Head
      ellipse (150, 60, 50, 50);
      point (140, 60);
      point (160, 60);
      //Body
      rect (150, 135, 50, 100);
      //Arms
      pushMatrix();
      translate(125,85);
      rotate(map(mouseX,0,width,-PI,PI));
      line (0,0, -25, 75);
      popMatrix();
      pushMatrix();
      translate(175,85);
      rotate(map(mouseX,0,width,-PI,PI));
      line (0,0, 25, 75);
      popMatrix();  
      //Legs
      pushMatrix();
      translate(130,185);
      rotate(map(mouseY,0,height,-PI,PI));
      line (0,0, 0, 65);
      line (0,65, -5, 65);
      popMatrix();
      pushMatrix();
      translate(170,185);
      rotate(map(mouseY,0,height,-PI,PI));
      line (0,0,0,65);
      line (0,65,5,65);
      popMatrix();
    }
    
  • Answer ✓

    Sensational rotating arms & legs! <:-P
    Published to see it online too: http://studio.processingtogether.com/sp/pad/export/ro.9ozYNbweyOpjT/latest

  • Hi! I am having the same problem. I've been doing a couple tutorials, but it seems like i am doing something wrong here.

    I want my stickman to move his arms and legs when i move my mouse, could you guys help me out with it? I've tried to use the code thats been published in the thread, but i can't get it to work right.

    I got some datafiles for my stickman, background and music, so i wont post that. But it would be great if you guys could show me how to make the arms and legs move. i'll post the code below. Thanks.

    import ddf.minim.*;
    
    AudioPlayer avicii;
    Minim minim;//audio context
    
    PImage face;
    PImage bg;
    PImage suit;
    
    
    
    void setup() {
    
    size (800,768);
    face = loadImage("janbeib.png"); //Hode
    bg= loadImage ("bakgrunn.png"); //Disco
    suit = loadImage("suitfix.png"); //Suit
    
      minim = new Minim(this);
      avicii = minim.loadFile("discojan.mp3", 2048);
      avicii.play();
        avicii.loop();
    }
    
     void draw() {
    background (bg);
    ellipseMode (CENTER);
    
    image(face, 195, 205);
    point (140,60);
    point (160,60);
    
    rectMode (CENTER);
    image(suit, 180, 230);
    
    //rect (400,450,50,100); // X , Y , Bredde. Høyde
    
     strokeWeight(10);
    line (375,405,350,470); //left arm
    line (425,400,450,470); //right arm
    line (380,500,370,560); //left leg
    line (370,560,360,560); //left foot
    line (425,500,435,560); //right leg
    line (435,560,445,560); //right foot
     }
    
    
    
    void stop()
    {
      avicii.close();
      minim.stop();
      super.stop();
    }
    
  • Thank you TfGuy44!

    Just what i needed :)

  • "if you guys could show me how to make the arms and legs move"
    Since your code looks a lot like the one in the first message, you were already shown how to do it.

    "I've tried to use the code thats been published in the thread, but i can't get it to work right."
    Wow, that's precise problem report!
    What didn't "work right"?

  • never mind! I figured it out. Thanks anyways.

    I used this for left and right arm.

     pushMatrix();
     translate(375,405);
     rotate(map(mouseX,0,width,-PI,PI));
    line (0,0,50,50); //venstre arm
    popMatrix();
    
    pushMatrix();
    translate(425,400);
    rotate(map(mouseX,0,width,-PI,PI));
    line (0,0,50,50); //høyre arm
    popMatrix();
    
Sign In or Register to comment.