Colors! (a lot of colors but not all of them)

import random

class Walker:
    def __init__ (self):
        self.x = width >> 1
        self.y = height >> 1
        self.foot = 10 #space between every step
        self.strw = 3#stroke weight
    def move(self):
        a = random.randint(0,4)
        if a == 0:
            #self.x = constrain(self.x - self.foot,2,width - 2)
            self.x = self.x - self.foot
        elif a == 1:
            #self.x = constrain(self.x +self.foot,2,width - 2)
            self.x = self.x + self.foot
        elif a == 2:
            #self.y = constrain(self.y - self.foot,2,height - 2)
            self.y = self.y - self.foot
        elif a == 3:
            #self.y = constrain(self.y + self.foot,2,height - 2)
            self.y = self.y + self.foot
        if(self.x > width- self.strw):
            self.x = self.strw
        if(self.x < self.strw):
            self.x = width - self.strw
        if(self.y > height- self.strw):
            self.y = self.strw
        if(self.y < self.strw):
            self.y = height - self.strw
    def show(self,colorr):
        self.strw = 4
        stroke(colorr)
        strokeWeight(self.strw)
        point (self.x,self.y)
    
width = 500
height = 500
walker = Walker()


def setup():
    global i
    i = 0
    size(width,height)
    background(0)
    frameRate(120)
    
def draw():
    if i < 1<<24:
        r = ((i>>16) & 0xff) #* 0x11
        g = ((i>>8) & 0xff) #* 0x11
        b = (i & 0xff) #* 0x11
        colour = color(r,g,b)
        walker.show(colour)
        walker.move()
        global i
        i = i + 20

To have a shorter range of colors:

 if i < 1<<12:
        r = ((i>>8) & 0xff) * 0x11
        g = ((i>>4) & 0xff) * 0x11
        b = (i & 0xff) * 0x11

or add to i a bigger number
RGB colors scale (but only blue) :


The “Walker” example where i took ‘inspiration’:
https://natureofcode.com/book/introduction/

What can I add?
Theres a way to run this code as screensaver? :smiley:
saver

1 Like

Checkout color() and lerpCollor() fucntions.

Or read about HSV color model if you want to dive deeper.

2 Likes