How to make head wiggle?

Hi this is my code


void setup() {
    
size(200,250);
  
background(255);
smooth();
ellipseMode(CENTER);
rectMode(CENTER); 

  } 
  
  void draw() {
  background (255, 50,0); 
  body(); 
  head(); 
  float x = 0; 
 
  
  

  }
  
void body() {
stroke(0);
//body
fill(255);
ellipse(105,83,30,20);
ellipse(103,98,25,18);
ellipse(98,113,25,18);
ellipse(118,120,18,18);
ellipse(138,120,18,18);
ellipse(158,120,18,18);
ellipse(168,110,10,10);
//head
}
void  head(){
ellipse(100,60,60,30); 
ellipse(85,40,20,30);
ellipse(115,40,20,30);
fill (random (250), random (250) , random (250)); 
rect(93,60,5,5); // Left Eye
fill (random (250), random (250) , random (250)); 
rect(107,60,5,5); // Right Eye '
}

I want to make the head move back and forth across the body

Well, you should probably work with classes, inheritance and PVectors. That would make it much easier. Try reading further in Nature of Code. :slight_smile:

1 Like

In the future, please format your code. It makes it easier for us to read and understand your code, which can help us help you more quickly.

As for your actual question;

I’m going to ask you to be more specific. A lot more specific. Any sort of problem solving can be approached by breaking it into smaller, manageable pieces, and in this case, you might ask yourself:

  • How would I make a shape “move”?
  • What methods do I have at my disposal?
  • What does it mean to “wiggle”

Once you’ve really defined the type of behavior you want in more specific terms, it will be easier to look at your toolset and start working on a solution.

2 Likes