Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Introduction to Programming
- // Week 3 – Interactive Shapes
- void setup() {
- size(500, 200);
- }
- void draw() {
- println(mouseX);
- println(mouseY);
- // Dark gray background
- background(30, 30, 40);
- // 1) LEFT – CIRCLE
- int cX = 100;
- int cY = 100;
- int cSize = 80; // Diameter
- // Default dark gray
- fill(80);
- // Pink
- if (mouseX > cX && mouseY > cY) {
- fill(237, 27, 118); // Pink color
- }
- noStroke();
- circle(cX, cY, cSize);
- // 2) MIDDLE – RECTANGLE
- int rX = 250;
- int rY = 100;
- int rW = 60;
- int rH = 60;
- // Default dark gray
- fill(80);
- // Green
- if (mouseX > rX || mouseY > rY) {
- fill(36, 159, 156); // Green color
- }
- rectMode(CENTER);
- rect(rX, rY, rW, rH);
- // 3) RIGHT – TRIANGLE (outline always, fill when mouse on RIGHT 1/4)
- int tX1 = 380, tY1 = 140;
- int tX2 = 460, tY2 = 140;
- int tX3 = 420, tY3 = 60;
- // Fill with green when mouse is pressed
- if (mousePressed) {
- fill(36, 159, 156); // Green fill when condition true
- } else {
- stroke(237, 27, 118); // Pink outline
- noFill();
- }
- triangle(tX1, tY1, tX2, tY2, tX3, tY3);
- }
Add Comment
Please, Sign In to add comment