Move Pixels Based on Brightness

Hi Processing community. I am new to processing, but have used many scripts and am somewhat familiar with the interface and in thinking through the code.

My question is I would like to move the pixels of an image based on brightness values.

https://processing.org/tutorials/pixels/

^ the last example on the page [Example: 2D image mapped to 3D] uses map to calculate a z position as a function of mouse X, but I would like the script to work off of an equation rather than it be interactive.

for example

if (br < 120 || br > 180) {

I would like the pixels either to move or not move - but I am not sure how to finish the code!

Here is the original examples code, I would deeply love and appreciate if anybody has any recommendations or solutions!

PImage img; // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int cols, rows; // Number of columns and rows in our system

void setup() {
size(200, 200, P3D);
img = loadImage(“sunflower.jpg”); // Load the image
cols = width/cellsize; // Calculate # of columns
rows = height/cellsize; // Calculate # of rows
}

void draw() {
background(0);
loadPixels();
// Begin loop for columns
for ( int i = 0; i < cols;i++) {
// Begin loop for rows
for ( int j = 0; j < rows;j++) {
int x = icellsize + cellsize/2; // x position
int y = j
cellsize + cellsize/2; // y position
int loc = x + y*width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
float z = (mouseX/(float)width) * brightness(img.pixels[loc]) - 100.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x,y,z);
fill©;
noStroke();
rectMode(CENTER);
rect(0,0,cellsize,cellsize);
popMatrix();
}
}
}

explode3

Additionally, the end goal of the script I’m trying to write, I only would need to replace the movement of pixels with the mousex - maybe the problem is the map() ?