Guest User

Untitled

a guest
Dec 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. final int WIDTH = 600;
  2. final int HEIGHT = 800;
  3.  
  4. final int total = 20;
  5. int nowImageF = 1, nowImageB = 1;
  6.  
  7. int btnHeight = 50;
  8.  
  9. void createBtn(int x, int y, String text)
  10. {
  11. fill(255, 255, 255);
  12. rect(x, y, 100, btnHeight);
  13.  
  14. fill(0, 0, 0);
  15. textSize(16);
  16. text(text, x + 20, y + 30);
  17. }
  18.  
  19. void btn()
  20. {
  21. // upper
  22. createBtn(500, 0, "Random");
  23. createBtn(500, 100, "Next");
  24. createBtn(500, 150, "Previous");
  25.  
  26. createBtn(500, 300, "Save");
  27.  
  28. // bottom
  29. createBtn(500, 550, "Random");
  30. createBtn(500, 600, "Next");
  31. createBtn(500, 650, "Previous");
  32. }
  33.  
  34. boolean func()
  35. {
  36. int x = mouseX, y = mouseY;
  37.  
  38. if(mousePressed == true)
  39. {
  40. if(mouseButton == LEFT)
  41. {
  42. if(x >= 500)
  43. {
  44. // Random
  45. if(y <= btnHeight)
  46. {
  47. nowImageF = (int)random(1, 20);
  48. }
  49. else if(y >= 550 && y <= 550 + btnHeight)
  50. {
  51. nowImageB = (int)random(1, 20);
  52. }
  53. // Next
  54. else if(y >= 100 && y <= 100 + btnHeight)
  55. {
  56. nowImageF++;
  57.  
  58. }
  59. else if(y >= 600 && y <= 600 + btnHeight)
  60. {
  61. nowImageB++;
  62. }
  63. // Previous
  64. else if(y >= 150 && y <= 150 + btnHeight)
  65. {
  66. nowImageB--;
  67. }
  68. else if(y >= 300 && y <= 300 + btnHeight)
  69. {
  70. save("random_pic.jpg");
  71. println("Saved!");
  72. }
  73.  
  74. if(nowImageB > 20)
  75. {
  76. nowImageB %= total;
  77. nowImageB += 1;
  78. }
  79. if(nowImageF > 20)
  80. {
  81. nowImageF %= total;
  82. nowImageF += 1;
  83. }
  84. }
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90.  
  91. void setup()
  92. {
  93. size(600, 800);
  94. frameRate(60);
  95.  
  96. btn();
  97. }
  98.  
  99.  
  100. void draw()
  101. {
  102. if(!func())
  103. {
  104. //
  105. String f = Integer.toString(nowImageF);
  106. String b = Integer.toString(nowImageB);
  107.  
  108. // print(f + "\n");
  109.  
  110. PImage imgFront = loadImage("image/" + "pic.jpg");
  111. PImage imgBack = loadImage("image/" + b + "b.jpg");
  112.  
  113. image(imgFront, 0, 0, 500, 400);
  114. image(imgBack, 0, 400, 500, 400);
  115. }
  116. }
Add Comment
Please, Sign In to add comment