How move the penguin without the arms flying off?

‘’‘processing’‘’
//position
float xorigin, yorigin;
//origin position
float xPos, yPos;
//penguin position
//wing animation
float wingangle;
float wingspeed;
float upperwinglimit;
float lowerwinglimit;
boolean winglimitBO;
void setup() {
//varibles

//position
xPos = 0;
yPos = 0;
xorigin = 400;
yorigin = 400;

//Wings
wingangle = PI/16;
upperwinglimit=PI/12;
lowerwinglimit=PI/20;
wingspeed = PI/4096;
size(800,800);
void draw() {

//setup
translate(xorigin,yorigin);
.
pushMatrix();
rotate(wingangle);
ellipse(xPos-90,yPos+120,40,180); // wing left
popMatrix();

pushMatrix();
rotate(-wingangle);
ellipse(xPos+90,yPos+120,40,180); // wing right
popMatrix();
.
if (wingangle>upperwinglimit) {
winglimitBO = false;
}

if (winglimitBO) {
wingangle = wingangle + wingspeed;
}
if (winglimitBO == false) {
wingangle = wingangle - wingspeed;
}

if (wingangle<lowerwinglimit) {
winglimitBO = true;
}

This isn’t the full code but it is all the code relating to the position/angle of the wings the wings flap up and down like they are meant to when stationary but if you change the X position of the penguin through something such as xPos += 1; then the wings will start moving up and down without any change to the Y axis being made and I cant figure out why. I was wondering if there is an error or a way to fix this?

1 Like

Maybe the position of the wings should not be calculated based on (xPos, yPos) which must be I think the position of the total image. Thus, it would be enough to change the position of the whole by a translate(xPos,yPos) before drawing everything including the wings.

2 Likes

in your version:

since you use translate(xorigin,yorigin); the Pinguin is at pos xorigin,yorigin.

xpos and ypos can stay 0, it’s not in use because you use translate.

To move the pinguin, change xorigin,yorigin.

here is my version





// position Pinguin
float xPinguin, yPinguin;

// position / NOT IN USE / always == 0
float xPos, yPos;

//wing animation
float wingangle;
float wingspeed;
float upperwinglimit;
float lowerwinglimit;

boolean winglimitBO;

// -------------------------------------------------------------------------------

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

  //position
  xPos = 0;
  yPos = 0;
  xPinguin = 2;
  yPinguin = 400-322;

  //Wings
  wingangle = PI/16;
  upperwinglimit=PI/12*2;
  lowerwinglimit=PI/20;
  wingspeed = PI/4096*3;

  background (111);
}

void draw() {
  background (111);

  // -----------------------------
  // move entire Pinguin
  xPinguin++;

  // -----------------------------
  // display Pinguin
  translate(xPinguin, yPinguin);

  pushMatrix();
  rotate(wingangle);
  ellipse(xPos-90, yPos+120, 40, 180); // wing left
  popMatrix();

  pushMatrix();
  rotate(-wingangle);
  ellipse(xPos+90, yPos+120, 40, 180); // wing right
  popMatrix();

  // -----------------------------
  // move Wings

  if (wingangle>upperwinglimit) {
    winglimitBO = false;
  }

  if (winglimitBO) {
    wingangle = wingangle + wingspeed;
  } else if (! winglimitBO) { // FALSE
    wingangle = wingangle - wingspeed;
  }

  if (wingangle<lowerwinglimit) {
    winglimitBO = true;
  }
}
//