Hello,
Cool stuff!
I feel like that with every new topic I learn.
I was inspired and sharing my initial exploration of this:
Code here
// Pixel Exploration
// v1.0.0
// GLV 2020-10-05
// Inspired by topic:
// https://discourse.processing.org/t/using-pixels-array-over-points-trying-to-moving-pixels-xy-off-screen-like-points/24309
PImage img, img2, img3;
float mod;
int counter;
int choice = 1;
void setup()
{
size(500, 500, P3D);
frameRate(60);
img = loadImage("http://learningprocessing.com/code/assets/sunflower.jpg");
//img.loadPixels();
background(0);
img2 = createImage(400, 400, ARGB);
//img2.loadPixels();
for (int i = 0; i < img2.width*img2.height ; i++)
{
img2.pixels[i] = color(0, 255);
}
//img2.updatePixels();
}
void draw()
{
//Sinusoidal modulation from 0 to 2
mod = 1+1*sin(counter*TAU/500-TAU/4);
counter++;
switch(choice)
{
case 1:
println("Plot 1");
plot1();
break;
case 2:
println("Plot 2");
plot2();
break;
case 3:
println("Plot 3");
plot3();
break;
case 4:
println("Plot 4");
plot4();
break;
default:
println("Woops!");
break;
}
surface.setTitle(str(frameRate));
}
//**********************************************************************************
void plot1()
{
fill(0, 5);
noStroke();
rect(0, 0, width, height);
for (int x = 0; x < img.width; x++ )
{
for (int y = 0; y < img.height; y++ )
{
// Pixel location and color
color c = img.get(x, y);
float sz = (brightness(c)/255)*mod;
set(int(x*sz), int(y*sz), c);
}
}
}
//**********************************************************************************
void plot2()
{
fill(0, 5);
noStroke();
rect(0, 0, width, height);
for (int x = 0; x < img.width; x++ )
{
for (int y = 0; y < img.height; y++ )
{
// Pixel location and color
color c = img.pixels[x+img.width*y];
float sz = (brightness(c)/255)*mod;
set(int(x*sz), int(y*sz), c);
}
}
}
//**********************************************************************************
void plot3()
{
fill(0, 5);
noStroke();
rect(0, 0, width, height);
for (int x = 0; x < img.width; x++ )
{
for (int y = 0; y < img.height; y++ )
{
// Pixel location and color
color c = img.pixels[x+img.width*y];
float sz = (brightness(c)/255)*mod;
//sz = 1; // Try this to see original image.
img2.pixels[int(x*sz)+int(y*sz)*400] = c;
}
}
img2.updatePixels();
image(img2, 0, 0);
}
//**********************************************************************************
void plot4()
{
// Sets pixel array to a fixed color with transparency
for (int i = 0; i < img2.width*img2.height ; i++)
{
img2.pixels[i] = color(0, 5);
}
for (int x = 0; x < img.width; x++ )
{
for (int y = 0; y < img.height; y++ )
{
// Pixel location and color
color c = img.pixels[x+img.width*y];
float sz = brightness(c)/255*mod;
//sz = 1; // Try this to see original image.
//c = color(255, 255, 0); //Test with fixed color
img2.pixels[int(x*sz)+int(y*sz)*400] = c;
}
}
img2.updatePixels();
image(img2, 0, 0);
}
void keyPressed()
{
counter = 0;
choice++;
if (choice >4)
choice = 1;
}
I did not scrutinize your code and instead did an exploration of this.
:)