Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /**
  2. * Tickle.
  3. *
  4. * The word "tickle" jitters when the cursor hovers over.
  5. * Sometimes, it can be tickled off the screen.
  6. */
  7.  
  8. String message = "tickle";
  9. float x, y; // X and Y coordinates of text
  10. float hr, vr; // horizontal and vertical radius of the text
  11.  
  12. void setup() {
  13. size(640, 360);
  14.  
  15. // Create the font
  16. textFont(createFont("SourceCodePro-Regular.ttf", 36));
  17. textAlign(CENTER, CENTER);
  18.  
  19. hr = textWidth(message) / 2;
  20. vr = (textAscent() + textDescent()) / 2;
  21. noStroke();
  22. x = width / 2;
  23. y = height / 2;
  24. }
  25.  
  26. void draw() {
  27. // Instead of clearing the background, fade it by drawing
  28. // a semi-transparent rectangle on top
  29. fill(204, 120);
  30. rect(0, 0, width, height);
  31.  
  32. // If the cursor is over the text, change the position
  33. if (abs(mouseX - x) < hr &&
  34. abs(mouseY - y) < vr) {
  35. x += random(-5, 5);
  36. y += random(-5, 5);
  37. }
  38. fill(0);
  39. text("tickle", x, y);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement