Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. // note: many imports aren't used yet
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4. import processing.core.PApplet;
  5. import processing.core.PShape;
  6.  
  7. import java.applet.*;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11. public class Main extends PApplet{
  12.  
  13. PShape rectangle;
  14.  
  15. String file = "";
  16.  
  17. char letter;
  18.  
  19. int color;
  20. int color2;
  21. int color3;
  22. boolean red = false;
  23. boolean blue = false;
  24. boolean green = false;
  25. boolean yellow = false;
  26. boolean eraser = false;
  27.  
  28. boolean saving = false;
  29.  
  30. // needed to create this in order for Eclipse to work
  31. public static void main(String[] args) {
  32. PApplet.main("Main");
  33. }
  34.  
  35. public void settings(){
  36. size(1280, 720);
  37. }
  38.  
  39. public void setup() {
  40. size(1280, 720);
  41. smooth();
  42. background(255, 255, 255);
  43. noStroke();
  44.  
  45. }
  46.  
  47. public void draw() {
  48.  
  49. if (keyPressed) {
  50.  
  51. if (key == 'c') {
  52. background(255, 255, 255);
  53. }
  54.  
  55. if (key == 's') {
  56. save("Drawing.tif");
  57.  
  58. }
  59.  
  60. }
  61. else {
  62. color = 0;
  63. }
  64. fill(0);
  65. text("Press 'c' to clear the screen", 50, 700, 200, 50);
  66. text("Press 's' to save", 250, 700, 200, 50);
  67.  
  68. fill(255, 0, 0);
  69. // red square
  70. rect(0, 50, 50, 50);
  71. fill(0, 10, 255);
  72. // blue square
  73. rect(0, 100, 50, 50);
  74. fill(0, 255, 40);
  75. // green square
  76. rect(0, 150, 50, 50);
  77. fill(255, 255, 0);
  78. // yellow square
  79. rect(0, 200, 50, 50);
  80. fill(0);
  81.  
  82.  
  83. }
  84.  
  85. public void mousePressed() {
  86. if(red) {
  87. color = 255;
  88. color2 = 0;
  89. color3 = 0;
  90. }
  91. if(eraser) {
  92. color = 255;
  93. color2 = 255;
  94. color3 = 255;
  95. }
  96. if(blue) {
  97. color = 0;
  98. color2 = 10;
  99. color3 = 255;
  100. }
  101. if(green){
  102. color = 0;
  103. color2 = 255;
  104. color3 = 40;
  105. }
  106. else{
  107. fill(0);
  108. }
  109. // check if mouse is in drawing area
  110. if (mouseX >= 50 && mouseX <= 1280 && mouseY >= 0 && mouseY <= 680) {
  111. // change the drawing color
  112. fill(color, color2, color3);
  113. rect(mouseX, mouseY, 50, 50);
  114. }
  115. // if red
  116. if (mouseX >= 0 && mouseX <= 50 && mouseY >= 50 && mouseY <= 100) {
  117. eraser = false;
  118. blue = false;
  119. green = false;
  120. red = true;
  121. }
  122. // if eraser (note: in top left corner)
  123. if (mouseX >= 0 && mouseX <= 50 && mouseY >= 0 && mouseY <= 50) {
  124. red = false;
  125. blue = false;
  126. green = false;
  127. eraser = true;
  128. }
  129. // if blue
  130. if (mouseX >= 0 && mouseX <=50 && mouseY >= 100 && mouseY <= 150) {
  131. eraser = false;
  132. red = false;
  133. green = false;
  134. blue = true;
  135. }
  136. // if green
  137. if (mouseX >= 0 && mouseY <= 50 && mouseY >= 150 && mouseY <= 200) {
  138. eraser = false;
  139. red = false;
  140. blue = false;
  141. green = true;
  142. }
  143. }
  144.  
  145. // basically the same code for mousePressed
  146. public void mouseDragged() {
  147. if(red) {
  148. color = 255;
  149. color2 = 0;
  150. color3 = 0;
  151. }
  152. if(eraser) {
  153. color = 255;
  154. color2 = 255;
  155. color3 = 255;
  156. }
  157. if(blue) {
  158. color = 0;
  159. color2 = 10;
  160. color3 = 255;
  161. }
  162. if(green){
  163. color = 0;
  164. color2 = 255;
  165. color3 = 40;
  166. }
  167. else{
  168. fill(0);
  169. }
  170. // check if mouse is in drawing area
  171. if (mouseX >= 50 && mouseX <= 1280 && mouseY >= 0 && mouseY <= 680) {
  172. // change the drawing color
  173. fill(color, color2, color3);
  174. rect(mouseX, mouseY, 50, 50);
  175. }
  176. // if red
  177. if (mouseX >= 0 && mouseX <= 50 && mouseY >= 50 && mouseY <= 100) {
  178. eraser = false;
  179. blue = false;
  180. green = false;
  181. red = true;
  182. }
  183. // if eraser (note: in top left corner)
  184. if (mouseX >= 0 && mouseX <= 50 && mouseY >= 0 && mouseY <= 50) {
  185. red = false;
  186. blue = false;
  187. green = false;
  188. eraser = true;
  189. }
  190. // if blue
  191. if (mouseX >= 0 && mouseX <=50 && mouseY >= 100 && mouseY <= 150) {
  192. eraser = false;
  193. red = false;
  194. green = false;
  195. blue = true;
  196. }
  197. // if green
  198. if (mouseX >= 0 && mouseY <= 50 && mouseY >= 150 && mouseY <= 200) {
  199. eraser = false;
  200. red = false;
  201. blue = false;
  202. green = true;
  203. }
  204. }
  205.  
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement