We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to copy part of an image to a new location. If I call the coordinates explicitly it copies fine. If the coordinates are based on a calculation it tries to put in the remaining part of the image. Where am I going wrong? Yes, I am new to processing. I am running on linux. The following shows the two code examples. Thanks
Code 1 - The copy is called explicitly
PImage photo;
void setup() {
size(900, 360);
photo = loadImage("Data/test.png"); // Load the image into the program
}
void draw() {
background(0);
image(photo, 0, 0);
// Displays a part of the image to a new section of the window.
copy(photo, 330, 0, 100, height, 750, 0, 100, height);
}
Code 2 - The copy is based on an equation
PImage photo;
float x;
int speed, z;
void setup() {
size(900, 360);
photo = loadImage("data/test.png");
speed=30;
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
//Change direction
x=x+(speed*e);
//Check boundry
if (x < 0) {
x = 540;
} else if (x > 540) {
x = 0;
}
println(x);
}
void draw()
{
z=int(x);
background(0);
//z=(int)x;
image(photo, 0, 0, 640, 360);
copy(photo, z, 0, z+100, height, 750, 0, 100, height);
line(z, 0, z, height);
line(z+100, 0, z+100, height);
}
Answers
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Thanks for looking at my post. I was wondering why it reformatted the code when I previewed it. Hopefully it is cleaned up and you can read it now.
those two copy()s are completely different though
if z was 330 then the second would be
copy(photo, 330, 0, 430, height, 750, 0, 100, height);
there's never a case when they are identical
i think that z + 100 in the second should just be 100 - it's relative whereas you have it as an absolute.
That works! It seems so obvious now. Thanks for the help.