Here is a quick video of my processing code for a project I’m working on learning Java and processing!
Here is the code (you can see at the bottom where I had to comment out a segment that was causing the music to loop repeatedly over itself):
import processing.sound.*; SoundFile file;
boolean playing = false; PImage img;
void setup() { size(360, 640); background(17, 49, 76); frameRate(30);
file = new SoundFile(this, "Swan-lake-music-box.wav"); file.play();
img = loadImage("man-in-window.png"); }
void draw () {
//house fill(193, 195, 196); rect(85, 70, 200, 500);
line(85, 240, 285, 240);
//arm stroke(255); strokeWeight(2); line(285, 260, 300, 260); line(300, 260, 300, 270); line(300, 270, 315, 270); rect(310, 265, 20, 10); noStroke();
//roof stroke(0); strokeWeight(1); fill(255); rect(75, 55, 220, 40);
fill(104, 25, 44); rect(75, 70, 220, 10);
//top windows fill(255, 90); rect(110, 110, 60, 110);
fill(255, 90); rect(195, 110, 60, 110);
//middle windows fill(255); rect(110, 265, 60, 110);
fill(255); rect(195, 265, 60, 110);
//bottom skinny windows fill(255); rect(110, 420, 35, 80);
fill(255); rect(155, 420, 35, 80);
//door fill(110, 111, 113); rect(210, 400, 70, 140);
fill(104, 25, 44); rect(220, 430, 51, 110);
//doorwindow fill(255); rect(220, 410, 51, 15);
//steps fill(255); rect(200, 525, 90, 25);
fill(255); rect(195, 550, 100, 25);
if ((mouseX > 110) && (mouseX < 265) && (mouseY > 260) && (mouseY < 500)) { fill(163, 110, 217); rect(110, 420, 35, 80); rect(155, 420, 35, 80); rect(110, 265, 60, 110); rect(195, 265, 60, 110); } //song(); //(310, 265, 20, 10) if ((mouseX > 310) && (mouseX < 330) && (mouseY > 265) && (mouseY < 275) && (playing == false)) { file.play(); playing = true; // song(); // alternate to file.play } else if (!((mouseX > 310) && (mouseX < 330) && (mouseY > 265) && (mouseY < 275))){ file.pause(); playing = false; }
if ((mouseX > 110) && (mouseX < 170) && (mouseY > 110) && (mouseY < 220)) { image(img,0,0); } }
// void song() { // noLoop(); // if ((mouseX > 110) && (mouseX < 170) && (mouseY > 260) && (mouseY < 500)) { // file.play(); // } else if (!((mouseX > 110) && (mouseX < 170) && (mouseY > 260) && (mouseY < 500))){ // file.pause(); // } // }









