Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. class Button{
  2.  
  3. float bColor;
  4. float xPos, yPos;
  5. float bDiameter;
  6. PFont bFont;
  7. String bText;
  8.  
  9. Button() {
  10. bColor = 100;
  11. xPos = width/2;
  12. yPos = height/2;
  13. bDiameter = 100;
  14. bFont = createFont("Times New Roman", bDiameter/1.75);
  15. bText = "_";
  16. }
  17.  
  18. Button(float tColor, float txPos, float tyPos, float tDiameter) {
  19. bColor = tColor;
  20. xPos = txPos;
  21. yPos = tyPos;
  22. bDiameter = tDiameter;
  23. bFont = createFont("Times New Roman", bDiameter/1.75);
  24. }
  25.  
  26. Button(float tColor, float txPos, float tyPos, float tDiameter, String tText) {
  27. bColor = tColor;
  28. xPos = txPos;
  29. yPos = tyPos;
  30. bDiameter = tDiameter;
  31. bFont = createFont("Times New Roman", bDiameter/1.75);
  32. bText = tText;
  33. }
  34.  
  35. public void setColor(float tColor){
  36. this.bColor = tColor;
  37. }
  38.  
  39. public void setXPos(float txPos){
  40. this.xPos = txPos;
  41. }
  42.  
  43. public void setYPos(float tyPos){
  44. this.yPos = tyPos;
  45. }
  46.  
  47. public void setDiameter(float tDiameter){
  48. this.bDiameter = tDiameter;
  49. }
  50.  
  51. public void setText(String tText){
  52. this.bText = tText;
  53. }
  54.  
  55. void display() {
  56. ellipse(xPos, yPos, bDiameter, bDiameter);
  57. fill(0);
  58. textFont(bFont);
  59. textAlign(CENTER);
  60. if ( bText != null && !bText.isEmpty() )
  61. text (bText, xPos, yPos + bDiameter/5);
  62. }
  63.  
  64.  
  65. void display(String tText) {
  66. bText = tText;
  67. ellipse(xPos, yPos, bDiameter, bDiameter);
  68. fill(0);
  69. textFont(bFont);
  70. textAlign(CENTER);
  71. text (bText, xPos, yPos + bDiameter/5);
  72. }
  73.  
  74. void highlight(){
  75. if (overCircle() == true) {
  76. fill(bColor + 20);
  77. }
  78. else {
  79. fill(bColor);
  80. }
  81. }
  82.  
  83. boolean overCircle() {
  84. float disX = xPos - mouseX;
  85. float disY = yPos - mouseY;
  86. if (sqrt(sq(disX) + sq(disY)) < bDiameter/2 ) {
  87. return true;
  88. } else {
  89. return false;
  90. }
  91. }
  92.  
  93. }
  94.  
  95. class ButtonRect {
  96. float bColor;
  97. float xPos, yPos;
  98. float bLength, bWidth;
  99. PFont bFont;
  100. String bText;
  101.  
  102. ButtonRect() {
  103. bColor = 100;
  104. xPos = width/2;
  105. yPos = height/2;
  106. bLength = 40;
  107. bWidth = 20;
  108. bFont = createFont("Times New Roman", bLength*bWidth/1.75);
  109. }
  110.  
  111. ButtonRect(float tColor, float txPos, float tyPos, float tLength, float tWidth) {
  112. bColor = tColor;
  113. xPos = txPos;
  114. yPos = tyPos;
  115. bLength = tLength;
  116. bWidth = tWidth;
  117. bFont = createFont("Times New Roman", (bLength+bWidth/2)/1.75);
  118. }
  119.  
  120. ButtonRect(float tColor, float txPos, float tyPos, float tLength, float tWidth, String tText) {
  121. bColor = tColor;
  122. xPos = txPos;
  123. yPos = tyPos;
  124. bLength = tLength;
  125. bWidth = tWidth;
  126. bText = tText;
  127. bFont = createFont("Times New Roman", (bLength+bWidth/2)/2.25);
  128. }
  129.  
  130. public void setColor(float tColor){
  131. this.bColor = tColor;
  132. }
  133.  
  134. public void setXPos(float txPos){
  135. this.xPos = txPos;
  136. }
  137.  
  138. public void setYPos(float tyPos){
  139. this.yPos = tyPos;
  140. }
  141.  
  142. public void setLength(float tLength){
  143. this.bLength = tLength;
  144. }
  145.  
  146. public void setWidth(float tWidth){
  147. this.bWidth = tWidth;
  148. }
  149.  
  150. public void setText(String tText){
  151. this.bText = tText;
  152. }
  153.  
  154. void display() {
  155. rectMode(CENTER);
  156. rect(xPos, yPos, bLength, bWidth);
  157. fill(0);
  158. textFont(bFont);
  159. textAlign(CENTER);
  160. if ( bText != null && !bText.isEmpty() )
  161. text (bText, xPos, yPos + yPos/25);
  162. }
  163.  
  164. void display(String tText) {
  165. bText = tText;
  166. rectMode(CENTER);
  167. rect(xPos, yPos, bLength, bWidth);
  168. fill(0);
  169. textFont(bFont);
  170. textAlign(CENTER);
  171. text (bText, xPos, yPos + yPos/2);
  172. }
  173.  
  174. void highlight(){
  175. if (overRect() == true) {
  176. fill(bColor + 20);
  177. }
  178. else {
  179. fill(bColor);
  180. }
  181. }
  182.  
  183.  
  184.  
  185. boolean overRect() {
  186. if (mouseX >= xPos-bLength/2 && mouseX <= xPos+bLength/2 &&
  187. mouseY >= yPos-bWidth/2 && mouseY <= yPos+bWidth/2) {
  188. return true;
  189. } else {
  190. return false;
  191. }
  192. // https://www.processing.org/examples/button.html
  193. }
  194.  
  195.  
  196. }
  197.  
  198.  
  199. Button[] button;
  200.  
  201. class Question {
  202.  
  203. Question(){
  204. button = new Button[5];
  205. for (int i = 0; i < 5; i++) {
  206. button[i] = new Button();
  207. }
  208. for (Button button : button) {
  209. button.setColor(192);
  210. button.setDiameter(30);
  211. }
  212. button[0].setText("1");
  213. button[0].setXPos(width*2/9);
  214. button[0].setYPos(height*2/9);
  215.  
  216. button[1].setText("A");
  217. button[1].setXPos(width*3/9);
  218. button[1].setYPos(height*3.5/9);
  219.  
  220. button[2].setText("B");
  221. button[2].setXPos(width*3/9);
  222. button[2].setYPos(height/2);
  223.  
  224. button[3].setText("C");
  225. button[3].setXPos(width*3/9);
  226. button[3].setYPos(height*5.5/9);
  227.  
  228. button[4].setText("D");
  229. button[4].setXPos(width*3/9);
  230. button[4].setYPos(height*6.5/9);
  231.  
  232. for (Button button : button) {
  233. button.highlight();
  234. button.display();
  235. }
  236.  
  237. }
  238.  
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement