manipulate multiple PImage with mouse
in
Programming Questions
•
1 year ago
Hi,
I'm really new to programming and I need a bit of help. I want to write an app that has a bank of elements (PImage or Shape elements) on the left and a background image on the right. I want to be able to click on the elements on the left to add them to the image one at a time (or drag it on to the canvas), and I want to be able to resize the elements individually.
Is Processing capable of this? I know that might sound confusing, so I'll start with just one question. In this example have commented out the images and replaced them with rectangles. I want to be able to manipulate each rectangle individually, without affecting the other one. In my app, I want these to be images (.png) rather than shapes.
Now that I've typed this out. I feel like I should be able to answer my own question, but I'm stumped. Maybe I've been looking at this too long.
Thanks in advance!
- //PImage clv;
- Tree tree;
- Tree tree2;
- void setup() {
- size(800, 500);
- smooth();
- imageMode(CENTER);
- // clv = loadImage("clv.png");
- // tree = new Tree("tree.gif", 50, 50);
- // tree2 = new Tree("tree.gif", 33, 60);
- tree = new Tree(50,50);
- tree2 = new Tree(150,150);
- }
- void draw() {
- // background(clv);
- background(150);
- tree.display();
- tree.move();
- tree2.display();
- tree2.move();
- }
- class Tree {
- PImage tree;
- float x,y;
- Tree(
- //String filename,
- float x_, float y_) {
- // tree = loadImage(filename);
- x = x_;
- y = y_;
- }
- void display() {
- // translate(x,y);
- // image(tree, x, y);
- rect(x,y,100,200);
- }
- void move() {
- if (mousePressed) {
- x=mouseX;
- y=mouseY;
- }
- }
- }
1