Daryan997

Introduction to Programming - Week 3 [Task]

Jan 18th, 2026 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | Source Code | 0 0
  1. // Introduction to Programming
  2. // Week 3 – Task: Interactive Circle Button
  3.  
  4. // 1) Create window 500 x 200
  5. // 2) Dark gray background: background(30, 30, 40);
  6. // 3) Draw ONE CIRCLE:
  7. //    - X = 250, Y = 100, diameter = 80 (Use variables to implement)
  8. //    - noStroke()
  9.  
  10. // 4) Use TWO if statements to set colors:
  11. //    a) DEFAULT: fill(80)  // dark gray
  12. //    b) HOVER: fill(36, 159, 156) when mouseX is greater than Circle X (OR) Circle Y
  13. //    c) CLICK: fill(237, 27, 118) when mouseX is greater than Circle X (AND) mousePressed
  14.  
  15. // 5) Test it:
  16. //    - Gray: default Color
  17. //    - Green: when mouseX is greater than Circle X (OR) Circle Y
  18. //    - Pink: when mouseX is greater than Circle X (AND) mousePressed
  19.  
  20.  
  21. // Introduction to Programmingwhen mouseX is greater than Circle X (AND) mousePressed
  22. // Week 3 – Task: Interactive Circle Button (Solution)
  23.  
  24. void setup() {
  25.   size(500, 200);
  26. }
  27.  
  28. void draw() {
  29.   background(30, 30, 40);  // Dark gray
  30.  
  31.   int cX = 250;
  32.   int cY = 100;
  33.   int cSize = 80;
  34.  
  35.   noStroke();
  36.  
  37.   // 1) Default gray
  38.   fill(80);
  39.  
  40.   // 2) Green when hovering
  41.   if (mouseX > cX || mouseY > cY) {
  42.     fill(36, 159, 156);    // Green
  43.   }
  44.  
  45.   // 3) Pink when hovering AND clicked (overrides green)
  46.   if (mouseX > cX && mousePressed) {
  47.     fill(237, 27, 118);    // Pink
  48.   }
  49.  
  50.   circle(cX, cY, cSize);
  51. }
Add Comment
Please, Sign In to add comment