Trying to do an animation, how can I make the mushroom go from closed to open?

pls repair above code posting,

  • by using in processing IDE [ctrl][t]
  • and here at the forum editor use for code the
</> code tag

so it might look like

void setup() {
  size(500, 500);
}

void draw() {
  my_background();
  my_mushroom();
}

void my_background() {            //BACKGROUND GRADIENT START
  int r=0, g=0, b=0;
  for (int i = 0; i< height; i++) {
    stroke(r, i, b);
    line(0, i, width, i);
  }
}                                  //BACKGROUND GRADIENT END

void my_mushroom() {
  fill(#4d3300);            //dirt floor
  rect(-1, 360, 500, 500);
  fill(#ffffe6);            //mushroom stalk
  noStroke();
  rect(225, 120, 50, 330);
  ellipse(250, 450, 50, 10);
  fill(#c2c2a3);             //mushroom head
  bezier(180, 270, 210, -50, 290, -50, 320, 270);
}



ok to your question,
the head of the mushroom is your

bezier(180,270,210,-50,290,-50,320,270);

if you know already that the idea is to make that variable,
how you can draw that hard coded?
a very variable version would use

int mx, my, mw, mh;

like for the outer rectangle of the head.
after you have that running we talk about the animation.

? is it your idea to use
https://processing.org/reference/bezier_.html
for the head?

1 Like