Why does image resize differently with copy()?

edited September 2015 in Questions about Code

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

Sign In or Register to comment.