# How can I rotate all of this

**URL:** <https://discourse.processing.org/t/how-can-i-rotate-all-of-this/40015>\
**Category:** Coding Questions\
**Created:** [December 3, 2022, 10:22pm UTC](https://discourse.processing.org/t/how-can-i-rotate-all-of-this/40015 "2022-12-03T22:22:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![returng](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@returng](https://discourse.processing.org/u/returng)\
**Post date:** [December 3, 2022, 10:22pm UTC](https://discourse.processing.org/t/how-can-i-rotate-all-of-this/40015/1 "2022-12-03T22:22:25Z")

</div>

I want to rotate my snowflake with mouseX, here is the full code;

```auto
float angle = 0;
float cx;
float cy;
 
void setup() {
  size(640, 480);
  cx = 50;
  cy = height/2;
  noLoop();
  
}
 
void draw() {
  background(255);
  stroke(0);
  //kochCurve(243,4);
  translate(100,-100);
  kochSnowflake(360,4);
  
}

void kochCurve(float lngth, int level) {
  float newlngth;
  if (level == 0){
    forward(lngth);
    return;
  }
  else {
    newlngth = lngth/3.0;
    kochCurve(newlngth,level-1);
    rotation(-60);
    kochCurve(newlngth,level-1);
    rotation(120);
    kochCurve(newlngth,level-1);
    rotation(-60);
    kochCurve(newlngth,level-1); 
  }
}

void forward(float amount) {
  float newX = cx + cos(radians(angle)) * amount;
  float newY = cy + sin(radians(angle)) * amount;
 
  line(cx, cy, newX, newY);
  
  fill(0); 
  cx = newX;
  cy = newY;
}
 
void rotation(float degree) {
  angle = (angle + degree);
}

void kochSnowflake(float lngth, int level) {
  kochCurve(lngth,level); 
  rotation(120);
  kochCurve(lngth,level);
  rotation(120);
  kochCurve(lngth,level); 
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 3, 2022, 10:57pm UTC](https://discourse.processing.org/t/how-can-i-rotate-all-of-this/40015/2 "2022-12-03T22:57:25Z")

</div>

Hello,

You will have to remove the `noLoop()`.

An example of rotating that you can integrate with your code:

```auto
angle = 0; // Sets your snowflake angle to 0
translate(width/2, height/2); // Try with and without this to see what it does.
float angle2 = frameCount*(TAU/360);
rotate(angle2);
translate(-200, -300);

```

Not perfect… you can sort out the exact values.

Now try it with `mouseX` and `map()`.  
You must map mouseX to an angle.  
You will need to read the references for this.

Please format your code as a courtesy to our community:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/4/1462a0f0fe1f63a001ee0610181c9a6359dfacc7.png)

`:)`
