Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Introduction to Programming
- // Week 3 – Task: Interactive Circle Button
- // 1) Create window 500 x 200
- // 2) Dark gray background: background(30, 30, 40);
- // 3) Draw ONE CIRCLE:
- // - X = 250, Y = 100, diameter = 80 (Use variables to implement)
- // - noStroke()
- // 4) Use TWO if statements to set colors:
- // a) DEFAULT: fill(80) // dark gray
- // b) HOVER: fill(36, 159, 156) when mouseX is greater than Circle X (OR) Circle Y
- // c) CLICK: fill(237, 27, 118) when mouseX is greater than Circle X (AND) mousePressed
- // 5) Test it:
- // - Gray: default Color
- // - Green: when mouseX is greater than Circle X (OR) Circle Y
- // - Pink: when mouseX is greater than Circle X (AND) mousePressed
- // Introduction to Programmingwhen mouseX is greater than Circle X (AND) mousePressed
- // Week 3 – Task: Interactive Circle Button (Solution)
- void setup() {
- size(500, 200);
- }
- void draw() {
- background(30, 30, 40); // Dark gray
- int cX = 250;
- int cY = 100;
- int cSize = 80;
- noStroke();
- // 1) Default gray
- fill(80);
- // 2) Green when hovering
- if (mouseX > cX || mouseY > cY) {
- fill(36, 159, 156); // Green
- }
- // 3) Pink when hovering AND clicked (overrides green)
- if (mouseX > cX && mousePressed) {
- fill(237, 27, 118); // Pink
- }
- circle(cX, cY, cSize);
- }
Add Comment
Please, Sign In to add comment