Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float volume = 100, handleRot;
- PImage volumeImage, muteImage;
- float timer = 0; //controls how long the flush lasts
- void setup() {
- size(800, 800);
- volumeImage = loadImage("volume.png");
- muteImage = loadImage("mute.png");
- volumeImage.resize(50, 50);
- muteImage.resize(50, 50);
- }
- void draw() {
- scale(1.2, 1.2);
- rectMode(CENTER);
- background(255);
- noStroke();
- fill(255/2);
- rect(width/2, height/2 + 20, width, 80); //Large horizontal bar
- fill(255f * 3/4f);
- rect(width/2, height/2 - 100, 45, 200); //Dark bar behind volume bar
- fill(255);
- rect(width/2, height/2 - 100, 25, 180); //white volume bg bar
- rectMode(CORNER);
- fill(0, 255, 0);
- float v = map(volume, 0, 100, 0, 180);
- rect(width/2 - 25/2, height/2 - v - 10, 25, v); //volume bar
- if (volume > 0) {
- image(volumeImage, width/2 - 25, height/2 + 10);
- } else {
- image(muteImage, width/2 - 25, height/2 + 10);
- }
- drawHandle(width/2 - 50, height/2 + 20);
- if (volume < 100 && frameCount % 20 == 0 && timer == 0) { //only add volume if it's not already full & if a flush isn't happening
- volume++;
- }
- if (timer > 0) { //if timer is > 0 then decrement it and volume
- timer --;
- volume -= 1;
- if (volume < 0) {
- volume = 0;
- }
- }
- handleRot = lerp(handleRot, 0, .1f); //make the rotation of the handle always approach zero
- }
- void drawHandle(float x, float y) {
- pushMatrix();
- translate(x, y);
- rotate(handleRot);
- noStroke();
- fill(255 * 4f / 5f);
- ellipse(0, -15, 30, 30);
- rect(-50, -25, 50, 15);
- popMatrix();
- }
- void mousePressed() { //this has no concern for whether or not the mouse is on the plunger since it's fake lol
- handleRot = radians(-45);
- timer = 60;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement