Scale using cos/sin

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_Xcos(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 !

1 Like

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

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;
}

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

:)

Thank you I will take it from here !

1 Like