arrayCopy to pixels of PGraphics object
in
Programming Questions
•
1 year ago
I am trying to create a gradient by copying an array of color+transparency data into the pixels[] of a PGraphics object. But it seems the data for the blue values gets mixed up somehow. I think it might simply be the way i input the data that's the problem but haven't been able to resolve it. I have tried using bitshift, different renderes, etc. but the problem remains.
Any help would be appreiciated.
Any help would be appreiciated.
- PGraphics grad;
int[] colArr;
float gradExp = 2.0;
float n; float transp;
void setup() {
size(400, 255);
colArr = new int[width];
}
void draw()
{
background(255);
grad = createGraphics(width, height, JAVA2D);
// Calc vals
for (int i = 0; i < width; i++)
{
n = norm(i, 0, width);
transp = 255 - pow(n, gradExp) * 255;
// Fill array // blue = mouseY
colArr[i] = int(color(0, 0, int(mouseY), int(transp) ));
}
// Copy array to pixels
grad.loadPixels();
for (int i = 0; i < height; i++)
{
arrayCopy(colArr, 0, grad.pixels, width*i , width);
}
grad.updatePixels();
image(grad, 0, 0);
println(mouseY);
}
1