Hi there, I don’t know if there’s a way to do this but I have a rect() function in my code and I want to know if it’s possible to group the line of code as a variable to make it all move at once. Read more at the bottom;
Here is the code:
// Mouth Variables
int x = 190; // Mouth move
int dx = 1; // Mouth move
// Body Variables
// Arm Variables
int ax =180;
int ax1 = 1;
int ax2 = 270;
int ax21 = 1;
void setup () {
size (400, 400);
ellipseMode(CENTER);
rectMode(CENTER);
smooth();
}
void draw () {
background (25, 86, 219);
textSize (32);
text ("A Shaky Robot", 10, 30);
// Arms
line (180, 270, 60, 270); // Left Arm
ax = ax + ax1;
ax = +1;
line (360, 270, 60, 270); // Right Arm
// Legs
line (160, 300, 160, 360);
line (237, 300, 237, 360);
// Body
rect (200, 250, 120, 120);
// Head
strokeWeight (3);
stroke (0);
fill (89, 16, 98);
rect (200, 150, 200, 120);
// Eyes
strokeWeight (3);
stroke (0);
fill (92, 151, 198);
rect (150, 140, 40, 40); // Left Eye
rect (250, 140, 40, 40); // Right Eye
rect (150, 140, 20, 20);
rect (250, 140, 20, 20);
// Mouth
rect (200, x, 20, 20); // Mouth
x = x + dx;
if (x > 190)
dx = - 1;
if (x < 185)
dx = 1;
}
If you go down to the // Body section, the coordinates of the rect() function is what I want to change simultaneously, so that as one line of code I can make it move left and return right and then move right and return left.