Scaling Images in a Sketch

edited April 2014 in Questions about Code

I'm just learning processing and my knowledge feels just above minimal. I'm good at copying + pasting and making things work for projects, heh hehh... I've been skimming the book and it seems like scale() could help, but I don't know how to approach adjusting it. I want to be able to have a set image in the sketch and then be able to scale it down. I found something pretty close in another forum that originally worked with rect and I replaced with a png and that worked fine...But every time mouse is Pressed a new image comes up, getting rid of the older one.

I feel as if this is either pretty simple or a lil complicated. Either way I'm a lil bit clueless. (^ . ^); Really I just want to place a set of png's which I'm fine on doing myself of course. hmm But would that involve push and pop matrix? When the mouse makes contact with an image and presses/drags any one I want to be able to scale it in this fashion:

PVector click, drag;
PImage img;

void setup() {
  size(500,500);
  click = new PVector(0, 0);
  drag = new PVector(0, 0);
  img = loadImage("bee1.png");
  smooth();
}

void draw() {
  background(255);
//  image(img, click.x, click.y, drag.x - click.x, drag.y - click.y);
rect(click.x, click.y, drag.x - click.x, drag.y - click.y);
}

void mousePressed() {
  click.set(mouseX, mouseY, 1);
  drag.set(mouseX, mouseY, 1);
}

void mouseDragged() {
  drag.set(mouseX, mouseY, 1);
}

Answers

  • I feel this is wrong but I think this is what you meant?

    PVector click, drag;
    PImage img;
    
    void setup() {
      size(500,500);
      click = new PVector(0, 0);
      drag = new PVector(0, 0);
      img = loadImage("img.jpg");
    }
    
    void draw() {
      background(255);
      image(img, click.x, click.y, drag.x - click.x, drag.y - click.y);
    }
    
    void mousePressed() {
      click.set(mouseX, mouseY, 1);
      drag.set(mouseX, mouseY, 1);
    }
    
    void mouseDragged() {
      drag.set(mouseX, mouseY, 1);
    }
    
  • Yes, I'd already been using what you just wrote right, but it was previously used with a rectangle not an image. I just want to be able to scale a set image once I click and drag it. Thank you though.

  • I dont want the image to be solely dependent of the mouse. I want the mouse to be able to interact with an image.

Sign In or Register to comment.