Hi! I am attempting to load an image into a Pgraphic with creategraphics named layer 1
The intent is to be able to load an image, distort the r,g,b and update the pixels into the layer1 create graphic thus clipping the distorted image.
It currently loads the distorted image, but outside of the layer1 creategraphic
You can find the code I am referring to under void photo()
Poster newPoster;
void setup() {
size(displayWidth, 1152);
smooth();
newPoster = new Poster(width/2, height/2, 1728/2, 1152, 1, color(255, 255, 0), "artNOW", color(0), 50, 45);
}
void draw() {
background(0);
newPoster.display();
newPoster.photo();
newPoster.type();
newPoster.mouseDragged();
saveFrame("poster.jpg");
}
class Poster {
color c;
float xpos;
float ypos;
float pwidth;
float pheight;
float s;
String t;
color textcolor;
float textsize;
PFont font;
PImage img;
float leading;
float wave;
float imagePosX = width/2;
float imagePosY = height/2;
int imageEdgeLeft = 650;
PGraphics layer1, layer2, layer3, layer4;
Poster(float tempX, float tempY, float tempW, float tempH, float tempScale, color tempBGcolor, String tempString, color tempTextcolor, float tempTextsize, float tempLeading) {
c = tempBGcolor;
xpos = tempX;
ypos = tempY;
pwidth = tempW; //18"
pheight = tempH; //24"
s = tempScale;
t = tempString;
textcolor = tempTextcolor;
textsize = tempTextsize;
leading = tempLeading;
}
void display() {
imageMode(CENTER);
layer3 = createGraphics(width, height);
layer3.beginDraw();
layer3.rectMode(CENTER);
layer3.noStroke();
//translate(250, 250);
layer3.scale(s);
layer3.fill(c);
layer3.rect(xpos, ypos, pwidth, pheight);
layer3.endDraw();
image(layer3, width/2, height/2);
}
void photo() {
imageMode(CENTER);
layer1 = createGraphics(700, 700); // layer 1 clipping box
img = loadImage("falcon9.jpg");
image(img, imagePosX, imagePosY);
layer1.beginDraw();
layer1.background(155);
loadPixels();
img.loadPixels();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++ ) {
int loc = x + y*width;
float r, g, b;
r = red(pixels[loc]);
g = green(pixels[loc]);
b = blue(pixels[loc]);
float adjustBrightness = 3;
r *= adjustBrightness;
g *= adjustBrightness;
b *= adjustBrightness;
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
pixels[loc] = color(r, g, b);
}
}
updatePixels();
layer1.endDraw();
//layer1.filter(GRAY);
//layer1.filter(BLUR);
image(layer1, width/2, height/2-100); //layer starting point // imageMode is center not corner default
}
void mouseDragged() {
if (mouseX > 0 && mouseX < img.width ) {
if (mouseY > 200 && mouseY < 900) {
if (mousePressed) {
imagePosX =+ mouseX;
imagePosY =+ mouseY;
}
}
}
}
void type() {
font = loadFont("LucidaSans-Typewriter-48.vlw");
textFont(font, 32);
imageMode(CENTER);
layer2 = createGraphics(width, height);
layer2.beginDraw();
textSize(textsize);
fill(textcolor);
layer2.textLeading(leading);
text(t, 612, 900, width/2, height/2);
layer2.endDraw();
image(layer2, width/2, height/2, width, height);
}
}