Advertisement
Guest User

Toilet Volume (With comments)

a guest
Aug 7th, 2017
1,723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. float volume = 100, handleRot;
  2. PImage volumeImage, muteImage;
  3. float timer = 0; //controls how long the flush lasts
  4.  
  5. void setup() {
  6.   size(800, 800);
  7.   volumeImage = loadImage("volume.png");
  8.   muteImage = loadImage("mute.png");
  9.   volumeImage.resize(50, 50);
  10.   muteImage.resize(50, 50);
  11. }
  12.  
  13. void draw() {
  14.   scale(1.2, 1.2);
  15.   rectMode(CENTER);
  16.   background(255);
  17.  
  18.   noStroke();
  19.   fill(255/2);
  20.   rect(width/2, height/2 + 20, width, 80); //Large horizontal bar
  21.  
  22.   fill(255f * 3/4f);
  23.   rect(width/2, height/2 - 100, 45, 200); //Dark bar behind volume bar
  24.  
  25.   fill(255);
  26.   rect(width/2, height/2 - 100, 25, 180); //white volume bg bar
  27.  
  28.   rectMode(CORNER);
  29.   fill(0, 255, 0);
  30.   float v = map(volume, 0, 100, 0, 180);
  31.   rect(width/2 - 25/2, height/2 - v - 10, 25, v); //volume bar
  32.  
  33.   if (volume > 0) {
  34.     image(volumeImage, width/2 - 25, height/2 + 10);
  35.   } else {
  36.     image(muteImage, width/2 - 25, height/2 + 10);
  37.   }
  38.   drawHandle(width/2 - 50, height/2 + 20);
  39.  
  40.   if (volume < 100 && frameCount % 20 == 0 && timer == 0) { //only add volume if it's not already full & if a flush isn't happening
  41.     volume++;
  42.   }
  43.  
  44.   if (timer > 0) { //if timer is > 0 then decrement it and volume
  45.     timer --;
  46.     volume -= 1;
  47.     if (volume < 0) {
  48.       volume = 0;
  49.     }
  50.   }
  51.   handleRot = lerp(handleRot, 0, .1f); //make the rotation of the handle always approach zero
  52. }
  53.  
  54. void drawHandle(float x, float y) {
  55.   pushMatrix();
  56.   translate(x, y);
  57.   rotate(handleRot);
  58.   noStroke();
  59.   fill(255 * 4f / 5f);
  60.   ellipse(0, -15, 30, 30);
  61.   rect(-50, -25, 50, 15);
  62.   popMatrix();
  63. }
  64.  
  65. void mousePressed() { //this has no concern for whether or not the mouse is on the plunger since it's fake lol
  66.   handleRot = radians(-45);
  67.   timer = 60;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement