# How do you Create Shadows in Processing?

**URL:** <https://discourse.processing.org/t/how-do-you-create-shadows-in-processing/35128>\
**Category:** Coding Questions\
**Created:** [February 12, 2022, 5:07pm UTC](https://discourse.processing.org/t/how-do-you-create-shadows-in-processing/35128 "2022-02-12T17:07:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdcmole](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rdcmole/32/15669_2.png) [@rdcmole](https://discourse.processing.org/u/rdcmole)\
**Post date:** [February 12, 2022, 5:07pm UTC](https://discourse.processing.org/t/how-do-you-create-shadows-in-processing/35128/1 "2022-02-12T17:07:41Z")

</div>

I am trying to make my images more realistic by adding the shadows of the rendered shapes. I thought that it may be automatic when adding directional lights, but this does not appear to work. Below is a simple test code that I wrote at attempts to use directional and spot lights to draw the shadow of a sphere on the inside of a box but does not work.

```auto
/*
 * Shadow Test Code
 *
 * Move the mouse the change the direction of the light.
 *
 */

void setup() {
  size(900, 400, P3D);
  noStroke();
}

void draw() {
  noStroke();
  background(0);
  float dirY = (mouseY / float(height) - 0.5) * 2;
  float dirX = (mouseX / float(width) - 0.5) * 2;
  directionalLight(204, 204, 204, -dirX, -dirY, -1);
  spotLight(250, 250, 0, 0, 0, 1200, -dirX, -dirY, -1, PI/8, 100);
  translate(width/2, height/2, 0);
  sphere(80);
  box(900.0, 400.0, 1000.0);
}

```

I searched other posts and found a discussion that gave a rather complex method but being a processing novice, I could not get the posted code to work.

Is there a relatively simple method of creating object shadows?
