line tracking-mouse pressed, over an image (drawing ontop of an image)

edited July 2015 in Questions about Code

hey, im quite new with processing and im trying to make a code for altering images on key commands. My problem is first i change colors then i have a magnifies quad, and then i tried put a continuos line tracking on mose pressed so that you can draw on top of the image- and this doesnt work! when i press the command the dot shows up but not the line behind it, I guess the background is being redrawn in each loop so it doesnt show but i dont know where to put the image so that it stays behind?...

PImage img1; float rotx = PI/4; float roty = PI/4; float angle = 0.0;

int MODE = 2;

PImage magnifier;

void setup() { size(600, 800, P3D); img1 = loadImage("mray.jpg");

textureMode(NORMAL); fill(255); stroke(color(44, 48, 32)); noCursor();

}

int red; int green; int blue;

void draw() {

if (MODE == 1) {

red = mouseX;
green = mouseY;
blue = 180;

} tint(red, green, blue); image(img1, 0, 0);

//if (MODE == 3) { // filter(INVERT); //}

if (MODE == 2) { noStroke();

magnifier = img1.get(mouseX+380, mouseY+150, 100, 100);
translate(mouseX, mouseY+200);
magnifier.resize(80, 80);


rotateX(rotx);
rotateY(roty);
scale(50);


if (keyPressed == true) {
  saveFrame();
}

} println(magnifier); TexturedCube(magnifier); }

void TexturedCube(PImage img) { noTint(); beginShape(QUADS);

texture(img);

// +Z "front" face vertex(0, -1, 1, 0, 0); vertex( 0, -1, 1, -1, 0); vertex( 1, 1, 1, -1, 1); vertex(-1, 1, 1, 0, 1);

// -Z "back" face vertex( 0, -1, -1, 0, 0); vertex(0, -1, -1, 1, 0); vertex(-1, 1, -1, 1, 1); vertex( 1, 1, -1, 0, 1);

// +Y "bottom" face vertex(-1, 1, 1, 0, 0); vertex( 1, 1, 1, 1, 0); vertex( 1, 1, -1, 1, 1); vertex(-1, 1, -1, 0, 1);

// +X "right" face vertex( 0, -1, 1, 0, 0); vertex( 0, -1, -1, 1, 0); vertex( 1, 1, -1, 1, 1); vertex( 1, 1, 1, 0, 1);

// -X "left" face vertex(0, -1, -1, 0, 0); vertex(0, -1, 1, 1, 0); vertex(-1, 1, 1, 1, 1); vertex(-1, 1, -1, 0, 1);

endShape();

if (MODE == 4) { stroke(255); strokeWeight(2); if (mousePressed == true) { line(mouseX, mouseY, pmouseX, pmouseY); }

} }

void keyPressed() { println(keyCode);

if (keyCode == 49) { MODE = 1; } if (keyCode == 50) { MODE = 2; } if (keyCode == 51) { MODE = 3; }

if (keyCode == 52) { MODE = 4; } }

void mouseDragged() { float rate = 0.01; rotx += (pmouseY-mouseY) * rate; roty += (mouseX-pmouseX) * rate; }

Sign In or Register to comment.