Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. PImage[] imgs;
  2. int imgNo1;
  3. int imgNo2;
  4.  
  5. void setup()
  6. {
  7. //Size of each square * 4 (1 initial, 4 after that)
  8. size(700, 700);
  9. String server = "http://doc.gold.ac.uk/~mas01mjy/itp2015/ex2/";
  10. String[] files = new String[16];
  11. for (int i=0; i<files.length; i++)
  12. {
  13. files[i] = server + "image"+i+".png";
  14. }
  15.  
  16. imgs = new PImage[files.length];
  17.  
  18. for (int i=0; i<files.length; i++)
  19. {
  20. imgs[i] = loadImage(files[i]);
  21. }
  22.  
  23. //imgs[3] = loadImage("http://cdn.cutestpaw.com/wp-content/uploads/2012/06/l-Monkey-munchies.jpeg");
  24. }
  25.  
  26. void draw()
  27. {
  28. int y = 0;
  29. int x = 0;
  30. for (int i = 0; i < imgs.length; i++)
  31. {
  32. image(imgs[i], x, y);
  33. imgs[i].resize(175, 175);
  34. if (mouseOver(x, y))
  35. {
  36. imgNo1 = i;
  37. println(imgNo1);
  38. }
  39. //Resized this so that each square is drawn at x + new width
  40. x += 175;
  41. if (i % 4 == 3)
  42. {
  43. //Adapted this to the new tile size
  44. y += 175;
  45. x = 0;
  46. }
  47. }
  48. }
  49.  
  50. boolean mouseOver (float x, float y)
  51. {
  52. if (mousePressed && (mouseX > x) && (mouseX < x + 175) && (mouseY > y) && (mouseY < y + 175))
  53. {
  54. return true;
  55. }
  56. else
  57. {
  58. return false;
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement