Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage[] imgs;
- int imgNo1;
- int imgNo2;
- void setup()
- {
- //Size of each square * 4 (1 initial, 4 after that)
- size(700, 700);
- String server = "http://doc.gold.ac.uk/~mas01mjy/itp2015/ex2/";
- String[] files = new String[16];
- for (int i=0; i<files.length; i++)
- {
- files[i] = server + "image"+i+".png";
- }
- imgs = new PImage[files.length];
- for (int i=0; i<files.length; i++)
- {
- imgs[i] = loadImage(files[i]);
- }
- //imgs[3] = loadImage("http://cdn.cutestpaw.com/wp-content/uploads/2012/06/l-Monkey-munchies.jpeg");
- }
- void draw()
- {
- int y = 0;
- int x = 0;
- for (int i = 0; i < imgs.length; i++)
- {
- image(imgs[i], x, y);
- imgs[i].resize(175, 175);
- if (mouseOver(x, y))
- {
- imgNo1 = i;
- println(imgNo1);
- }
- //Resized this so that each square is drawn at x + new width
- x += 175;
- if (i % 4 == 3)
- {
- //Adapted this to the new tile size
- y += 175;
- x = 0;
- }
- }
- }
- boolean mouseOver (float x, float y)
- {
- if (mousePressed && (mouseX > x) && (mouseX < x + 175) && (mouseY > y) && (mouseY < y + 175))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement