Not work mousePressed left click!

tileCountX=2

tileCountY=10

colorsLeft=[]

colorsRight=[]

interpolateShortest=True

def setup():

size(800,800)

colorMode(HSB)

noStroke()

shakeColors()

def draw():

tileCountX=int(map(mouseX,0,width,2,100))

tileCountY=int(map(mouseY,0,height,2,10))



tileWidth=width/tileCountX

tileHeight=height/tileCountY

for gridY in range(tileCountY):

    col1=colorsLeft[gridY]

    col2=colorsRight[gridY]

    for gridX in range(tileCountX):

        amount=map(gridX,0,tileCountX-1,0,1)

        if interpolateShortest:

            colorMode(RGB)

            interCol=lerpColor(col1,col2,amount)

            colorMode(HSB)

        else:

            interCol=lerpColor(col1,col2,amount)

        fill(interCol)

        posX=tileWidth*gridX

        posY=tileHeight*gridY

        rect(posX,posY,tileWidth,tileHeight)

def shakeColors():

for i in range(tileCountY):

    colorsLeft.append(color(random(0, 60), random(0, 100), 100)) 

    colorsRight.append(color(random(160, 190), 100, random(0, 100)))

def keyPressed():

global interpolateShortest

if key=="1": 

    interpolateShortest=True

elif key=="2": 

    interpolateShortest=False

def mousePressed():

shakeColors()         #didnt work i couldn t reuse shakeColor function when i pressed mouse left click.

i changed the name shakeColors as makeColors and then i redefined colorsLeft,colorsRight lists indexes again with shakeColors function.then solved

2 Likes