Daryan997

Introduction to Programming - Week 3 [Example]

Jan 18th, 2026 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | Source Code | 0 0
  1. // Introduction to Programming
  2. // Week 3 – Interactive Shapes
  3.  
  4. void setup() {
  5.   size(500, 200);
  6. }
  7.  
  8. void draw() {
  9.   println(mouseX);
  10.   println(mouseY);
  11.   // Dark gray background
  12.   background(30, 30, 40);
  13.  
  14.   // 1) LEFT – CIRCLE
  15.   int cX = 100;
  16.   int cY = 100;
  17.   int cSize = 80;  // Diameter
  18.  
  19.   // Default dark gray
  20.   fill(80);
  21.  
  22.   // Pink
  23.   if (mouseX > cX && mouseY > cY) {
  24.     fill(237, 27, 118);    // Pink color
  25.   }
  26.  
  27.   noStroke();
  28.   circle(cX, cY, cSize);
  29.  
  30.   // 2) MIDDLE – RECTANGLE
  31.   int rX = 250;
  32.   int rY = 100;
  33.   int rW = 60;
  34.   int rH = 60;
  35.  
  36.   // Default dark gray
  37.   fill(80);
  38.  
  39.   // Green
  40.   if (mouseX > rX || mouseY > rY) {
  41.     fill(36, 159, 156);    // Green color
  42.   }
  43.  
  44.   rectMode(CENTER);
  45.   rect(rX, rY, rW, rH);
  46.  
  47.   // 3) RIGHT – TRIANGLE (outline always, fill when mouse on RIGHT 1/4)
  48.   int tX1 = 380, tY1 = 140;
  49.   int tX2 = 460, tY2 = 140;
  50.   int tX3 = 420, tY3 = 60;
  51.  
  52.   // Fill with green when mouse is pressed
  53.   if (mousePressed) {
  54.     fill(36, 159, 156);      // Green fill when condition true
  55.   } else {
  56.     stroke(237, 27, 118);      // Pink outline
  57.     noFill();
  58.   }
  59.  
  60.   triangle(tX1, tY1, tX2, tY2, tX3, tY3);
  61. }
Add Comment
Please, Sign In to add comment