# How to animate a square with circular movement, varying rotation and scale

**URL:** <https://discourse.processing.org/t/how-to-animate-a-square-with-circular-movement-varying-rotation-and-scale/39733>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 15, 2022, 6:21pm UTC](https://discourse.processing.org/t/how-to-animate-a-square-with-circular-movement-varying-rotation-and-scale/39733 "2022-11-15T18:21:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerardo\_DiazL](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Gerardo\_DiazL](https://discourse.processing.org/u/Gerardo_DiazL)\
**Post date:** [November 15, 2022, 6:21pm UTC](https://discourse.processing.org/t/how-to-animate-a-square-with-circular-movement-varying-rotation-and-scale/39733/1 "2022-11-15T18:21:11Z")

</div>

//ciclo de vida se translada a processing  
float rotate=0;  
void setup(){  
size(800,800,P3D);  
stroke(255);  
noFill();  
}

void draw(){  
//Limpiar el cuadro anterior de dibujo  
background(0);  
//identity  
float tx=width/2;  
float ty=height/2;  
float tz=0;

//TRANSLATION  
PMatrix3D translation= new PMatrix3D(1,0,0,tx,  
0,1,0,ty,  
0,0,1,tz,  
0,0,0,1);

//SCALE  
float sx=3;  
float sy=3;  
float sz=3;  
PMatrix3D scale= new PMatrix3D(sx,0,0,0,  
0,sy,0,0,  
0,0,sz,0,  
0,0,0,1);  
//Rotar en z  
rotate=rotate - 1;  
float angle=radians(20 + rotate);  
PMatrix3D rotateZ= new PMatrix3D(sin(angle), cos(angle), 0, 0,  
cos(angle), -sin(angle), 0, 0,  
0, 0, 1, 0,  
0, 0, 0, 1);  
// Moverse en circulo

```
     //aqui es cuando ya afecta

```

applyMatrix(translation);  
applyMatrix(scale);  
applyMatrix(rotateZ);  
//DIBUJO DIRECTO (YA NO EXISTE EN VERSIONES RECIENTES DE OPENGL)  
beginShape();  
vertex(-50,-50);  
vertex(50,-50);  
vertex(50,50);  
vertex(-50,50);

endShape(CLOSE);  
}

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [November 17, 2022, 11:09am UTC](https://discourse.processing.org/t/how-to-animate-a-square-with-circular-movement-varying-rotation-and-scale/39733/2 "2022-11-17T11:09:17Z")

</div>

Hi @Gerardo_DiazL,

Welcome to the forum! 😉

Please do the following before we can answer:

- Your post title should be short and straight to the point, post the content of your question in the post itself. (I renamed it)

- Format your code as described here:

- Describe what doesn’t work with your current code and what you want to do in the end.
