Guest User

Untitled

a guest
Dec 11th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. int [] backgroundColor = {128, 128, 128};
  2. int [] nowFillColor = {0, 0, 0};
  3.  
  4. void drawText(String s, int x, int y, int r, int g, int b)
  5. {
  6. fill(r, g, b);
  7. text(s, x, y);
  8. }
  9.  
  10. void functionArea()
  11. {
  12. strokeWeight(1);
  13. // red 0
  14. fill(255, 0, 0);
  15. rect(0, 0, 100, 100);
  16. // green 1
  17. fill(0, 255, 0);
  18. rect(0, 100, 100, 100); // 100 200
  19. // blue 2
  20. fill(0, 0, 255);
  21. rect(0, 200, 100, 100);// 100 300
  22. // yellow 3
  23. fill(255, 255, 0);
  24. rect(0, 300, 100, 100); // 100, 400
  25. // cyan 4
  26. fill(0, 255, 255);
  27. rect(0, 400, 100, 100); // 100, 500
  28. // purple 5
  29. fill(255, 0, 255);
  30. rect(0, 500, 100, 100);
  31.  
  32. //-----------------------------------
  33. // Draw Right function area
  34. textSize(16);
  35. // Clear button 750-800 0-50
  36. fill(255, 255, 255);
  37. rect(750, 0, 50, 50);
  38.  
  39. drawText("Clear", 755, 30, 255, 0, 0);
  40. //
  41. // Draw button
  42. fill(255, 255, 255);
  43. rect(750, 50, 50, 50); // y: 50-100
  44.  
  45. drawText("Eraser", 753, 80, 255, 0, 0);
  46. //
  47. // Draw size small x:750-800 y:150-200
  48. fill(255, 255, 255);
  49. rect(750, 150, 50, 50);
  50.  
  51. fill(0, 0, 0);
  52. ellipse(775, 175, 8, 8);
  53. //
  54. // Draw size big x:750-800 y:200-250
  55. fill(255, 255, 255);
  56. rect(750, 200, 50, 50);
  57.  
  58. fill(0, 0, 0);
  59. ellipse(775, 225, 16, 16);
  60. //
  61. // Draw save button
  62. fill(255, 255, 255);
  63. rect(750, 550, 50, 50);
  64.  
  65. drawText("Save", 760, 580, 255, 0, 0);
  66.  
  67. // Reset stroke weight
  68. stroke(0, 0, 0);
  69. strokeWeight(8);
  70. }
  71.  
  72. void setup() {
  73. size(800, 600);
  74. smooth();
  75. background(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
  76. functionArea();
  77. strokeWeight(8);
  78. }
  79.  
  80. int nowColor;
  81. boolean picked = false;
  82.  
  83.  
  84. void draw() {
  85. // Judge choose color
  86. if(mousePressed && mouseButton == LEFT)
  87. {
  88. // Red
  89. if(mouseX <= 100 && mouseY <= 100)
  90. {
  91. nowColor = 0;
  92. picked = true;
  93. }
  94. // Green
  95. else if(mouseX >= 0 && mouseX <= 100 && mouseY >= 100 && mouseY <= 200)
  96. {
  97. nowColor = 1;
  98. picked = true;
  99. }
  100. // Blue
  101. else if(mouseX >= 0 && mouseX <= 100 && mouseY >= 200 && mouseY <= 300)
  102. {
  103. nowColor = 2;
  104. picked = true;
  105. }
  106. // Yellow
  107. else if(mouseX >= 0 && mouseX <= 100 && mouseY >= 300 && mouseY <= 400)
  108. {
  109. nowColor = 3;
  110. picked = true;
  111. }
  112. // Cyan
  113. else if(mouseX >= 0 && mouseX <= 100 && mouseY >= 400 && mouseY <= 500)
  114. {
  115. nowColor = 4;
  116. picked = true;
  117. }
  118. // Purple
  119. else if(mouseX >= 0 && mouseX <= 100 && mouseY >= 500 && mouseY <= 600)
  120. {
  121. nowColor = 5;
  122. picked = true;
  123. }
  124. /// Right function area
  125. else if(mouseX >= 750)
  126. {
  127. // Clear
  128. if(mouseY <= 50)
  129. {
  130. background(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
  131. stroke(0, 0, 0);
  132. functionArea();
  133. }
  134. // Eraser
  135. else if(mouseY > 50 && mouseY <= 100)
  136. {
  137. //
  138. //stroke(0, 0, 0);
  139. nowColor = -1;
  140. picked = true;
  141. }
  142. // size small
  143. else if(mouseY > 150 && mouseY <= 200)
  144. {
  145. strokeWeight(8);
  146. }
  147. // size large
  148. else if(mouseY > 200 && mouseY <= 250)
  149. {
  150. strokeWeight(16);
  151. }
  152. else if(mouseY > 550 && mouseY <= 600)
  153. {
  154. //background(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
  155. save("pic.jpg");
  156. functionArea();
  157. }
  158. }
  159. // drawing
  160. else if(picked)
  161. {
  162. switch(nowColor)
  163. {
  164. // Eraser
  165. case -1:
  166. stroke(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
  167. break;
  168. //////////////
  169. // Color
  170. case 0:
  171. stroke(255, 0, 0);
  172. break;
  173.  
  174. case 1:
  175. stroke(0, 255, 0);
  176. break;
  177.  
  178. case 2:
  179. stroke(0, 0, 255);
  180. break;
  181.  
  182. case 3:
  183. stroke(255, 255, 0);
  184. break;
  185.  
  186. case 4:
  187. stroke(0, 255, 255);
  188. break;
  189.  
  190. case 5:
  191. stroke(255, 0, 255);
  192. break;
  193. }
  194. line(mouseX, mouseY, pmouseX, pmouseY);
  195. }
  196. }
  197. }
Add Comment
Please, Sign In to add comment