# Rotate sun keyPressed

**URL:** <https://discourse.processing.org/t/rotate-sun-keypressed/18429>\
**Category:** Coding Questions\
**Created:** [March 5, 2020, 9:53pm UTC](https://discourse.processing.org/t/rotate-sun-keypressed/18429 "2020-03-05T21:53:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![M.juliet](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@M.juliet](https://discourse.processing.org/u/M.juliet)\
**Post date:** [March 5, 2020, 9:53pm UTC](https://discourse.processing.org/t/rotate-sun-keypressed/18429/1 "2020-03-05T21:53:33Z")

</div>

Hi, I’m writing some code for a animation project and I want to let ellipses move around a sun. I have four ellipses that move four times around the sun and I want to let them move around when you press the up or the down key. With the code I have right now, I’m not only moving the ellipses around the sun but the whole city. (There might be some dutch words in my code that I used as comments or as function names).

 ![2020-03-05 (28)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/852cda00c9bdb4b4fc043e3e06196c8bac203611.png)

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [March 5, 2020, 10:24pm UTC](https://discourse.processing.org/t/rotate-sun-keypressed/18429/2 "2020-03-05T22:24:17Z")

</div>

Hoi. Gebruik [dit.](https://processing.org/reference/translate_.html) en [dit](https://processing.org/reference/rotate_.html) en [dit](https://processing.org/reference/push_.html).

---

<div class="post-metadata">

**Author:** ![Dr.Dremur](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dr.dremur/32/8266_2.png) [@Dr.Dremur](https://discourse.processing.org/u/Dr.Dremur)\
**Post date:** [March 6, 2020, 2:46am UTC](https://discourse.processing.org/t/rotate-sun-keypressed/18429/3 "2020-03-06T02:46:59Z")

</div>

[[https://processing.org/reference/ellipseMode\_.html](https://processing.org/reference/ellipseMode_.html)]  
[[https://processing.org/reference/pushMatrix\_.html](https://processing.org/reference/pushMatrix_.html)]

```auto
void draw(){
  background(255);
  pushMatrix();
  translate(width/2, height/2);
  ellipseMode(CENTER);
  rotate(radians(angle)); 
  roundSun();
  popMatrix(); 
  fill(#FFF7AF);
ellipse (30, 30, 100, 100);
}

void keyPressed(){
  if(keyCode == UP){ 
    angle--; 
  } else if(keyCode == DOWN){ 
    angle++; 
  }
}

```

Push, Pop helps when you want to move alot at once, kinda like grouping shapes together. I did end up placing the main sun body in the draw and kept the rays with the void draw, so just the rays rotate around the main ellipse when pressing the button.

See if this helps, hope I read the question correctly  
😁

---

<div class="post-metadata">

**Author:** ![M.juliet](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@M.juliet](https://discourse.processing.org/u/M.juliet)\
**Post date:** [March 6, 2020, 7:49am UTC](https://discourse.processing.org/t/rotate-sun-keypressed/18429/4 "2020-03-06T07:49:47Z")

</div>

Yes, thank you soo much!!  
I had to change a few things but I finally managed to only rotate the rays of the sun.  
Again, thanks for your help 🙂
