# Light emitting outwards from a sphere

**URL:** <https://discourse.processing.org/t/light-emitting-outwards-from-a-sphere/16904>\
**Category:** Coding Questions\
**Created:** [January 6, 2020, 4:01pm UTC](https://discourse.processing.org/t/light-emitting-outwards-from-a-sphere/16904 "2020-01-06T16:01:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olsxn](https://avatars.discourse-cdn.com/v4/letter/o/ee7513/32.png) [@olsxn](https://discourse.processing.org/u/olsxn)\
**Post date:** [January 6, 2020, 4:01pm UTC](https://discourse.processing.org/t/light-emitting-outwards-from-a-sphere/16904/1 "2020-01-06T16:01:04Z")

</div>

I have created a small representation of the solar system and, at the moment, I have an ambient light and directional light in the scene.

However, I would like to have the light emitting from the “Sun” outwards in all directions. How could I go about achieving this? I have included screenshots of my scene and the code below.

Thank you.

```auto
float angle = 0;

PImage img;

void setup() { 
size(640, 360, P3D);
img = loadImage("space background.jpg");
camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);
smooth(8);
}

void draw(){
  background(img);
  ambientLight(102, 102, 102);
  directionalLight(255, 255, 255, 200, 200, 0);
  
  //sun
  translate(width/2, height/2);
  noStroke();
  fill(255,200,50);
  sphere(50);
  
  //earth
  pushMatrix();
  rotateY(angle/2);
  translate(150,0);
  fill(50,200,255);
  sphere(20);
  
  //moon
  pushMatrix();
  rotateY(-angle*4);
  translate(36,0);
  fill(200);
  sphere(5);
  popMatrix();
  
  popMatrix();
  
  //mercury
  pushMatrix();
  rotateY(angle/1.5);
  translate(75, 0);
  fill(255, 50, 50);
  sphere(15);
  popMatrix();
  
  //venus
  pushMatrix();
  rotateY(angle/3);
  translate(280,0);
  fill(0, 100, 255);
  sphere(10);
  popMatrix();
  
  angle += 0.01;
}

```

 ![Screenshot 2020-01-06 at 16.00.44](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dbbaf0ebc87bb628ee8537a2822d88b3c24f62af.jpeg)

---

<div class="post-metadata">

**Author:** ![GSA\_IxD](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gsa_ixd/32/7554_2.png) [@GSA\_IxD](https://discourse.processing.org/u/GSA_IxD)\
**Post date:** [January 6, 2020, 6:37pm UTC](https://discourse.processing.org/t/light-emitting-outwards-from-a-sphere/16904/2 "2020-01-06T18:37:40Z")

</div>

You can use noLight() before drawing the sun to use uniform shading in 3D. I also created a pointLight() at the centre of the sun (changed from directionalLight())  
Try making these changes:

```auto
float angle = 0;

PImage img;

void setup() { 
  size(640, 360, P3D);
  img = loadImage("space background.jpg");
  camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);
  smooth(8);
}

void draw() {
  background(img);

  // set up ambient light
  ambientLight(102, 102, 102);

  // call noLights() before drawing sun for uniform shading
  noLights();

  //sun
  translate(width/2, height/2, 0); // create system from centre of view
  noStroke();
  fill(255, 200, 50);
  sphere(50);
  pointLight(255, 255, 255, 0, 0, 0); // create point light at centre of sun

  //earth
  pushMatrix();
  rotateY(angle/2);
  translate(150, 0);
  fill(50, 200, 255);
  sphere(20);

  //moon
  pushMatrix();
  rotateY(-angle*4);
  translate(36, 0);
  fill(200);
  sphere(5);
  popMatrix();

  popMatrix();

  //mercury
  pushMatrix();
  rotateY(angle/1.5);
  translate(75, 0);
  fill(255, 50, 50);
  sphere(15);
  popMatrix();

  //venus
  pushMatrix();
  rotateY(angle/3);
  translate(280, 0);
  fill(0, 100, 255);
  sphere(10);
  popMatrix();

  angle += 0.01;
}

```

You could get tricky and draw a rect() at the centre of the scene instead of the sphere and display a fuzzy circle as a texture on it, then use blendMode(ADD) to draw it in a more realistic way. You can also easily make the scene interactive by simply including the PeasyCam library allowing users to move around and inspect. Just some thoughts – it’s nice

---

<div class="post-metadata">

**Author:** ![olsxn](https://avatars.discourse-cdn.com/v4/letter/o/ee7513/32.png) [@olsxn](https://discourse.processing.org/u/olsxn)\
**Post date:** [January 6, 2020, 7:54pm UTC](https://discourse.processing.org/t/light-emitting-outwards-from-a-sphere/16904/3 "2020-01-06T19:54:55Z")

</div>

Thank you that works perfectly, looks exactly how I imagined it. I will experiment with the other points you made as well.
