# Random Color on Background

**URL:** <https://forum.critterandguitari.com/t/random-color-on-background/4063>\
**Category:** ETC\
**Created:** [March 24, 2019, 2:35pm UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063 "2019-03-24T14:35:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanwander](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.critterandguitari.com/fanwander/32/5076_2.png) [@fanwander](https://forum.critterandguitari.com/u/fanwander)\
**Post date:** [March 24, 2019, 2:35pm UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063/1 "2019-03-24T14:35:58Z")

</div>

I wanted to have random color blinking on the background. I found two methods:

1.) as first action in a mode draw a rectangle with random color. This may look like this

```
...
def draw(screen, etc):
   pygame.draw.rect(screen, ((random.randrange(0, 2) * 255),(random.randrange(0, 2) * 255),(random.randrange(0, 2) * 255)), ((0,0),(1280,720)), 0)
...

```

2.) Or change in /root/ETC\_Mother/etc\_system.py the definition of color\_picker\_bg, which is at the end of the file:

```
def color_picker_bg( self ):
    c = float(self.knob5)
    if c < .99 :
        r = (1 - (math.cos(c * 3 * math.pi) * .5 + .5)) * c
        g = (1 - (math.cos(c * 7 * math.pi) * .5 + .5)) * c
        b = (1 - (math.cos(c * 11 * math.pi) * .5 + .5)) * c
        color = (r * 255,g * 255,b * 255)

    if c > .98 :
        r = random.randrange(0, 2) * 255
        g = random.randrange(0, 2) * 255
        b = random.randrange(0, 2) * 255
        color = (r,g,b) 
    self.bg_color = color
    return color

```

This way the bg-color knob will switch to random if turned fully clockwise.

---

<div class="post-metadata">

**Author:** ![d00g13h0ws3rmd](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.critterandguitari.com/d00g13h0ws3rmd/32/2165_2.png) [@d00g13h0ws3rmd](https://forum.critterandguitari.com/u/d00g13h0ws3rmd)\
**Post date:** [March 25, 2019, 12:55am UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063/2 "2019-03-25T00:55:23Z")

</div>

awesome. thanks!

---

<div class="post-metadata">

**Author:** ![fanwander](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.critterandguitari.com/fanwander/32/5076_2.png) [@fanwander](https://forum.critterandguitari.com/u/fanwander)\
**Post date:** [March 25, 2019, 9:37am UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063/3 "2019-03-25T09:37:00Z")

</div>

I am still looking for the possibility to have the background slowly fading through the colours. I would know how to achieve this with printing the background rectangle within the mode. But I would like to have it as a possible selection on the knob5. Any idea?

---

<div class="post-metadata">

**Author:** ![seanomenon](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@seanomenon](https://forum.critterandguitari.com/u/seanomenon)\
**Post date:** [March 14, 2020, 6:57pm UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063/4 "2020-03-14T18:57:21Z")

</div>

Hi @fanwander I have been wondering this same thing: “I am still looking for the possibility to have the background slowly fading through the colours.” Have you found a way to achieve this in the year since this post?

---

<div class="post-metadata">

**Author:** ![fanwander](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.critterandguitari.com/fanwander/32/5076_2.png) [@fanwander](https://forum.critterandguitari.com/u/fanwander)\
**Post date:** [March 14, 2020, 9:16pm UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063/5 "2020-03-14T21:16:36Z")

</div>

No, not yet. But I did not follow this idea until now.

---

<div class="post-metadata">

**Author:** ![seanomenon](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@seanomenon](https://forum.critterandguitari.com/u/seanomenon)\
**Post date:** [March 15, 2020, 12:02am UTC](https://forum.critterandguitari.com/t/random-color-on-background/4063/6 "2020-03-15T00:02:03Z")

</div>

OK - I’m going to explore the idea too. I’ll let you know if I figure anything out.
