Advertisement
Guest User

Change letter fill on hover

a guest
Apr 8th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. float bx;
  2. float by;
  3. float ax;
  4. float ay;
  5. boolean overA = false;
  6. boolean overB = false;
  7. PFont f;
  8.  
  9. void setup() {
  10.   size(640, 360);
  11.   ax = 80;
  12.   ay = 80;
  13.   bx = 160;
  14.   by = 80;
  15.   f = createFont("Arial",20,true);
  16. }
  17.  
  18. void draw() {
  19.   background(0);
  20.   textFont(f);
  21.  
  22.   char a = 'X';
  23.   char b = 'D';
  24.   float cwA = textWidth(a);
  25.   float cwB = textWidth(b);
  26.  
  27.   // Text A
  28.   if (mouseX > ax-cwA/2.0 && mouseX < ax+cwA/2.0 &&
  29.       mouseY > ay-2*cwA && mouseY < ay) {
  30.     overA = true;  
  31.     fill(200);
  32.   } else {
  33.     fill(255);
  34.     overA = false;
  35.   }
  36.   text(a, ax-cwA/2.0, ay-cwA/2.0);
  37.  
  38.   // Text B
  39.   if (mouseX > bx-cwB/2.0 && mouseX < bx+cwB/2.0 &&
  40.       mouseY > by-2*cwB && mouseY < by) {
  41.     overB = true;  
  42.     fill(200);
  43.   } else {
  44.     fill(255);
  45.     overB = false;
  46.   }
  47.   text(b, bx-cwA/2.0, by-cwB/2.0);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement