# Does anyone know how to fix the background color?

**URL:** <https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [November 2, 2022, 2:08pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553 "2022-11-02T14:08:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningprocessing23](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@learningprocessing23](https://discourse.processing.org/u/learningprocessing23)\
**Post date:** [November 2, 2022, 2:08pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/1 "2022-11-02T14:08:10Z")

</div>

Hello! I setup the color could be changed from 2 pink colors. I hope after dragging to a color that I like (between color A and color B), I can decide and make the color as background color (maybe by mousePressed()) And then the color will not change when the mouse move again. I am not sure how to add the void mousePressed and hopefully you could help! Thanks! 🙂

> void setup() {  
> size(600, 600);  
> }

> void draw() {  
> color colorA = color(#F2ACB9);  
> color colorB = color(#f27999);  
> float value = map(mouseX, 0, width, 0, 1);  
> color colorC = lerpColor(colorA, colorB, value);  
> background(colorC);  
> }

---

<div class="post-metadata">

**Author:** ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)\
**Post date:** [November 2, 2022, 2:41pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/2 "2022-11-02T14:41:25Z")

</div>

Did you try out a similar approach as the example on the [`mousePressed()`](https://processing.org/reference/mousePressed_.html) reference page?

---

<div class="post-metadata">

**Author:** ![learningprocessing23](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@learningprocessing23](https://discourse.processing.org/u/learningprocessing23)\
**Post date:** [November 2, 2022, 2:52pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/3 "2022-11-02T14:52:49Z")

</div>

Thank you! But my problem is that I need to change between the range of color A and color B, instead of switching from color A to color B.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 2, 2022, 4:19pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/4 "2022-11-02T16:19:42Z")

</div>

Hi

Change color with mouse

```auto
void setup () {
size (600,600);
colorMode(HSB);
}
void draw(){
for(int i= 500; i >0; i=i -2) {
  background ((i/2) + (mouseX/3), 255,255);
}
}

```

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [November 2, 2022, 4:40pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/5 "2022-11-02T16:40:23Z")

</div>

> [@learningprocessing23](#):
>
> need to change between the range of color A and color

Do you mean that you want to be able to drag the mouse and the background color changes while the mouse is dragging across screen?  
🤓

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 2, 2022, 4:43pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/6 "2022-11-02T16:43:03Z")

</div>

Hi

Your sketch is working in think you picked close colors value

[https://funprogramming.org/82-Program-a-gradient-of-colors.html](https://funprogramming.org/82-Program-a-gradient-of-colors.html)

```auto
void setup() {
size(600, 600);
}

void draw() {
color colorA = color(#F200B0);
color colorB = color(#f279f9);
float value = map(mouseX, 0, width, 0, 1);
color colorC = lerpColor(colorA, colorB, value);
background(colorC);
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 2, 2022, 6:29pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/7 "2022-11-02T18:29:52Z")

</div>

Hi

With mouse pressed

```auto

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

void draw() {

}
void mousePressed() {
 color colorA = color(#F200B0);
color colorB = color(#f279f9);
float value = map(mouseX, 0, width, 0, 1);
color colorC = lerpColor(colorA, colorB, value);
background(colorC);
  
}

```

---

<div class="post-metadata">

**Author:** ![learningprocessing23](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@learningprocessing23](https://discourse.processing.org/u/learningprocessing23)\
**Post date:** [November 2, 2022, 11:32pm UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/8 "2022-11-02T23:32:15Z")

</div>

Hello! Yes, I hope the color would change while the mouse is dragging across screen. But actually, I hope after dragging to a color that I like (between color A and color B), I can decide and make the color as background color (maybe by MouseClicked?) The color will not change when the mouse move again. But I don’t know how to do that function. Thank you~

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 3, 2022, 1:09am UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/9 "2022-11-03T01:09:07Z")

</div>

Hello @learningprocessing23,

Consider this in the draw() loop:

```auto
if(mousePressed)
    {
    // change colorC here
    }
  background(colorC);

```

Keep in mind that some you will have to _declare_ some variables globally and change them inside the _if()_ statement.

[https://processing.org/examples/variablescope.html](https://processing.org/examples/variablescope.html)

Once I released the mouse the color was applied to the background.

References:

- [https://processing.org/tutorials/interactivity](https://processing.org/tutorials/interactivity)

- [https://processing.org/reference/#input](https://processing.org/reference/#input)  
See Mouse section

`:)`

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 3, 2022, 2:45am UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/10 "2022-11-03T02:45:28Z")

</div>

> [@jafal](#):
>
> With mouse pressed

@learningprocessing23

With the sketch I provided color won’t change unless you press mouse and move it

Moving mouse only won’t change the color …what you need exactly?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 3, 2022, 4:49am UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/11 "2022-11-03T04:49:26Z")

</div>

In this video close idea of what you want

[https://funprogramming.org/81-How-to-read-the-color-of-a-pixel.html](https://funprogramming.org/81-How-to-read-the-color-of-a-pixel.html)

---

<div class="post-metadata">

**Author:** ![learningprocessing23](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@learningprocessing23](https://discourse.processing.org/u/learningprocessing23)\
**Post date:** [November 4, 2022, 2:30am UTC](https://discourse.processing.org/t/does-anyone-know-how-to-fix-the-background-color/39553/12 "2022-11-04T02:30:02Z")

</div>

Thank you! This turtorial is very helpful!!
