# Beginner question, changing background in pong when ball hits paddle

**URL:** https://discourse.processing.org/t/beginner-question-changing-background-in-pong-when-ball-hits-paddle/27158
**Category:** Coding Questions
**Created:** [January 18, 2021, 2:11pm UTC](https://discourse.processing.org/t/beginner-question-changing-background-in-pong-when-ball-hits-paddle/27158 "2021-01-18T14:11:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lucyteio](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lucyteio](https://discourse.processing.org/u/lucyteio)
#### Post date: [January 18, 2021, 2:11pm UTC](https://discourse.processing.org/t/beginner-question-changing-background-in-pong-when-ball-hits-paddle/27158/1 "2021-01-18T14:11:57Z")

</div>

Hello to all  
I have an assignment for art school. we have been given the pong game and we must change the code to create a story… I wish to change the background each time the pong hits a paddle.  
any help would be gratefully received

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 18, 2021, 2:17pm UTC](https://discourse.processing.org/t/beginner-question-changing-background-in-pong-when-ball-hits-paddle/27158/2 "2021-01-18T14:17:23Z")

</div>

instead of saying `background(0);`

use a variable that you define before setup()

`color colBackground = color(255,0,0);`

and say `background(colBackground);`

**NOW**

NOW when you have a hit change colBackground with

`colBackground = color(random(256),random(20,256),random(256));`

**Hey and welcome to the forum!**

**Great to have you here!**

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [January 18, 2021, 2:59pm UTC](https://discourse.processing.org/t/beginner-question-changing-background-in-pong-when-ball-hits-paddle/27158/3 "2021-01-18T14:59:00Z")

</div>

a program that flashes when key is pressed;

```auto
int v = 0, s = -10;
void draw() {
  background(v);
  v = constrain(v+s,0,255);
}
void keyPressed() { v = 255; }

```
