# Scale using cos/sin

**URL:** <https://discourse.processing.org/t/scale-using-cos-sin/30542>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [June 6, 2021, 9:51pm UTC](https://discourse.processing.org/t/scale-using-cos-sin/30542 "2021-06-06T21:51:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MacJ](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@MacJ](https://discourse.processing.org/u/MacJ)\
**Post date:** [June 6, 2021, 9:51pm UTC](https://discourse.processing.org/t/scale-using-cos-sin/30542/1 "2021-06-06T21:51:19Z")

</div>

Hello so below is my code of a simple planet orbiting the sun

final int SUN\_DIAM = 50;  
final int ORBIT\_X = 150;  
final int ORBIT\_Y = 35;  
final int PLANET\_DIAM = 25;  
final float SPEED = 0.03;  
float angle = 0;  
final int PLANET\_DIAM\_CHANGE = 10;

float xPos, yPos;  
void setup () {  
size(500, 500);  
}

void draw () {  
background(0);  
fill(255, 255, 0);  
circle(width/2, height/2, SUN\_DIAM);

xPos= (width/2)+ORBIT\_X_cos(angle);  
yPos= (height/2)+ORBIT\_Y_sin(angle);

fill(120);  
circle(xPos, yPos, PLANET\_DIAM);

angle = angle + SPEED;  
}  
So now I want to make the diameter of the planet change, depending on angle using a sin or cos function. Thank you !

---

<div class="post-metadata">

**Author:** ![mcintyre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mcintyre/32/14561_2.png) [@mcintyre](https://discourse.processing.org/u/mcintyre)\
**Post date:** [June 7, 2021, 1:28am UTC](https://discourse.processing.org/t/scale-using-cos-sin/30542/2 "2021-06-07T01:28:23Z")

</div>

Cool project! Here are a few tweaks that might get you started.

```java
final int SUN_DIAM = 50;
final int ORBIT_X = 150;
final int ORBIT_Y = 35;
final float SPEED = 0.03;
float angle = 0;
float planetDiam = 25;
float xPos, yPos;

void setup () {
  size(500, 500);
}

void draw () {
  background(0);
  fill(255, 255, 0);
  circle(width/2, height/2, SUN_DIAM);

  xPos = ORBIT_X * cos(angle) + width/2;
  yPos = ORBIT_Y * sin(angle) + height/2;

  fill(120);
  circle(xPos, yPos, planetDiam);

  angle = angle + SPEED;
  planetDiam = 10 * cos(angle) + 15;
}

```

---

<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:** [June 7, 2021, 1:30am UTC](https://discourse.processing.org/t/scale-using-cos-sin/30542/3 "2021-06-07T01:30:21Z")

</div>

Hello,

Please format your code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

`:)`

---

<div class="post-metadata">

**Author:** ![MacJ](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@MacJ](https://discourse.processing.org/u/MacJ)\
**Post date:** [June 7, 2021, 1:51am UTC](https://discourse.processing.org/t/scale-using-cos-sin/30542/4 "2021-06-07T01:51:13Z")

</div>

Thank you I will take it from here !
