# Making 3D planets

**URL:** <https://discourse.processing.org/t/making-3d-planets/6136>\
**Category:** Coding Questions\
**Created:** [December 1, 2018, 7:26am UTC](https://discourse.processing.org/t/making-3d-planets/6136 "2018-12-01T07:26:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerdboybi](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@nerdboybi](https://discourse.processing.org/u/nerdboybi)\
**Post date:** [December 1, 2018, 7:26am UTC](https://discourse.processing.org/t/making-3d-planets/6136/1 "2018-12-01T07:26:35Z")

</div>

Hello, so I have made this program where my planet rotates around the sun.

```auto
final int SUN_SIZE=50;

final int planetSize=SUN_SIZE/2;
final int X_RADIUS=150;
final int Y_RADIUS=35;
float angle=0;
final float SPEED=0.03;

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

void draw()
{
  background(0);
    
  fill(255,255,0);
 ellipse(width/2,height/2,SUN_SIZE,SUN_SIZE);
 fill(200);
 
 ellipse(width/2+X_RADIUS*cos(angle),height/2+Y_RADIUS*sin(angle),planetSize,planetSize);
 angle+=SPEED;
 
}
 

```

**What I now need to do is to make the diameter of the planet change, depending on angle, using a sin or cos function. If the planet is straight down from the sun, the diameter of the planet should be increased by 10. If the planet is straight up from the sun, decrease its diameter by 10. It should grow and shrink smoothly as it goes around its orbit.**

I know I can use the if condition but I want to do without it. Is there any way to do the above?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 1, 2018, 7:30am UTC](https://discourse.processing.org/t/making-3d-planets/6136/2 "2018-12-01T07:30:22Z")

</div>

i think you should do it in real 3D…  
not try to emulate 3D in 2D by fake size.  
also see

> [@3D solar system simulator](https://discourse.processing.org/t/3d-solar-system-simulator/5478/2):
>
> very good, would like to learn from you to improve my show [http://kll.engineering-news.org/kllfusion01/articles.php?article\_id=154#here8](http://kll.engineering-news.org/kllfusion01/articles.php?article_id=154#here8) of the objects/planets, also i still have problems with the orbits absolute angles ( that is why i come here to the forum in the first place ) and initial settings (1.1.2000), the kepler elliptic orbits work. [snap-083] ( this one does not use a library, views , orbits, operation ( mouse and buttons ) are coded beginner style // difficult to read ) c…

---

<div class="post-metadata">

**Author:** ![nerdboybi](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@nerdboybi](https://discourse.processing.org/u/nerdboybi)\
**Post date:** [December 1, 2018, 7:32am UTC](https://discourse.processing.org/t/making-3d-planets/6136/3 "2018-12-01T07:32:19Z")

</div>

Soon, This is just a small Lab exercise for my class and I am stuck here

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 1, 2018, 7:40am UTC](https://discourse.processing.org/t/making-3d-planets/6136/4 "2018-12-01T07:40:07Z")

</div>

the 2 sphere version ( but with my PTZ )  
just delete what you not need

> **[TWO\_SPHERE - OpenProcessing](https://www.openprocessing.org/sketch/613920)**
>
> earth moon

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 1, 2018, 9:48am UTC](https://discourse.processing.org/t/making-3d-planets/6136/5 "2018-12-01T09:48:56Z")

</div>

but here a small rev of your code:

```auto
  float zplanetSize = planetSize* (2 + sin(angle));
  ellipse(width/2+X_RADIUS*cos(angle), height/2+Y_RADIUS*sin(angle), zplanetSize, zplanetSize);

```

---

<div class="post-metadata">

**Author:** ![nerdboybi](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@nerdboybi](https://discourse.processing.org/u/nerdboybi)\
**Post date:** [December 1, 2018, 11:42pm UTC](https://discourse.processing.org/t/making-3d-planets/6136/6 "2018-12-01T23:42:40Z")

</div>

This code doesnt work the way i want it to work

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 2, 2018, 1:42am UTC](https://discourse.processing.org/t/making-3d-planets/6136/7 "2018-12-02T01:42:03Z")

</div>

> [@nerdboybi](#):
>
> This code

What code? You should put your current code in every post so we know which code you are talking about.

> [@nerdboybi](#):
>
> doesnt work the way i want it to work

What is it doing wrong? How do you want it to work? Keep in mind that I am BRAND NEW to this discussion, and so if you make it SUPER EASY for me to read your last post, see the code, and know what the remaining problems are, I can jump right in and help. But you haven’t made it easy for me, so now to help I would have to read the entire discussion so far.

And that’s not fun for me. Try telling which code you mean and what is wrong in a concise, current post, and maybe you will get more helpful replies.
