Spiel für das Medientheater HBK Saar, Teil des Projektes "Fun Palace" (Reupload der Repository von 2017)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

flexibleButton.pde 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //what does a cool button need?
  2. //either trigger or bang
  3. //bang: call a function on click
  4. //trigger: toggle a boolean on click
  5. //image
  6. Button[] button = new Button[3];
  7. void setup() {
  8. size(300, 300);
  9. button[0] = new Button(10, 10, 100, 100, "Button8.png", "print");
  10. button[1] = new Button(200, 100, 100, 100, "Button1.png", "switchdoormovie");
  11. button[2] = new Button(200, 100, 100, 100, "Button1.png", "toggle random movement");
  12. fill(255);
  13. }
  14. void draw() {
  15. background(0);
  16. for (int i = 0; i < button.length; i++) {
  17. button[i].display();
  18. }
  19. }
  20. void mousePressed() {
  21. for (int i = 0; i < button.length; i++) {
  22. if (button[i].hover())
  23. button[i].clicked();
  24. }
  25. }
  26. class Button {
  27. int x, y, w, h;
  28. String WhatToDo;
  29. PImage img;
  30. boolean hover() {
  31. if (mouseX > x && mouseX < x + w &&
  32. mouseY > y && mouseY < y + h) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. }
  38. Button(int X, int Y, int W, int H, String Img, String WTD) {
  39. x = X;
  40. y = Y;
  41. w = W;
  42. h = H;
  43. img = loadImage(Img);
  44. WhatToDo = WTD;
  45. }
  46. void clicked() {
  47. if (WhatToDo.equals("color")) {
  48. //call color functions shizzle
  49. } else if (WhatToDo.equals("print")) {
  50. println("Clicked!");
  51. } else if (WhatToDo.equals("something")){
  52. } else if (WhatToDo.equals("movieToggle5")){
  53. // layers[5].togglePlay():
  54. }
  55. }
  56. void display() {
  57. image(img, x, y, w, h);
  58. }
  59. }