# Separating effects

**URL:** https://discourse.processing.org/t/separating-effects/32139
**Category:** Coding Questions
**Created:** [September 7, 2021, 5:45pm UTC](https://discourse.processing.org/t/separating-effects/32139 "2021-09-07T17:45:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![achip30](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@achip30](https://discourse.processing.org/u/achip30)
#### Post date: [September 7, 2021, 5:45pm UTC](https://discourse.processing.org/t/separating-effects/32139/1 "2021-09-07T17:45:21Z")

</div>

This is a snippet from my main code. I have two separate ellipses. I only want the central ellipse to have a shadowing effect. How do I limit the shadowing effect specifically to the central ellipse, and not to the smaller ellipse in the lower left?

```auto
function setup() {
  createCanvas(400, 400);
  background(255);
}

function draw() {

  // lower left ellipse
    noStroke();
    fill(255,50,0);
   ellipse(50, 375, 25, 25);
  

//shadow effect
  drawingContext.shadowOffsetX = -2;
  drawingContext.shadowOffsetY = 3;
  drawingContext.shadowBlur = 1;
  drawingContext.shadowColor = 'black'; 

// central ellipse (main) 
  let c = color(130, 130, 0); //COLOR = ATOMIC MASS
  fill(c);
  noStroke();
  ellipse(200, 200, 150, 150);
  
 
}

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [September 7, 2021, 6:03pm UTC](https://discourse.processing.org/t/separating-effects/32139/2 "2021-09-07T18:03:27Z")

</div>

Hi @achip30,

Welcome to the forum! 😉

In order to save and restore the context, you can use the `CanvasRenderingContext2D` methods: [`save()`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save) and [`restore()`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore)

They work just like `push()` and `pop()`:

```auto
drawingContext.save(); // Save the current style

drawingContext.shadowOffsetX = -2;
drawingContext.shadowOffsetY = 3;
drawingContext.shadowBlur = 1;
drawingContext.shadowColor = 'black'; 
  
fill(130, 130, 0);
noStroke();
ellipse(200, 200, 150, 150);
  
drawingContext.restore(); // Restore the style

```

---

<div class="post-metadata">

### Author: ![achip30](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@achip30](https://discourse.processing.org/u/achip30)
#### Post date: [September 7, 2021, 6:13pm UTC](https://discourse.processing.org/t/separating-effects/32139/3 "2021-09-07T18:13:48Z")

</div>

Thank you so much! New to p5 and I figured it was something simple lol.

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [September 7, 2021, 8:42pm UTC](https://discourse.processing.org/t/separating-effects/32139/4 "2021-09-07T20:42:52Z")

</div>

Hello, @achip30, and welcome to the Processing Forum!

It is important to remember that `draw()` is called repeatedly, unless you specify otherwise.

See [p5.js Reference: `draw()`](https://p5js.org/reference/#/p5/draw).

The following, which is a modified version of your code, may help you observe what happened:

```auto
function setup() {
  createCanvas(200, 200);
  background(255);
  frameRate(0.5);
  noStroke();
  textSize(20);
}

function draw() {
  background(255);
  text("Frame " + frameCount, width / 2, height - 25);
  fill(255,50,0);
  
  // smaller ellipse in the lower left
  ellipse(50, height - 25, 25, 25);
  
  // invoke shadowing
  drawingContext.shadowOffsetX = -8;
  drawingContext.shadowOffsetY = 8;
  drawingContext.shadowBlur = 1;
  drawingContext.shadowColor = 'blue'; 
  let c = color(130, 130, 0); //COLOR = ATOMIC MASS
  fill(c);
  
  // central ellipse
  ellipse(width / 2, height / 2, width / 3, height / 3);
}

```

Below are renderings of the sketch during the first two frames:  
 ![frame1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1ff554224b3b4d632d142c3a5421a6e60480d41a.png)

![frame2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8e5ea2753a67643bd179f06606b89330d18d98d1.png)

During frame 1, the smaller ellipse in the lower left and the text were drawn before shadowing was in effect. The central ellipse was drawn after shadowing had been activated.

Since you did not specify otherwise, shadowing was still in effect at the start of frame 2, and throughout the duration of every frame thereafter.

---

<div class="post-metadata">

### Author: ![achip30](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@achip30](https://discourse.processing.org/u/achip30)
#### Post date: [September 8, 2021, 3:56am UTC](https://discourse.processing.org/t/separating-effects/32139/5 "2021-09-08T03:56:14Z")

</div>

Great explanation. This actually got me to read about noLoop(), which helped solve another problem I was having. Thank you!

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [September 8, 2021, 7:47am UTC](https://discourse.processing.org/t/separating-effects/32139/6 "2021-09-08T07:47:39Z")

</div>

Ahh love it, this is what everyone should do! Reading the docs is underrated 😜
