diff --git a/.vscode/launch.json b/.vscode/launch.json index 5f0c7af3b..2d13f0e56 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,6 +2,26 @@ "configurations": [ { "type": "java", +<<<<<<< HEAD + "name": "ambersVisual", + "request": "launch", + "mainClass": "C22400154.ambersVisual", +======= + "name": "MusicVisualizer", + "request": "launch", + "mainClass": "c22368271.MusicVisualizer", +>>>>>>> 8b3be4fbce12a731e0d2402b35d1105a3f8b5226 + "projectName": "java" + }, + { + "type": "java", + "name": "IriaVisual2", + "request": "launch", + "mainClass": "c22305863.IriaVisual2", + "projectName": "java" + }, + { + "type": "java", "name": "CodeLens (Launch) - Main", "request": "launch", "mainClass": "ie.tudublin.Main", diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..c995aa5ce --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/README.md b/README.md index 19ba88c75..0109e59db 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,33 @@ # Music Visualiser Project -Name: +Name:Wissam Hadjarab -Student Number: +Student Number: C21404706 +TU858/2 + +Name: Iria Parada Murciego + +Student Number: c22305863 + +github : iriaPM + +class group: TU 856 /2 + +Name: Amber Kane + +Student Number: C22400154 + +github : C22400154 + +class group: TU 856 /2 + +Name: Mymuna Alom Munma + +Student Number: C22368271 + +GitHub: mymunaalom + +Class Group: TU856/2 ## Instructions - Fork this repository and use it a starter project for your assignment @@ -12,78 +37,405 @@ Student Number: - Check out the WaveForm and AudioBandsVisual for examples of how to call the Processing functions from other classes that are not subclasses of PApplet # Description of the assignment +For our group assignment we chose to do the music visualiser as a team. We chose the squidward tiki song from spongebob for a more light hearted visiualizer and stuck to the theme of spongebob throughout the different images. # Instructions # How it works +Wissam -- +We initially worked on a seperate file each, one visiualiser each and designed and coded that section on our own. +For my file I included different elements whilst in line with the theme. I included a background of a grid along with an imported picture of the spongebob beach background too to give it more emphasis. +I created a outline of the screen to go in beat and pulse with the song with different altitudes and colour to give more dimention and a 'pop' to add something to the screen that will stand out and resemble to frequencies of the audio. +for (int i = 0; i < ab.size(); i++) { + float cx = width / 2; + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + float hue = map(i, 0, ab.size(), 0, 256); + float s = lerpedBuffer[i] * cx * 2; -# What I am most proud of in the assignment + // from left side to right + stroke(40, 255, 255); + line(0, i, s, i); + // from right side to left + line(width, i, width - s, i); + // from top to bottom + line(i, 0, i, s); + // from bottom to top + line(i, height, i, height - s); + +I also wanted to include a moving element onto the screen and tried to keep it with theme so I decided to make an ocean wave based on one frequency wave from the audio. I implented it so that it would take the width of third of the screeen and change the colour to represent the ocean. + + + // Ocean wave parameters + float waveSpeed = 0.0000000000000000001f; // Speed of the waves + float waveAmplitude = 10; // Amplitude of the waves + float waveFrequency = 0.025f; // Frequency of the waves + + for (int z = 0; z < width; z++) { + stroke(160, 255, 255); // HSB color (blue) + float waveHeight = sin(z * waveFrequency + off) * waveAmplitude; + line(z, height * 2 / 3 + waveHeight, z, height); // Drawing waves from the center of the canvas to the bottom + } +To encorperate another moving element, I wanted to put something across the screen as it seemed a bit empty. I included a class to bring another imported image of bananas and put them in an list to be called in a for loop to also be in line with the music using the amplitude and calling it in the display. +bananaPic = loadImage("banana_pic.png"); + bananas = new ArrayList(); -# Markdown Tutorial + bg = loadImage("spongeBG.png"); -This is *emphasis* + int numBananas = 30; + float bananaSpacing = width / (numBananas + 1); // calculate spacing between bananas + for (int i = 1; i <= numBananas; i++) { + float bananaX = i * bananaSpacing ; + bananas.add(new Banana(bananaX, 0)); // Add bananas to the list + } + int numBananas = 15; + float bananaSpacing = width / (numBananas + 1); // calculate spacing between tikis -This is a bulleted list -- Item -- Item + for (int i = 1; i <= numBananas; i++) { + float bananaX = i * bananaSpacing - 100; // Calculate X position -This is a numbered list + // move bananas with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + float bananaY = -amplitude * 0.5f; + float bananaSize = map(amplitude, 0, 50, 10, 50); -1. Item -1. Item + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); -This is a [hyperlink](http://bryanduggan.org) + } +![An image](images/WissamSS.png) -# Headings -## Headings -#### Headings -##### Headings +Iria -- +IriaVisual is composed of a background picture that everyone in the group has, to follow the spongebob theme; Then I have two sets of images one on the top half and the other one on the bottom half, they are tiki faces with a hawaiian skirt, these images are not directly from spongebob series but they are inspired by the ‘tikiland’ song sequence. I used PImage to display the images onto the screen, I Initialise them in a method called tiki_face(), using Pvector I was able to position the images where I wanted them to be and also allow them to move up and down with the music, using the amplitude variable and ab.size(); -This is code: +```java -```Java -public void render() -{ - ui.noFill(); - ui.stroke(255); - ui.rect(x, y, width, height); - ui.textAlign(PApplet.CENTER, PApplet.CENTER); - ui.text(text, x + width * 0.5f, y + height * 0.5f); -} + // move tiki with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8);// + PVector tikiPos = new PVector(tikiX, height / 12 + amplitude);// + PVector tikiPos2 = new PVector(tikiX, height / 1.50f + amplitude); + + // skirt + PVector skirtPos = new PVector(tikiX , height / 3.4f + amplitude); + PVector skirtPos2 = new PVector(tikiX , height / 1.14f + amplitude); +``` + +The coconuts are also a big part of this visual, when cliked via mouse/touchscreen a coconut will appear on the screen and fall then go back up, once it reaches the bottom twice the coconut disappears(doesnt go back up). For this effect, I created an array to store all the coconuts that appear on screen, I used a class called ‘Coconut’, I used Pvector to also position the coconuts. Inside this class I made a method called update(), this is the method that updates the coconut position to make it appear on screen, I used pushmatrix() to save the current position of the coconut, then I made the coconut using two ellipses one for the brown part and another one for the little hole on the top corner. To make them fall I add 3 to the yposition.and then used an if statement making it go back up once it reaches the bottom, but once it reaches it twice the coconut gets removed from the array. + +```java + + pushMatrix(); // save the current transformation matrix + translate(position.x, position.y); // translate to the coconut's position + noStroke(); + fill(360, 100, 36); + ellipse(0, 0, coconutSize, coconutSize); // draw coconut at the translated position + + // Draw small circle inside the coconut + float smallCircleSize = 20; + float smallCircleOffsetX = coconutSize / 2 - 30; + float smallCircleOffsetY = -coconutSize / 2 + 30; + fill(67, 37, 100); + ellipse(smallCircleOffsetX, smallCircleOffsetY, smallCircleSize, smallCircleSize); + + popMatrix(); // restore the previous transformation matrix + + // makes coconut falls down + position.y += 3; + if (position.y > height) { + position.y = 0; // coconut goes back up when it reaches the bottom + timesReachedEnd++; + } + if (timesReachedEnd >= 2) { + coconuts.remove(this); // remove coconut from the list if reached the end twice + } ``` -So is this without specifying the language: +For the coconuts to appear on screen I made a method(outside of the coconut class), that used the built-in mousepressed function in an if statement and so add a coconut to the array in the position of the mouse, using mouseX, mouseY. this function is then called in draw() and i use get() to to display the coconut. +```java + public void reactToMouseMovement() { + // make coconuts appear on screen when clicked by mouse + if (mousePressed) { + coconuts.add(new Coconut(new PVector(mouseX, mouseY)));// create new coconuts + add to list + } + } ``` -public void render() -{ - ui.noFill(); - ui.stroke(255); - ui.rect(x, y, width, height); - ui.textAlign(PApplet.CENTER, PApplet.CENTER); - ui.text(text, x + width * 0.5f, y + height * 0.5f); -} + +In the center of the screen I have several elements, for them I used the lerped buffer and smoothed amplitude that we used in the labs to make the shapes expand with the music. + +The first shape is a line that using a for loop and adding cos and sin into the parameters make it this cool shape, that expands with the bass of the music. I also have a circle behind it that in the same way expands as the music gets louder. inside this circle I have a line that makes a circle inside it formed by multiple lines that change color with the music. For the use of color I used the HSB mode. + +![An image](images/IriaSS.png) + +Amber -- +"ambersVisual" brings the beat of "Squidward's Tiki Land Psy-Trance Remix" to life with bouncing palm trees, floating clouds, and colorful flowers. The trees dance along with the song's rhythm, while clouds drift across the screen at random speeds. When the music drops, various colourful and vibrant flowers pop up, adding bursts of color to the scene. +The drawTree() function draws stylized trees using rectangles and Bezier curves. It consists of trunk and leaf shapes drawn with various vertices and Bezier curves to create a palm tree-like appearance. +```java + void drawTree(float x, float y, float scale) + { + //trunk + fill(55, 40, 28); + rect(x - 10 * scale, y, 20 * scale, 150 * scale); + + //leaves + fill(19, 128, 99); + + //topleft + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x - 50 * scale, y - 60 * scale, x - 70 * scale, y + 20 * scale, x - 50 * scale, y + 60 * scale); + bezierVertex(x - 20 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x, y); + endShape(CLOSE); + + //left + beginShape(); + vertex(x - 10 * scale, y); + bezierVertex(x - 80 * scale, y - 30 * scale, x - 90 * scale, y + 10 * scale, x - 70 * scale, y + 50 * scale); + bezierVertex(x - 30 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x - 10 * scale, y); + endShape(CLOSE); + + //right + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 80 * scale, y - 30 * scale, x + 90 * scale, y + 10 * scale, x + 70 * scale, y + 50 * scale); + bezierVertex(x + 30 * scale, y + 20 * scale, x + 40 * scale, y - 10 * scale, x + 10 * scale, y); + endShape(CLOSE); + //topright + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 50 * scale, y - 60 * scale, x + 80 * scale, y - 20 * scale, x + 50 * scale, y + 20 * scale); + bezierVertex(x + 20 * scale, y - 20 * scale, x + 30 * scale, y - 40 * scale, x + 10 * scale, y); + endShape(CLOSE); + } ``` +The Cloud class defines objects representing clouds in the visualization. Each cloud has properties like position, size, and speed, and methods for display and movement. The display() method draws the cloud using ellipse shapes, while the move() method updates the cloud's position. +```java + class Cloud + { + float x, y, size, speed; + Cloud(float x, float y, float size, float speed) + { + this.x = x; + this.y = y; + this.size = size; + this.speed = speed; + } + void display() + { + noStroke(); + fill(255); + float angleStep = TWO_PI / 10; + ellipse(x, y, size * 2, size * 0.8f); + for (float angle = 0; angle < TWO_PI; angle += angleStep) + { + float vx = x + cos(angle) * size; + float vy = y + sin(angle) * size * 0.5f; + ellipse(vx, vy, (float)(size * 0.8), (float)(size * 0.8)); + } + } + void move() + { + x += speed; + if (x > width + size / 2) + { + x = -size / 2; + } + } + } +``` +The Flower class represents individual flowers in the visualization. Each flower has properties like position, velocity, size, and color, and methods for updating and displaying. The update() method updates the flower's position, while the display() method draws the flower as a series of ellipse shapes. The startFlowers() function generates the 75 flowers with random attributes, adding them to the display for visual enhancement. +```java + public class Flower + { + float x, y; + float vx, vy; + float size; + int color; + + public Flower(float x, float y, float vx, float vy, float size, int color) + { + this.x = x; + this.y = y; + this.vx = vx * 2; + this.vy = vy * 2; + this.size = size; + this.color = color; + } + + public void update() + { + x += vx; + y += vy; + } + + public void display(PApplet p) + { + p.noStroke(); + p.fill(color); + float petalAngleIncrement = TWO_PI / 5; + for (int i = 0; i < 5; i++) { + float angle = i * petalAngleIncrement; + float petalX = x + cos(angle) * size * 0.8f; + float petalY = y + sin(angle) * size * 0.8f; + p.ellipse(petalX, petalY, size * 1.1f, size * 1.1f); + } + } + } + void startFlowers() + { + for (int i = 0; i < 75; i++) + { + float x = random(width); + float y = random(height); + float vx = random(-2, 2); + float vy = random(-2, 2); + float size = random(20, 40); + int color = color(random(255), random(255), random(255)); + flowers.add(new Flower(x, y, vx, vy, size, color)); + } + } +``` +These components collectively create an engaging audio visualization experience within the SpongeBob theme. -This is an image using a relative URL: +![An image](images/AmberSS.png) -![An image](images/p8.png) +Mymuna -- -This is an image using an absolute URL: +moonVisual brings you straight into Bikini Bottom, the mysterious flower's native to the town can be seen pulsing to the beat of Squidward's Tiki Land Psy-Trance Remix. +In the flowers() class, I used an image with a transparent background to bring it to life. To get the flowers to move with the song, I used the map function, and used my knowledge of angles to put them in a ring depending on the number of flowers used. -![A different image](https://bryanduggandotorg.files.wordpress.com/2019/02/infinite-forms-00045.png?w=595&h=&zoom=2) +```java -This is a youtube video: + public void flowers(float amplitude) { + int numflowers = 7; + float angleIn = TWO_PI / numflowers; -[![YouTube](http://img.youtube.com/vi/J2kHSSFA4NU/0.jpg)](https://www.youtube.com/watch?v=J2kHSSFA4NU) + float flowerSize = map(amplitude, 0, 1, 10, 100); -This is a table: + for (int i = 0; i < numflowers; i++) { + float angle = i * angleIn; + float radius = flowerSize * (i + 10); + float flowerPosX = width / 2 + cos(angle) * radius-100; + float flowerPosY = height / 2 + sin(angle) * radius-100; + image(flower, flowerPosX, flowerPosY, flower.width / 6, flower.height / 6); + } + } + +``` -| Heading 1 | Heading 2 | +The drawStrobeLights() function uses ellipses to create a ring of strobing lights of every colour in the rainbow! I hhave variables for the number of lights, the distance between each light, the radius of each ellipse, their coordinates, their size and, of course, their colours as well. I caluclated the colour of each ellipse based on the timing. The size of the ellipses change depending on the beat of the song, which I used smoothedAmplitude for. + +```java + + void drawStrobeLights() { + int numLights = 20; + float angleStep = TWO_PI / numLights; + float radius = min(width, height) * 0.4f; + float centerX = width / 2; + float centerY = height / 2; + + for (int i = 0; i < numLights; i++) { + + float x = centerX + cos(angleStep * i) * radius; + float y = centerY + sin(angleStep * i) * radius; + + + float lightSize = map(smoothedAmplitude, 0, 1, 10, 50); + + + int lightColor = color((frameCount + i * 10) % 255, 255, 255); + + + fill(lightColor); + stroke(lightColor); + + ellipse(x, y, lightSize, lightSize); + } + } + +``` + +Within the draw() method, I created the center square, which starts as black but eventually fills with different colours and gradually increases in size with the beat of the song. For this, I used Fast Fourier Transforms and Bands. I got the waveAmplitude using the map() function, which is used to get the coordinates of the wave in the square. + +```java + + float squareSize = map(smoothedAmplitude, 0, 1, 10, 400); + float squareX = width / 2 - squareSize / 2; + float squareY = height / 2 - squareSize / 2; + int rainbowColor = color((frameCount / 2) % 255, (frameCount / 3) % 255, (frameCount / 4) % 255); + stroke(rainbowColor); + fill(0); + rect(squareX, squareY, squareSize, squareSize); + + float waveAmplitude = map(smoothedAmplitude, 0, 1, 0, squareSize / 2); + fft.forward(ap.mix); + for (int i = 0; i < fft.specSize(); i++) { + float x = map(i, 0, fft.specSize(), squareX, squareX + squareSize); + float y = squareY + squareSize / 2 + fft.getBand(i) * waveAmplitude; + point(x, y); + } + +``` +I also found a background of Bikini Bottom, which we all applied to our visuals to make them all flow into each other! + +![An image](images/MymunaSS.png) + + + +# List of classes/assets in the project +| Class/asset | Source | |-----------|-----------| -|Some stuff | Some more stuff in this column | -|Some stuff | Some more stuff in this column | -|Some stuff | Some more stuff in this column | -|Some stuff | Some more stuff in this column | +|Squidward's Tiki Land Psy-Trance Remix.mp3 |From Youtube | +|Tiki_face.png| from google images| +|skirt.png | from google images| +|bg.png |from spongebob| +|Coconut class| Self written| +|banana_pic.png | from google images| +|banana class | Self written | + + +![An image](java/data/tiki_face3.png) +![An image](java/data/skirt.png) +![An image](java/data/spongeBG.png) + +| Class/asset | Source | +|-----------|-----------| +|Squidward's Tiki Land Psy-Trance Remix.mp3 |From Youtube | +|Cloud class | Self written | +|Flower class | Self written | + +# What I am most proud of in the assignment +Wissam - +Undergoing this assignment, I am proud to have learned a lot of things. +In regards to the group, I am proud of the teaming working together. We didn't have specific roles but all managed our tasks together in an organized manner and set up different forms of communication like group chats and OneNote combined pages to address all our roles and make sure we were all handling our tasks to get it done. +I am proud of learning more aspects to coding, in group and individual and learn more about functions and classes, how to efficiently use them in the code and to make sure the code is neat for all other group members to understand. I like how my visual turned out, if I had enough time I would go back an adjust small things but I am happy that it was in line with our team and was very fun getting to create something from scratch and exploring new, different and interactive ways of coding. + +Iria — +Being honest, I am very proud about the overall visual that I made, I really like the shapes in the center and the cool effect they have especially as the music gets louder and they expand and you can see them clearly; But I am very proud about figuring out the coconuts part, I like that it makes the visualiser interactive. This was the hardest element for me as I couldnt figure out how to do this effect, at the start I coudnt get the coconuts to look properly, also at the start they would appear at random points, and then I wanted to change it to make it more interacte, thats when i made the array to make as many as the user wants and also remove then from the screen. +Another thing I am proud of is figuring out how to display all of the teams files together. We had been trying for days to make the switch statement in "ourvisuals.java" work but it just didn't, so last minute I made a new file and I separated the draw() from each file into a new methos in the new “allfiles.java” file to display them all from the same file. + +Amber -- +What I'm really proud of in this assignment is how well everything fits together. The way the visuals, like the bouncing trees and drifting clouds, match up with the music creates a really fun experience. It took some work to get it just right, but seeing it all come together and capture the vibe of SpongeBob SquarePants makes me feel proud about what I've done. + +Mymuna -- +I'm really proud of myself as I find OOP to be one of the hardest and demanding module's yet. I would spend hours on the labs, and I'm so happy that I was able to pump out a visual like the one I created. It took me a long time to figure out the flowers and how to get them perfect, I probably fiddled with them for a few days, and when I finally got them how I wanted it, I was elated. I'm just so incredibly proud of myself for being able to complete this project, and I'm happy I was able to do it with my friends :) + +# What I learned +Wissam - +During the duration of this assignment I learned a variety of different things that took me a while to grasp including github. I would say that was my biggest obstacle to overcome and I still have a lot to learn but it was good have experience with it for the first time and got me to start using it. +I learned as well fully the difference between classes and functions whilst I was setting up other elements of my visualiser as I had issues getting it to be called in the display function but worked eventually when I split the code to be in my main function and encorperated the claass. +I also got to learn more about using external data, such as the images and sound and using it in my code and could manipulate it to do different things which I found to be cool especially with the music. + +Iria - +In the process of this assignment I learned a lot more about github, like the use of branches, which we struggled at the start but we figured it out anyway. In terms of programming, it also took me some time to fully understand how all the coordinates work, although we used them in the labs, making my own shapes forced me to know how to position shapes besides being in the center of the screen. I feel like creating the shape that I wanted also forced me to use some maths concepts such as sin and cos, to make a line look like a circle or like a flower. + +Amber -- +Java is not my strong suit however, I feel like I learned a lot throughout this project. I learned more about GitHub, especially how to use branches, though it was tough at first. In programming, understanding coordinates took me some time. Making my own shapes made me figure out how to position them properly on the screen as well as altering the speeds, sizes and perfecting the colours I wanted. + +Mymuna -- +I had little to no knowledge on GitHub before this project, and the little I did have was from the previous labs. In doing this project I learned a lot about it though. One thing I struggled a lot with during this project was committing, as I would always get merge conflicts and it would take me a long time to solve them. But as I progressed more and my knowledge evolved, I found myself getting less of them when I committed. This is a simple skill that I will use a lot in the future, and I'm glad I learned it from this project. + +[![YouTube](http://img.youtube.com/vi/-O0H-4Jyv44/0.jpg)](https://www.youtube.com/watch?v=-O0H-4Jyv44) + + diff --git a/images/AmberSS.png b/images/AmberSS.png new file mode 100644 index 000000000..2711e76d7 Binary files /dev/null and b/images/AmberSS.png differ diff --git a/images/IriaSS.png b/images/IriaSS.png new file mode 100644 index 000000000..746abe996 Binary files /dev/null and b/images/IriaSS.png differ diff --git a/images/MymunaSS.png b/images/MymunaSS.png new file mode 100644 index 000000000..b8cbddfa1 Binary files /dev/null and b/images/MymunaSS.png differ diff --git a/images/WissamSS.png b/images/WissamSS.png new file mode 100644 index 000000000..249d8e3a7 Binary files /dev/null and b/images/WissamSS.png differ diff --git a/java/.project b/java/.project index 0d5afed93..38d32a1a1 100644 --- a/java/.project +++ b/java/.project @@ -16,12 +16,12 @@ - 1616413840733 + 1710347678049 30 org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ diff --git a/java/data/Squidward's Tiki Land Psy-Trance Remix.mp3 b/java/data/Squidward's Tiki Land Psy-Trance Remix.mp3 new file mode 100644 index 000000000..eaab33df0 Binary files /dev/null and b/java/data/Squidward's Tiki Land Psy-Trance Remix.mp3 differ diff --git a/java/data/banana_pic.png b/java/data/banana_pic.png new file mode 100644 index 000000000..172b3a626 Binary files /dev/null and b/java/data/banana_pic.png differ diff --git a/java/data/skirt.png b/java/data/skirt.png new file mode 100644 index 000000000..6c9b60918 Binary files /dev/null and b/java/data/skirt.png differ diff --git a/java/data/song.mp3 b/java/data/song.mp3 new file mode 100644 index 000000000..c1ad90f3e Binary files /dev/null and b/java/data/song.mp3 differ diff --git a/java/data/spongeBG.png b/java/data/spongeBG.png new file mode 100644 index 000000000..5758ec248 Binary files /dev/null and b/java/data/spongeBG.png differ diff --git a/java/data/spongeFlower.png b/java/data/spongeFlower.png new file mode 100644 index 000000000..e1572f145 Binary files /dev/null and b/java/data/spongeFlower.png differ diff --git a/java/data/tiki_face3.png b/java/data/tiki_face3.png new file mode 100644 index 000000000..add568f9c Binary files /dev/null and b/java/data/tiki_face3.png differ diff --git a/java/src/C22400154/ambersVisual.java b/java/src/C22400154/ambersVisual.java new file mode 100644 index 000000000..f878bffee --- /dev/null +++ b/java/src/C22400154/ambersVisual.java @@ -0,0 +1,290 @@ +package C22400154; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import java.util.ArrayList; + + + + +public class ambersVisual extends PApplet +{ + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + + int mode = 0;// default mode for switch statement + + float[] lerpedBuffer; + float y = 0; // vertical position + float ySpeed = 2; + float smoothedY = 0; + float smoothedAmplitude = 0; + float outsideRadius = 150; + float insideRadius = 100; + + ArrayList clouds; + ArrayList flowers; + boolean flowersStarted = false; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + + switch (mode) { + case 0: + draw(); + break; + + default: + break; + } + + } + + public void settings() { + size(1024, 600, P3D); + // fullScreen(P3D, SPAN); + // size(1024,700); + } + + public void setup() { + minim = new Minim(this); + // Uncomment this to use the microphone + // ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + // am = ai.mix; + ap = minim.loadFile("Squidward's Tiki Land Psy-Trance Remix.mp3", 1024); + + ap.play(); + ab = ap.mix; + colorMode(RGB, 255); + + y = height / 2; + smoothedY = y; + + lerpedBuffer = new float[width]; + + clouds = new ArrayList(); + + for (int i = 0; i < 5; i++) { + clouds.add(new Cloud(random(width), random(height * 0.2f), random(50, 100), random(1, 3))); + + } + + flowers = new ArrayList(); + + } + + float off = 0; + + public void draw() + { + float average = 0; + float sum = 0; + off += 1; + + for (int i = 0; i < ab.size(); i++) + { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + background(152, 193, 217); + + float averageAmplitude = getAverageAmplitude(ab); + + float treeX1 = width / 4; + float treeX2 = width * 3 / 4; + + float treeY1 = map(averageAmplitude, 0, 1, height * 0.7f, height * 0.9f); + float treeY2 = map(averageAmplitude, 0, 1, height * 0.7f, height * 0.9f); + + for (Cloud c : clouds) + { + c.move(); + c.display(); + } + + drawTree(treeX1, treeY1, 1.5f); + drawTree(treeX2, treeY2, 1.5f); + + if (ap.isPlaying()) + { + int currentPosition = ap.position(); + if (currentPosition >= 19000 && currentPosition < 45000) + { + int timeInterval = currentPosition - 19000; + if (timeInterval % 7000 <= 40) + { + startFlowers(); + } + } + + } + + for (Flower flower : flowers) + { + flower.update(); + flower.display(this); + } + + + + } + + float getAverageAmplitude(AudioBuffer buffer) { + float sum = 0; + for (int i = 0; i < buffer.size(); i++) { + sum += abs(buffer.get(i)); + } + return sum / buffer.size(); + } + + void drawTree(float x, float y, float scale) + { + //trunk + fill(55, 40, 28); + rect(x - 10 * scale, y, 20 * scale, 150 * scale); + + //leaves + fill(19, 128, 99); + + //topleft + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x - 50 * scale, y - 60 * scale, x - 70 * scale, y + 20 * scale, x - 50 * scale, y + 60 * scale); + bezierVertex(x - 20 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x, y); + endShape(CLOSE); + + //left + beginShape(); + vertex(x - 10 * scale, y); + bezierVertex(x - 80 * scale, y - 30 * scale, x - 90 * scale, y + 10 * scale, x - 70 * scale, y + 50 * scale); + bezierVertex(x - 30 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x - 10 * scale, y); + endShape(CLOSE); + + //right + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 80 * scale, y - 30 * scale, x + 90 * scale, y + 10 * scale, x + 70 * scale, y + 50 * scale); + bezierVertex(x + 30 * scale, y + 20 * scale, x + 40 * scale, y - 10 * scale, x + 10 * scale, y); + endShape(CLOSE); + + //topright + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 50 * scale, y - 60 * scale, x + 80 * scale, y - 20 * scale, x + 50 * scale, y + 20 * scale); + bezierVertex(x + 20 * scale, y - 20 * scale, x + 30 * scale, y - 40 * scale, x + 10 * scale, y); + endShape(CLOSE); + } + + class Cloud + { + float x, y, size, speed; + + Cloud(float x, float y, float size, float speed) + { + this.x = x; + this.y = y; + this.size = size; + this.speed = speed; + } + + void display() + { + noStroke(); + fill(255); + float angleStep = TWO_PI / 10; + ellipse(x, y, size * 2, size * 0.8f); + for (float angle = 0; angle < TWO_PI; angle += angleStep) + { + float vx = x + cos(angle) * size; + float vy = y + sin(angle) * size * 0.5f; + ellipse(vx, vy, (float)(size * 0.8), (float)(size * 0.8)); + } + } + + void move() + { + x += speed; + if (x > width + size / 2) + { + x = -size / 2; + } + } + } + + public class Flower + { + float x, y; + float vx, vy; + float size; + int color; + + public Flower(float x, float y, float vx, float vy, float size, int color) + { + this.x = x; + this.y = y; + this.vx = vx * 2; + this.vy = vy * 2; + this.size = size; + this.color = color; + } + + public void update() + { + x += vx; + y += vy; + } + + public void display(PApplet p) + { + p.noStroke(); + p.fill(color); + float petalAngleIncrement = TWO_PI / 5; + for (int i = 0; i < 5; i++) { + float angle = i * petalAngleIncrement; + float petalX = x + cos(angle) * size * 0.8f; + float petalY = y + sin(angle) * size * 0.8f; + p.ellipse(petalX, petalY, size * 1.1f, size * 1.1f); + } + } + } + + void startFlowers() + { + for (int i = 0; i < 75; i++) + { + float x = random(width); + float y = random(height); + float vx = random(-2, 2); + float vy = random(-2, 2); + float size = random(20, 40); + int color = color(random(255), random(255), random(255)); + flowers.add(new Flower(x, y, vx, vy, size, color)); + } + } + + + + public static void main(String[] args) + { + PApplet.main("C22400154.ambersVisual"); + } + +} \ No newline at end of file diff --git a/java/src/C22400154/temp.java b/java/src/C22400154/temp.java new file mode 100644 index 000000000..cabbb3737 --- /dev/null +++ b/java/src/C22400154/temp.java @@ -0,0 +1,279 @@ +package C22400154; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import java.util.ArrayList; + + + + +public class ambersVisual extends PApplet +{ + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + + int mode = 0;// default mode for switch statement + + float[] lerpedBuffer; + float y = 0; // vertical position + float ySpeed = 2; + float smoothedY = 0; + float smoothedAmplitude = 0; + float outsideRadius = 150; + float insideRadius = 100; + + ArrayList clouds; + ArrayList flowers; + boolean flowersStarted = false; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + + switch (mode) { + case 0: + draw(); + break; + + default: + break; + } + + } + + public void settings() { + size(1024, 600, P3D); + // fullScreen(P3D, SPAN); + // size(1024,700); + } + + public void setup() { + minim = new Minim(this); + // Uncomment this to use the microphone + // ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + // am = ai.mix; + ap = minim.loadFile("Squidward's Tiki Land Psy-Trance Remix.mp3", 1024); + + ap.play(); + ab = ap.mix; + colorMode(RGB, 255); + + y = height / 2; + smoothedY = y; + + lerpedBuffer = new float[width]; + + clouds = new ArrayList(); + + for (int i = 0; i < 5; i++) { + clouds.add(new Cloud(random(width), random(height * 0.2f), random(50, 100), random(1, 3))); + + } + + flowers = new ArrayList(); + + + } + + float off = 0; + + public void draw() + { + float average = 0; + float sum = 0; + off += 1; + + for (int i = 0; i < ab.size(); i++) + { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + background(152, 193, 217); + + float averageAmplitude = getAverageAmplitude(ab); + + float treeX1 = width / 4; + float treeX2 = width * 3 / 4; + + float treeY1 = map(averageAmplitude, 0, 1, height * 0.7f, height * 0.9f); + float treeY2 = map(averageAmplitude, 0, 1, height * 0.7f, height * 0.9f); + + for (Cloud c : clouds) + { + c.move(); + c.display(); + } + + drawTree(treeX1, treeY1, 1.5f); + drawTree(treeX2, treeY2, 1.5f); + + if (ap.isPlaying() && ap.position() >= 19000 && !flowersStarted) + { + flowersStarted = true; + startFlowers(); + } + + for (Flower flower : flowers) + { + flower.update(); + flower.display(this); + } + + } + + float getAverageAmplitude(AudioBuffer buffer) { + float sum = 0; + for (int i = 0; i < buffer.size(); i++) { + sum += abs(buffer.get(i)); + } + return sum / buffer.size(); + } + + void drawTree(float x, float y, float scale) + { + //trunk + fill(55, 40, 28); + rect(x - 10 * scale, y, 20 * scale, 150 * scale); + + //leaves + fill(19, 128, 99); + + //topleft + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x - 50 * scale, y - 60 * scale, x - 70 * scale, y + 20 * scale, x - 50 * scale, y + 60 * scale); + bezierVertex(x - 20 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x, y); + endShape(CLOSE); + + //left + beginShape(); + vertex(x - 10 * scale, y); + bezierVertex(x - 80 * scale, y - 30 * scale, x - 90 * scale, y + 10 * scale, x - 70 * scale, y + 50 * scale); + bezierVertex(x - 30 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x - 10 * scale, y); + endShape(CLOSE); + + //right + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 80 * scale, y - 30 * scale, x + 90 * scale, y + 10 * scale, x + 70 * scale, y + 50 * scale); + bezierVertex(x + 30 * scale, y + 20 * scale, x + 40 * scale, y - 10 * scale, x + 10 * scale, y); + endShape(CLOSE); + + //topright + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 50 * scale, y - 60 * scale, x + 80 * scale, y - 20 * scale, x + 50 * scale, y + 20 * scale); + bezierVertex(x + 20 * scale, y - 20 * scale, x + 30 * scale, y - 40 * scale, x + 10 * scale, y); + endShape(CLOSE); + } + + class Cloud + { + float x, y, size, speed; + + Cloud(float x, float y, float size, float speed) + { + this.x = x; + this.y = y; + this.size = size; + this.speed = speed; + } + + void display() + { + noStroke(); + fill(255); + float angleStep = TWO_PI / 10; + ellipse(x, y, size * 2, size * 0.8f); + for (float angle = 0; angle < TWO_PI; angle += angleStep) + { + float vx = x + cos(angle) * size; + float vy = y + sin(angle) * size * 0.5f; + ellipse(vx, vy, (float)(size * 0.8), (float)(size * 0.8)); + } + } + + void move() + { + x += speed; + if (x > width + size / 2) + { + x = -size / 2; + } + } + } + + public class Flower + { + float x, y; + float vx, vy; + float size; + int color; + + public Flower(float x, float y, float vx, float vy, float size, int color) + { + this.x = x; + this.y = y; + this.vx = vx * 2; + this.vy = vy * 2; + this.size = size; + this.color = color; + } + + public void update() + { + x += vx; + y += vy; + } + + public void display(PApplet p) + { + p.noStroke(); + p.fill(color); + float petalAngleIncrement = TWO_PI / 5; // Divide the circle into 5 equal parts for the petals + + for (int i = 0; i < 5; i++) { + float angle = i * petalAngleIncrement; + float petalX = x + cos(angle) * size * 0.8f; // Adjust the multiplier for the position of circles + float petalY = y + sin(angle) * size * 0.8f; + p.ellipse(petalX, petalY, size * 1.1f, size * 1.1f); // Adjust the size of circles as needed + } + } + } + + void startFlowers() + { + for (int i = 0; i < 100; i++) { + float x = random(width); + float y = random(height); + float vx = random(-2, 2); + float vy = random(-2, 2); + float size = random(10, 30); + int color = color(random(255), random(255), random(255)); + flowers.add(new Flower(x, y, vx, vy, size, color)); + } + } + + public static void main(String[] args) + { + PApplet.main("C22400154.ambersVisual"); + } + +} \ No newline at end of file diff --git a/java/src/c123456/BryansVisual.java b/java/src/c123456/BryansVisual.java index e69de29bb..1fa06045e 100644 --- a/java/src/c123456/BryansVisual.java +++ b/java/src/c123456/BryansVisual.java @@ -0,0 +1,9 @@ +//hello + +//ur mum +//hello im iria + +//hi im moon + +//amberr +//hi im moon again \ No newline at end of file diff --git a/java/src/c21404706/wissamVisual.java b/java/src/c21404706/wissamVisual.java new file mode 100644 index 000000000..d117f0732 --- /dev/null +++ b/java/src/c21404706/wissamVisual.java @@ -0,0 +1,236 @@ + +package c21404706; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.*; +import ie.tudublin.*; +import processing.core.*; +import java.util.ArrayList; + +public class wissamVisual extends PApplet { + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + + int mode = 0; + + float[] lerpedBuffer; + float y = 0; + float smoothedY = 0; + float smoothedAmplitude = 0; + + PImage bananaPic; + PImage bg; + ArrayList bananas; + + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + + public void settings() { + //size(1024, 1000, P3D); + size(1024, 600, P3D); + // fullScreen(P3D, SPAN); + } + + public void setup() { + minim = new Minim(this); + // Uncomment this to use the microphone + // ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + // ab = ai.mix; + ap = minim.loadFile("Squidward's Tiki Land Psy-Trance Remix.mp3", 1024); + ap.play(); + ab = ap.mix; + colorMode(HSB); + + y = height / 2; + smoothedY = y; + + lerpedBuffer = new float[width]; + + bananaPic = loadImage("banana_pic.png"); + bananas = new ArrayList(); + + bg = loadImage("spongeBG.png"); + + int numBananas = 30; + float bananaSpacing = width / (numBananas + 1); // calculate spacing between bananas + for (int i = 1; i <= numBananas; i++) { + float bananaX = i * bananaSpacing ; + bananas.add(new Banana(bananaX, 0)); // Add bananas to the list + } + } + + float off = 0; + + public void visiual() { + + for (int i = 0; i < ab.size(); i++) { + float cx = width / 2; + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + float hue = map(i, 0, ab.size(), 0, 256); + float s = lerpedBuffer[i] * cx * 2; + + // from left side to right + stroke(40, 255, 255); + line(0, i, s, i); + // from right side to left + line(width, i, width - s, i); + // from top to bottom + line(i, 0, i, s); + // from bottom to top + line(i, height, i, height - s); + } + + int gridSize = 40; + + for (int x = gridSize; x <= width - gridSize; x += gridSize) { + for (int y = gridSize; y <= height - gridSize; y += gridSize) { + noStroke(); + fill(255); + rect(x-1, y-1, 3, 3); + stroke(255, 100); + line(x, y, width/2, height/2); + } + } + + int num = 60; + float mx[] = new float[num]; + float my[] = new float[num]; + + // Cycle through the array, using a different entry on each frame. + // Using modulo (%) like this is faster than moving all the values over. + int which = frameCount % num; + mx[which] = mouseX; + my[which] = mouseY; + + for (int i = 0; i < num; i++) { + // which+1 is the smallest (the oldest in the array) + int index = (which+1 + i) % num; + ellipse(mx[index], my[index], i, i); + } + + int x; + int y; + float outsideRadius = 150; + float insideRadius = 100; + + int numPoints = (int) map((float) mouseX, 0, (float) width, 6, 60); + float angle = 0; + float angleStep = 180.0f/num; + + // Ocean wave parameters + float waveSpeed = 0.0000000000000000001f; // Speed of the waves + float waveAmplitude = 10; // Amplitude of the waves + float waveFrequency = 0.025f; // Frequency of the waves + + for (int z = 0; z < width; z++) { + stroke(160, 255, 255); // HSB color (blue) + float waveHeight = sin(z * waveFrequency + off) * waveAmplitude; + line(z, height * 2 / 3 + waveHeight, z, height); // Drawing waves from the center of the canvas to the bottom + } + + off += waveSpeed; // Incrementing the offset for the waves animation + + int numBananas = 15; + float bananaSpacing = width / (numBananas + 1); // calculate spacing between tikis + + + for (int i = 1; i <= numBananas; i++) { + float bananaX = i * bananaSpacing - 100; // Calculate X position + + // move bananas with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + float bananaY = -amplitude * 0.5f; + float bananaSize = map(amplitude, 0, 50, 10, 50); + + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + + } + + } + + + public void draw() { + image(bg,0,0,width,height); + float halfH = height / 2; + float average = 0; + float sum = 0; + off += 1; + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + float cx = width / 2; + float cy = height / 2; + + for (Banana banana : bananas) { + banana.display(); + } + + + //calling outline for visiual + visiual(); + } + + class Banana { + float x, y; + int timesReachedEnd; + + Banana(float x, float y) { + this.x = x; + this.y = y; + timesReachedEnd = 0; + } + + void display() { + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + float bananaX = x * (width / 1024.0f); // Adjust x position for different screen widths + float bananaY = y * (height / 600.0f); + float bananaSize = map(amplitude, 0, 50, 10, 50); + + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + image(bananaPic, x, bananaY, bananaSize, bananaSize * 2); + + y += 2; + if (y > height) { + y = 0; // coconut goes back up when it reaches the bottom + timesReachedEnd++; + } + if (timesReachedEnd >= 2) { + bananas.remove(this); // remove coconut from the list if reached the end twice + } + } + } + + + + + + + +} \ No newline at end of file diff --git a/java/src/c22305863/IriaVis.java b/java/src/c22305863/IriaVis.java new file mode 100644 index 000000000..941ad07e3 --- /dev/null +++ b/java/src/c22305863/IriaVis.java @@ -0,0 +1,191 @@ +package c22305863; + +import ie.tudublin.OurVisual; +import ie.tudublin.VisualException; +import processing.core.*; +import java.util.ArrayList; + +import ddf.minim.*; + + +// This is an example of a visual that renders the waveform +public class IriaVis extends PApplet { + OurVisual mv; + float cy = 0; + private AudioBuffer ab; + float[] lerpedBuffer; + float y = 0; // vertical position + float ySpeed = 2; + float smoothedY = 0; + float smoothedAmplitude = 0; + float outsideRadius = 150; + float insideRadius = 100; + float off = 0; + + ArrayList coconuts = new ArrayList(); // array to store coconuts + PImage tikiface; + PVector tikiPos; + + public IriaVis(OurVisual mv) { + this.mv = mv; + this.ab = mv.getAudioBuffer(); + cy = this.mv.height / 2; + y = height / 2; + smoothedY = y; + + lerpedBuffer = new float[width]; + // Minim minim = new Minim(this); + // // AudioPlayer player = minim.loadFile("your_audio_file.mp3"); // Replace "your_audio_file.mp3" with your audio file path + // // ab = player.mix; + // AudioPlayer player = minim.loadFile("your_audio_file.mp3"); // Replace "your_audio_file.mp3" with your audio file path + // if (player != null && player.isPlaying()) { + // ab = player.mix; // Initialize ab with the mix AudioBuffer of the player + // } else { + // System.err.println("Error loading audio file or audio player is not playing."); + // } + } + public void setup() { + // Load image here + colorMode(HSB, 360, 100, 100); // mode HSB + tikiface = loadImage("tiki_face3.png"); + tikiPos = new PVector(width / 2, height / 12); + } + + public void reactToMouseMovement() { + // make coconuts appear on screen when clicked by mouse + if (mousePressed) { + coconuts.add(new Coconut(new PVector(mouseX, mouseY)));// create new coconuts + add to list + } + } + + public void tiki_face() { + int numTikis = 5; + float tikiSpacing = width / (numTikis + 1); // calculate spacing between tikis + + for (int i = 1; i <= numTikis; i++) { + float tikiX = i * tikiSpacing - 100; // Calculate X position + + // move tiki with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + PVector tikiPos = new PVector(tikiX, height / 12 + amplitude); + PVector tikiPos2 = new PVector(tikiX, height / 1.5f + amplitude); + + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + + // draw tiki face at the updated position + image(tikiface, tikiPos.x, tikiPos.y); + image(tikiface, tikiPos2.x, tikiPos2.y); + + } + + } + + class Coconut { + // position of coconut + PVector position; + int timesReachedEnd; + + Coconut(PVector position) { + this.position = position; + } + + // update coconut position make it appear on screen + void update() { + // Draw coconut + float coconutSize = 100; + + pushMatrix(); // save the current transformation matrix + translate(position.x, position.y); // translate to the coconut's position + noStroke(); + fill(360, 100, 36); + ellipse(0, 0, coconutSize, coconutSize); // draw coconut at the translated position + + // Draw small circle inside the coconut + float smallCircleSize = 20; + float smallCircleOffsetX = coconutSize / 2 - 30; + float smallCircleOffsetY = -coconutSize / 2 + 30; + fill(67, 37, 100); + ellipse(smallCircleOffsetX, smallCircleOffsetY, smallCircleSize, smallCircleSize); + + popMatrix(); // restore the previous transformation matrix + + // makes coconut falls down + position.y += 2; + if (position.y > height) { + position.y = 0; // coconut goes back up when it reaches the bottom + timesReachedEnd++; + } + if (timesReachedEnd >= 2) { + coconuts.remove(this); // remove coconut from the list if reached the end twice + } + + } + + } + + public void render(AudioBuffer ab) { + this.ab = ab; + float average = 0; + float sum = 0; + + off += 1; + // calculate sum and average of the samples + // lerp each element of buffer; + lerpedBuffer = new float[ab.size()]; + + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + // Ensure lerpedBuffer is not accessed beyond its bounds + if (i < lerpedBuffer.length) { + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + float cx = width / 2; + float cy = height / 2; + + + background(209, 58, 100); + + reactToMouseMovement(); + for (int i = coconuts.size() - 1; i >= 0; i--) { + Coconut c = coconuts.get(i); // get the coconut from the list + c.update(); // draw the coconut + } + + for (int i = 0; i < ab.size(); i++) { + float hue = map(i, 0, ab.size(), 56, 0); + + stroke(hue, 100, 100); + noFill(); + circle(cx, cy, average * i * 2); + } + for (int i = 0; i < ab.size(); i++) { + float s = lerpedBuffer[i] * cx; + float hue = map(i, 0, ab.size(), 0, 121); + stroke(hue, 255, 300); + + // cool line that moves with the music + // cos and sin functions to make line move in a circular way + // two_pi is a full circle + line(cx, cy + smoothedAmplitude, cx + cos(TWO_PI / ab.size() * i) * s * 2, + cy + sin(TWO_PI / ab.size() * i) * s * 2); + + } + for (int i = 0; i < ab.size(); i++) { + float hue = map(i, 0, ab.size(), 290, 51); + stroke(hue, 100, 100); + // circle to be infront of the cool line + circle(cx, cy, average * i / 8); + } + + tiki_face(); + + + } + +} \ No newline at end of file diff --git a/java/src/c22305863/iriaVisual.java b/java/src/c22305863/iriaVisual.java new file mode 100644 index 000000000..10f516d35 --- /dev/null +++ b/java/src/c22305863/iriaVisual.java @@ -0,0 +1,218 @@ +package c22305863; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import processing.core.PImage; +import processing.core.PVector; +import java.util.ArrayList; + +public class iriaVisual extends PApplet { + + Minim minim; + AudioPlayer ap; + AudioInput ai; + private AudioBuffer ab; + + int mode = 0;// default mode for switch statement + + float[] lerpedBuffer; + float y = 0; // vertical position + float ySpeed = 2; + float smoothedY = 0; + float smoothedAmplitude = 0; + + ArrayList coconuts = new ArrayList(); // array to store coconuts + PImage tikiface; + PImage skirt; + PVector tikiPos; + PVector tikiPos2; + PVector skirtPos; + PVector skirtPos2; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + + public void settings() { + size(1024, 600, P3D); + // fullScreen(P3D, SPAN); + // size(1024,700); + } + + public void setup() { + minim = new Minim(this); + // Uncomment this to use the microphone + // ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + // am = ai.mix; + ap = minim.loadFile("Squidward's Tiki Land Psy-Trance Remix.mp3", 1024); + ap.play(); + ab = ap.mix; + colorMode(HSB); + + y = height / 2; + smoothedY = y; + + textureMode(NORMAL); + + lerpedBuffer = new float[width]; + + tikiface = loadImage("tiki_face3.png"); + skirt = loadImage("skirt.png"); + tikiPos = new PVector(width / 2, height / 12); + + } + + float off = 0; + + public void reactToMouseMovement() { + // make coconuts appear on screen when clicked by mouse + if (mousePressed) { + coconuts.add(new Coconut(new PVector(mouseX, mouseY)));// create new coconuts + add to list + } + } + + public void tiki_face() { + int numTikis = 5; + float tikiSpacing = width / (numTikis + 1); // calculate spacing between tikis + + for (int i = 1; i <= numTikis; i++) { + + float tikiX = i * tikiSpacing - 100; // Calculate X position + + // move tiki with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + PVector tikiPos = new PVector(tikiX, height / 12 + amplitude); + PVector tikiPos2 = new PVector(tikiX, height / 1.50f + amplitude); + + // skirt + PVector skirtPos = new PVector(tikiX , height / 3.4f + amplitude); + PVector skirtPos2 = new PVector(tikiX , height / 1.14f + amplitude); + + // draw tiki face at the updated position + image(tikiface, tikiPos.x, tikiPos.y); + image(tikiface, tikiPos2.x, tikiPos2.y); + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + image(skirt, skirtPos.x, skirtPos.y); + image(skirt, skirtPos2.x, skirtPos2.y); + + } + + } + + class Coconut { + // position of coconut + PVector position; + int timesReachedEnd; + + Coconut(PVector position) { + this.position = position; + } + + // update coconut position make it appear on screen + void update() { + // Draw coconut + float coconutSize = 100; + + pushMatrix(); // save the current transformation matrix + translate(position.x, position.y); // translate to the coconut's position + noStroke(); + fill(360, 100, 36); + ellipse(0, 0, coconutSize, coconutSize); // draw coconut at the translated position + + // Draw small circle inside the coconut + float smallCircleSize = 20; + float smallCircleOffsetX = coconutSize / 2 - 30; + float smallCircleOffsetY = -coconutSize / 2 + 30; + fill(67, 37, 100); + ellipse(smallCircleOffsetX, smallCircleOffsetY, smallCircleSize, smallCircleSize); + + popMatrix(); // restore the previous transformation matrix + + // makes coconut falls down + position.y += 3; + if (position.y > height) { + position.y = 0; // coconut goes back up when it reaches the bottom + timesReachedEnd++; + } + if (timesReachedEnd >= 2) { + coconuts.remove(this); // remove coconut from the list if reached the end twice + } + + } + + } + + public void draw() { + + float average = 0; + float sum = 0; + off += 1; + // calculate sum and average of the samples + // lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + float cx = width / 2; + float cy = height / 2; + + colorMode(HSB, 360, 100, 100); // mode HSB + background(209, 58, 100); + + reactToMouseMovement(); + for (int i = coconuts.size() - 1; i >= 0; i--) { + Coconut c = coconuts.get(i); // get the coconut from the list + c.update(); // draw the coconut + } + + for (int i = 0; i < ab.size(); i++) { + float hue = map(i, 0, ab.size(), 297, 58); + stroke(hue, 100, 100); + noFill(); + circle(cx, cy, average * i * 4 * smoothedAmplitude); + // line that surrounds the border of the circle + line(cx, cy, cx + cos(TWO_PI / average * i) * 100, cy + sin(TWO_PI / average * i) * 100); + + } + for (int i = 0; i < ab.size(); i++) { + + float hue = map(i, 0, ab.size(), 50, 0); + float s = lerpedBuffer[i] * cx; + stroke(hue, 100, 100); + // cool line that moves with the music + // cos and sin functions to make line move in a circular way + // two_pi is a full circle + line(cx, cy + smoothedAmplitude, cx + cos(TWO_PI / ab.size() * i) * s * 2, + cy + sin(TWO_PI / ab.size() * i) * s * 2); + + } + for (int i = 0; i < ab.size(); i++) { + float hue = map(i, 0, ab.size(), 290, 51); + + // circle to be infront of the cool line + circle(cx, cy, average * i / 8); + } + + tiki_face(); + + } +} diff --git a/java/src/c22368271/moonVisual.java b/java/src/c22368271/moonVisual.java new file mode 100644 index 000000000..5e16b3dac --- /dev/null +++ b/java/src/c22368271/moonVisual.java @@ -0,0 +1,141 @@ +package c22368271; + +import ddf.minim.*; +import ddf.minim.analysis.*; +import processing.core.PApplet; +import processing.core.PImage; +import processing.core.PVector; + +public class moonVisual extends PApplet { + + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + FFT fft; + + PImage bg; + PImage flower; + float speedX, speedY; + + int mode = 0; + + float[] lerpedBuffer; + float y = 0; + float smoothedY = 0; + float smoothedAmplitude = 0; + + float flowerX, flowerY; // flower pos + PVector flowerPos; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + public void settings() { + size(1024, 600, P3D); + } + + public void setup() { + minim = new Minim(this); + ap = minim.loadFile("Squidward's Tiki Land Psy-Trance Remix.mp3", 1024); + ap.play(); + ab = ap.mix; + + fft = new FFT(ap.bufferSize(), ap.sampleRate()); + + bg = loadImage("spongeBG.png"); + flower = loadImage("spongeFlower.png"); + + lerpedBuffer = new float[width]; + + colorMode(HSB); + } + + public void flowers(float amplitude) { + int numflowers = 7; + float angleIn = TWO_PI / numflowers; + + float flowerSize = map(amplitude, 0, 1, 10, 100); + + for (int i = 0; i < numflowers; i++) { + float angle = i * angleIn; + float radius = flowerSize * (i + 10); + float flowerPosX = width / 2 + cos(angle) * radius-100; + float flowerPosY = height / 2 + sin(angle) * radius-100; + image(flower, flowerPosX, flowerPosY, flower.width / 6, flower.height / 6); + } + } + + void drawStrobeLights() { + int numLights = 20; // Number of strobe lights + float angleStep = TWO_PI / numLights; // Angle step between each light + float radius = min(width, height) * 0.4f; // Radius of the circle containing the lights + float centerX = width / 2; // X-coordinate of the center of the circle + float centerY = height / 2; // Y-coordinate of the center of the circle + + for (int i = 0; i < numLights; i++) { + // Calculate position of each strobe light around the circle + float x = centerX + cos(angleStep * i) * radius; + float y = centerY + sin(angleStep * i) * radius; + + // Calculate size of the strobe light based on the amplitude + float lightSize = map(smoothedAmplitude, 0, 1, 10, 50); + + // Calculate color of the strobe light based on time + int lightColor = color((frameCount + i * 10) % 255, 255, 255); + + // Set fill and stroke colors + fill(lightColor); + stroke(lightColor); + + // Draw the strobe light + ellipse(x, y, lightSize, lightSize); + } + } + + + + public void draw() { + image(bg, 0, 0, width, height); + + float average = 0; + float sum = 0; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + + flowers(smoothedAmplitude); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + float squareSize = map(smoothedAmplitude, 0, 1, 10, 400); + float squareX = width / 2 - squareSize / 2; + float squareY = height / 2 - squareSize / 2; + int rainbowColor = color((frameCount / 2) % 255, (frameCount / 3) % 255, (frameCount / 4) % 255); + stroke(rainbowColor); + fill(0); + rect(squareX, squareY, squareSize, squareSize); + + float waveAmplitude = map(smoothedAmplitude, 0, 1, 0, squareSize / 2); + fft.forward(ap.mix); + for (int i = 0; i < fft.specSize(); i++) { + float x = map(i, 0, fft.specSize(), squareX, squareX + squareSize); + float y = squareY + squareSize / 2 + fft.getBand(i) * waveAmplitude; + point(x, y); + } + + drawStrobeLights(); + } +} diff --git a/java/src/example/AudioBandsVisual.java b/java/src/example/AudioBandsVisual.java index b6b99d6e5..8ad699489 100644 --- a/java/src/example/AudioBandsVisual.java +++ b/java/src/example/AudioBandsVisual.java @@ -1,13 +1,14 @@ package example; +import ie.tudublin.OurVisual; import processing.core.*; // This is an example of a visual that uses the audio bands public class AudioBandsVisual { - MyVisual mv; + OurVisual mv; - public AudioBandsVisual(MyVisual mv) + public AudioBandsVisual(OurVisual mv) { this.mv = mv; } diff --git a/java/src/example/WaveForm.java b/java/src/example/WaveForm.java index 5d38aa700..7df6df5de 100644 --- a/java/src/example/WaveForm.java +++ b/java/src/example/WaveForm.java @@ -1,31 +1,34 @@ package example; import processing.core.*; +import ie.tudublin.OurVisual; + + // This is an example of a visual that renders the waveform public class WaveForm { - MyVisual mv; + OurVisual ov; float cy = 0; - public WaveForm(MyVisual mv) + public WaveForm(OurVisual ov) { - this.mv = mv; - cy = this.mv.height / 2; + this.ov = ov; + cy = this.ov.height / 2; } public void render() { - mv.colorMode(PApplet.HSB); - for(int i = 0 ; i < mv.getAudioBuffer().size() ; i ++) + ov.colorMode(PApplet.HSB); + for(int i = 0 ; i < ov.getAudioBuffer().size() ; i ++) { - mv.stroke( - PApplet.map(i, 0, mv.getAudioBuffer().size(), 0, 255) + ov.stroke( + PApplet.map(i, 0, ov.getAudioBuffer().size(), 0, 255) , 255 , 255 ); - mv.line(i, cy, i, cy + cy * mv.getAudioBuffer().get(i)); + ov.line(i, cy, i, cy + cy * ov.getAudioBuffer().get(i)); } } } \ No newline at end of file diff --git a/java/src/ie/tudublin/Allfiles.java b/java/src/ie/tudublin/Allfiles.java new file mode 100644 index 000000000..39211314a --- /dev/null +++ b/java/src/ie/tudublin/Allfiles.java @@ -0,0 +1,717 @@ +package ie.tudublin; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import ddf.minim.analysis.FFT; +import processing.core.PApplet; +import processing.core.PImage; +import processing.core.PVector; +import java.util.ArrayList; + +public class Allfiles extends PApplet { + Minim minim; + AudioPlayer ap; + AudioInput ai; + FFT fft; + private AudioBuffer ab; + + int mode = 0;// default mode for switch statement + + float[] lerpedBuffer; + float y = 0; // vertical position + float ySpeed = 2; + float smoothedY = 0; + float smoothedAmplitude = 0; + + ArrayList coconuts = new ArrayList(); // array to store coconuts + PImage tikiface; + PImage skirt; + PVector tikiPos; + PVector tikiPos2; + PVector skirtPos; + PVector skirtPos2; + + PImage bananaPic; + PImage bg; + ArrayList bananas; + + + PImage flowerM; + float speedX, speedY; + float flowerX, flowerY; // flower pos + PVector flowerPos; + + float outsideRadius = 150; + float insideRadius = 100; + + ArrayList clouds; + ArrayList flowers; + boolean flowersStarted = false; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + public void settings() { + size(1024, 600, P3D); + // fullScreen(P3D, SPAN); + // size(1024,700); + } + + public void setup() { + minim = new Minim(this); + // Uncomment this to use the microphone + // ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + // am = ai.mix; + ap = minim.loadFile("Squidward's Tiki Land Psy-Trance Remix.mp3", 1024); + ap.play(); + ab = ap.mix; + colorMode(HSB); + + + + bg = loadImage("spongeBG.png"); + flowerM = loadImage("spongeFlower.png"); + + y = height / 2; + smoothedY = y; + + textureMode(NORMAL); + + lerpedBuffer = new float[width]; + + tikiface = loadImage("tiki_face3.png"); + skirt = loadImage("skirt.png"); + tikiPos = new PVector(width / 2, height / 12); + + bananaPic = loadImage("banana_pic.png"); + bananas = new ArrayList(); + + bg = loadImage("spongeBG.png"); + + int numBananas = 30; + float bananaSpacing = width / (numBananas + 1); // calculate spacing between bananas + for (int i = 1; i <= numBananas; i++) { + float bananaX = i * bananaSpacing; + bananas.add(new Banana(bananaX, 0)); // Add bananas to the list + } + fft = new FFT(ap.bufferSize(), ap.sampleRate()); + + clouds = new ArrayList(); + + for (int i = 0; i < 5; i++) { + clouds.add(new Cloud(random(width), random(height * 0.2f), random(50, 100), random(1, 3))); + + } + + flowers = new ArrayList(); + + } + + float off = 0; + + + + private void reactToMouseMovement() { + // make coconuts appear on screen when clicked by mouse + if (mousePressed) { + coconuts.add(new Coconut(new PVector(mouseX, mouseY)));// create new coconuts + add to list + } + } + + public void tiki_face() { + int numTikis = 5; + float tikiSpacing = width / (numTikis + 1); // calculate spacing between tikis + + for (int i = 1; i <= numTikis; i++) { + + float tikiX = i * tikiSpacing - 100; // Calculate X position + + // move tiki with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + PVector tikiPos = new PVector(tikiX, height / 12 + amplitude); + PVector tikiPos2 = new PVector(tikiX, height / 1.5f + amplitude); + + // skirt + PVector skirtPos = new PVector(tikiX+6.5f, height /3.58f + amplitude); + PVector skirtPos2 = new PVector(tikiX+6.6f, height / 1.16f + amplitude); + + // draw tiki face at the updated position + image(tikiface, tikiPos.x, tikiPos.y); + image(tikiface, tikiPos2.x, tikiPos2.y); + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + image(skirt, skirtPos.x, skirtPos.y); + image(skirt, skirtPos2.x, skirtPos2.y); + + } + + } + + class Coconut { + // position of coconut + PVector position; + int timesReachedEnd; + + Coconut(PVector position) { + this.position = position; + } + + // update coconut position make it appear on screen + void update() { + // Draw coconut + float coconutSize = 100; + + pushMatrix(); // save the current transformation matrix + translate(position.x, position.y); // translate to the coconut's position + noStroke(); + fill(360, 100, 36); + ellipse(0, 0, coconutSize, coconutSize); // draw coconut at the translated position + + // Draw small circle inside the coconut + float smallCircleSize = 20; + float smallCircleOffsetX = coconutSize / 2 - 30; + float smallCircleOffsetY = -coconutSize / 2 + 30; + fill(67, 37, 100); + ellipse(smallCircleOffsetX, smallCircleOffsetY, smallCircleSize, smallCircleSize); + + popMatrix(); // restore the previous transformation matrix + + // makes coconut falls down + position.y += 3; + if (position.y > height) { + position.y = 0; // coconut goes back up when it reaches the bottom + timesReachedEnd++; + } + if (timesReachedEnd >= 2) { + coconuts.remove(this); // remove coconut from the list if reached the end twice + } + + } + + } + + public void displayIria() { + + background(0); + + float average = 0; + float sum = 0; + off += 1; + // calculate sum and average of the samples + // lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + float cx = width / 2; + float cy = height / 2; + + colorMode(HSB, 360, 100, 100); // mode HSB + image(bg, 0, 0,width,height); + + reactToMouseMovement(); + for (int i = coconuts.size() - 1; i >= 0; i--) { + Coconut c = coconuts.get(i); // get the coconut from the list + c.update(); // draw the coconut + } + + for (int i = 0; i < ab.size(); i++) { + float hue = map(i, 0, ab.size(), 297, 58); + stroke(hue, 100, 100); + noFill(); + circle(cx, cy, average * i * 4 * smoothedAmplitude); + // line that surrounds the border of the circle + line(cx, cy, cx + cos(TWO_PI / average * i) * 100, cy + sin(TWO_PI / average * i) * 100); + + } + for (int i = 0; i < ab.size(); i++) { + + float hue = map(i, 0, ab.size(), 50, 0); + float s = lerpedBuffer[i] * cx; + stroke(hue, 100, 100); + // cool line that moves with the music + // cos and sin functions to make line move in a circular way + // two_pi is a full circle + line(cx, cy + smoothedAmplitude, cx + cos(TWO_PI / ab.size() * i) * s * 2, + cy + sin(TWO_PI / ab.size() * i) * s * 2); + + } + for (int i = 0; i < ab.size(); i++) { + float hue = map(i, 0, ab.size(), 290, 51); + + // circle to be infront of the cool line + circle(cx, cy, average * i / 8); + } + + tiki_face(); + } + + + + + public void visiual() { + + for (int i = 0; i < ab.size(); i++) { + float cx = width / 2; + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + float hue = map(i, 0, ab.size(), 0, 256); + float s = lerpedBuffer[i] * cx * 2; + + // from left side to right + stroke(40, 255, 255); + line(0, i, s, i); + // from right side to left + line(width, i, width - s, i); + // from top to bottom + line(i, 0, i, s); + // from bottom to top + line(i, height, i, height - s); + } + + int gridSize = 40; + + for (int x = gridSize; x <= width - gridSize; x += gridSize) { + for (int y = gridSize; y <= height - gridSize; y += gridSize) { + noStroke(); + fill(255); + rect(x - 1, y - 1, 3, 3); + stroke(255, 100); + line(x, y, width / 2, height / 2); + } + } + + int num = 60; + float mx[] = new float[num]; + float my[] = new float[num]; + + // Cycle through the array, using a different entry on each frame. + // Using modulo (%) like this is faster than moving all the values over. + int which = frameCount % num; + mx[which] = mouseX; + my[which] = mouseY; + + for (int i = 0; i < num; i++) { + // which+1 is the smallest (the oldest in the array) + int index = (which + 1 + i) % num; + ellipse(mx[index], my[index], i, i); + } + + int x; + int y; + float outsideRadius = 150; + float insideRadius = 100; + + int numPoints = (int) map((float) mouseX, 0, (float) width, 6, 60); + float angle = 0; + float angleStep = 180.0f / num; + + // Ocean wave parameters + float waveSpeed = 0.0000000000000000001f; // Speed of the waves + float waveAmplitude = 10; // Amplitude of the waves + float waveFrequency = 0.025f; // Frequency of the waves + + for (int z = 0; z < width; z++) { + stroke(160, 255, 255); // HSB color (blue) + float waveHeight = sin(z * waveFrequency + off) * waveAmplitude; + line(z, height * 2 / 3 + waveHeight, z, height); // Drawing waves from the center of the canvas to the + // bottom + } + + off += waveSpeed; // Incrementing the offset for the waves animation + + int numBananas = 15; + float bananaSpacing = width / (numBananas + 1); // calculate spacing between tikis + + for (int i = 1; i <= numBananas; i++) { + float bananaX = i * bananaSpacing - 100; // Calculate X position + + // move bananas with music + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + float bananaY = -amplitude * 0.5f; + float bananaSize = map(amplitude, 0, 50, 10, 50); + + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + + } + + } + + class Banana { + float x, y; + int timesReachedEnd; + + Banana(float x, float y) { + this.x = x; + this.y = y; + timesReachedEnd = 0; + } + + void display() { + float amplitude = map(sin(frameCount * 0.05f), -1, 1, 0, ab.size() / 8); + float bananaX = x * (width / 1024.0f); // Adjust x position for different screen widths + float bananaY = y * (height / 600.0f); + float bananaSize = map(amplitude, 0, 50, 10, 50); + + float hue = map(amplitude, 0, 50, 0, 360); + fill(hue, 100, 100); + image(bananaPic, x, bananaY, bananaSize, bananaSize * 2); + + y += 2; + if (y > height) { + y = 0; // banana goes back up when it reaches the bottom + timesReachedEnd++; + } + if (timesReachedEnd >= 2) { + bananas.remove(this); // remove banana from the list if reached the end twice + } + } + } + + public void displayWissam() { + background(0); + image(bg, 0, 0, width, height); + float halfH = height / 2; + float average = 0; + float sum = 0; + off += 1; + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + float cx = width / 2; + float cy = height / 2; + + // Create a list to hold bananas that need to be removed + ArrayList bananasToRemove = new ArrayList<>(); + + // Iterate over the bananas list + for (Banana banana : bananas) { + banana.display(); + // Check if the banana needs to be removed + if (banana.timesReachedEnd >= 2) { + bananasToRemove.add(banana); + } + } + + // Remove the bananas that need to be removed + bananas.removeAll(bananasToRemove); + + // calling outline for visiual + visiual(); + + } + + public void flowersM(float amplitude) { + int numflowers = 7; + float angleIn = TWO_PI / numflowers; + + float flowerSize = map(amplitude, 0, 1, 10, 100); + + for (int i = 0; i < numflowers; i++) { + float angle = i * angleIn; + float radius = flowerSize * (i + 10); + float flowerPosX = width / 2 + cos(angle) * radius-100; + float flowerPosY = height / 2 + sin(angle) * radius-100; + image(flowerM, flowerPosX, flowerPosY, flowerM.width / 6, flowerM.height / 6); + } + } + void drawStrobeLights() { + int numLights = 20; // Number of strobe lights + float angleStep = TWO_PI / numLights; // Angle step between each light + float radius = min(width, height) * 0.4f; // Radius of the circle containing the lights + float centerX = width / 2; // X-coordinate of the center of the circle + float centerY = height / 2; // Y-coordinate of the center of the circle + + for (int i = 0; i < numLights; i++) { + // Calculate position of each strobe light around the circle + float x = centerX + cos(angleStep * i) * radius; + float y = centerY + sin(angleStep * i) * radius; + + // Calculate size of the strobe light based on the amplitude + float lightSize = map(smoothedAmplitude, 0, 1, 10, 50); + + // Calculate color of the strobe light based on time + int lightColor = color((frameCount + i * 10) % 255, 255, 255); + + // Set fill and stroke colors + fill(lightColor); + stroke(lightColor); + + // Draw the strobe light + ellipse(x, y, lightSize, lightSize); + } + } + public void displaymoon(){ + background(0); + image(bg, 0, 0, width, height); + + float average = 0; + float sum = 0; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + + flowersM(smoothedAmplitude); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + float squareSize = map(smoothedAmplitude, 0, 1, 10, 400); + float squareX = width / 2 - squareSize / 2; + float squareY = height / 2 - squareSize / 2; + int rainbowColor = color((frameCount / 2) % 255, (frameCount / 3) % 255, (frameCount / 4) % 255); + stroke(rainbowColor); + fill(0); + rect(squareX, squareY, squareSize, squareSize); + + float waveAmplitude = map(smoothedAmplitude, 0, 1, 0, squareSize / 2); + fft.forward(ap.mix); + for (int i = 0; i < fft.specSize(); i++) { + float x = map(i, 0, fft.specSize(), squareX, squareX + squareSize); + float y = squareY + squareSize / 2 + fft.getBand(i) * waveAmplitude; + point(x, y); + } + + drawStrobeLights(); + } + + float getAverageAmplitude(AudioBuffer buffer) { + float sum = 0; + for (int i = 0; i < buffer.size(); i++) { + sum += abs(buffer.get(i)); + } + return sum / buffer.size(); + } + + void drawTree(float x, float y, float scale) + { + //trunk + fill(55, 40, 28); + rect(x - 10 * scale, y, 20 * scale, 150 * scale); + + //leaves + fill(19, 128, 99); + + //topleft + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x - 50 * scale, y - 60 * scale, x - 70 * scale, y + 20 * scale, x - 50 * scale, y + 60 * scale); + bezierVertex(x - 20 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x, y); + endShape(CLOSE); + + //left + beginShape(); + vertex(x - 10 * scale, y); + bezierVertex(x - 80 * scale, y - 30 * scale, x - 90 * scale, y + 10 * scale, x - 70 * scale, y + 50 * scale); + bezierVertex(x - 30 * scale, y + 20 * scale, x - 40 * scale, y - 10 * scale, x - 10 * scale, y); + endShape(CLOSE); + + //right + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 80 * scale, y - 30 * scale, x + 90 * scale, y + 10 * scale, x + 70 * scale, y + 50 * scale); + bezierVertex(x + 30 * scale, y + 20 * scale, x + 40 * scale, y - 10 * scale, x + 10 * scale, y); + endShape(CLOSE); + + //topright + beginShape(); + vertex(x + 10 * scale, y); + bezierVertex(x + 50 * scale, y - 60 * scale, x + 80 * scale, y - 20 * scale, x + 50 * scale, y + 20 * scale); + bezierVertex(x + 20 * scale, y - 20 * scale, x + 30 * scale, y - 40 * scale, x + 10 * scale, y); + endShape(CLOSE); + } + + class Cloud + { + float x, y, size, speed; + + Cloud(float x, float y, float size, float speed) + { + this.x = x; + this.y = y; + this.size = size; + this.speed = speed; + } + + void display() + { + noStroke(); + fill(255); + float angleStep = TWO_PI / 10; + ellipse(x, y, size * 2, size * 0.8f); + for (float angle = 0; angle < TWO_PI; angle += angleStep) + { + float vx = x + cos(angle) * size; + float vy = y + sin(angle) * size * 0.5f; + ellipse(vx, vy, (float)(size * 0.8), (float)(size * 0.8)); + } + } + + void move() + { + x += speed; + if (x > width + size / 2) + { + x = -size / 2; + } + } + } + + public class Flower + { + float x, y; + float vx, vy; + float size; + int color; + + public Flower(float x, float y, float vx, float vy, float size, int color) + { + this.x = x; + this.y = y; + this.vx = vx * 2; + this.vy = vy * 2; + this.size = size; + this.color = color; + } + + public void update() + { + x += vx; + y += vy; + } + + public void display(PApplet p) + { + p.noStroke(); + p.fill(color); + float petalAngleIncrement = TWO_PI / 5; + for (int i = 0; i < 5; i++) { + float angle = i * petalAngleIncrement; + float petalX = x + cos(angle) * size * 0.8f; + float petalY = y + sin(angle) * size * 0.8f; + p.ellipse(petalX, petalY, size * 1.1f, size * 1.1f); + } + } + } + + void startFlowers() + { + for (int i = 0; i < 75; i++) + { + float x = random(width); + float y = random(height); + float vx = random(-2, 2); + float vy = random(-2, 2); + float size = random(20, 40); + int color = color(random(255), random(255), random(255)); + flowers.add(new Flower(x, y, vx, vy, size, color)); + } + } + + + public void displayamber(){ + background(0); + + image(bg, 0, 0, width, height); + float average = 0; + float sum = 0; + off += 1; + + for (int i = 0; i < ab.size(); i++) + { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f); + } + average = sum / (float) ab.size(); + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + //background(152, 193, 217); + + float averageAmplitude = getAverageAmplitude(ab); + + float treeX1 = width / 4; + float treeX2 = width * 3 / 4; + + float treeY1 = map(averageAmplitude, 0, 1, height * 0.7f, height * 0.9f); + float treeY2 = map(averageAmplitude, 0, 1, height * 0.7f, height * 0.9f); + + for (Cloud c : clouds) + { + c.move(); + c.display(); + } + + drawTree(treeX1, treeY1, 1.5f); + drawTree(treeX2, treeY2, 1.5f); + + if (ap.isPlaying()) + { + int currentPosition = ap.position(); + if (currentPosition >= 19000 && currentPosition < 45000) + { + int timeInterval = currentPosition - 19000; + if (timeInterval % 7000 <= 40) + { + startFlowers(); + } + } + + } + + for (Flower flower : flowers) + { + flower.update(); + flower.display(this); + } + + } + public void draw() { + switch (mode) { + case 1: { + displayWissam(); + break; + } + case 2: { + displaymoon(); + break; + } + case 3: { + displayIria(); + break; + } + case 4: { + displayamber(); + break; + } + + default: + displayIria(); + break; + } + + } +} diff --git a/java/src/ie/tudublin/Main.java b/java/src/ie/tudublin/Main.java index 67e93d892..8f5af390a 100644 --- a/java/src/ie/tudublin/Main.java +++ b/java/src/ie/tudublin/Main.java @@ -1,18 +1,20 @@ -package ie.tudublin; - -import example.CubeVisual; -import example.MyVisual; -import example.RotatingAudioBands; - -public class Main { - - public void startUI() { - String[] a = { "MAIN" }; - processing.core.PApplet.runSketch(a, new MyVisual()); - } - - public static void main(String[] args) { - Main main = new Main(); - main.startUI(); - } + +package ie.tudublin; + +import c22305863.iriaVisual; +import example.CubeVisual; +import example.RotatingAudioBands; +import ie.tudublin.Allfiles; + +public class Main { + + public void startUI() { + String[] a = { "MAIN" }; + processing.core.PApplet.runSketch(a, new Allfiles()); + } + + public static void main(String[] args) { + Main main = new Main(); + main.startUI(); + } } \ No newline at end of file diff --git a/java/src/ie/tudublin/MyVisual2.java b/java/src/ie/tudublin/MyVisual2.java new file mode 100644 index 000000000..609a2477c --- /dev/null +++ b/java/src/ie/tudublin/MyVisual2.java @@ -0,0 +1,62 @@ +package ie.tudublin; + +import ie.tudublin.*; +import processing.core.*; +import c22305863.Iiria2; +import c21404706.*; +public class MyVisual2 extends Visual { + Iiria2 ip; + + + int mode = 0; + + public void settings() { + //size(1024, 500); + + // Use this to make fullscreen + // fullScreen(); + + // Use this to make fullscreen and use P3D for 3D graphics + fullScreen(P3D, SPAN); + } + + public void setup() { + startMinim(); + colorMode(HSB); + // Call loadAudio to load an audio file to process + loadAudio("Squidward's Tiki Land Psy-Trance Remix.mp3"); + + // Call this instead to read audio from the microphone + // startListening(); + + ip = new Iiria2(this); + //abv = new AudioBandsVisual(this); + } + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (key == ' ') { + getAudioPlayer().cue(0); + getAudioPlayer().play(); + } + + } + + public void draw() { + + switch (mode) { + case 0: + ip.render(); + break; + case 1: + { + //wissam render() + } //etc + + default: + break; + } + } +} diff --git a/java/src/example/MyVisual.java b/java/src/ie/tudublin/OurVisual.java similarity index 54% rename from java/src/example/MyVisual.java rename to java/src/ie/tudublin/OurVisual.java index 8a71fe3f6..62669d506 100644 --- a/java/src/example/MyVisual.java +++ b/java/src/ie/tudublin/OurVisual.java @@ -1,55 +1,87 @@ -package example; - -import ie.tudublin.*; - -public class MyVisual extends Visual { - WaveForm wf; - AudioBandsVisual abv; - - public void settings() { - size(1024, 500); - - // Use this to make fullscreen - // fullScreen(); - - // Use this to make fullscreen and use P3D for 3D graphics - // fullScreen(P3D, SPAN); - } - - public void setup() { - startMinim(); - - // Call loadAudio to load an audio file to process - // loadAudio("heroplanet.mp3"); - - // Call this instead to read audio from the microphone - startListening(); - - wf = new WaveForm(this); - abv = new AudioBandsVisual(this); - } - - public void keyPressed() { - if (key == ' ') { - getAudioPlayer().cue(0); - getAudioPlayer().play(); - } - } - - public void draw() { - background(0); - try { - // Call this if you want to use FFT data - calculateFFT(); - } catch (VisualException e) { - e.printStackTrace(); - } - // Call this is you want to use frequency bands - calculateFrequencyBands(); - - // Call this is you want to get the average amplitude - calculateAverageAmplitude(); - wf.render(); - abv.render(); - } -} + +package ie.tudublin; + +import c22305863.IriaVis; +import c22368271.MusicVisualizer; + +import ddf.minim.AudioBuffer; +import example.AudioBandsVisual; +import example.WaveForm; + +public class OurVisual extends Visual { + WaveForm wf; + AudioBandsVisual abv; + IriaVis ip; + MusicVisualizer mv; + + char mode = ' '; + int color; + boolean isPlaying = false; + + public void settings() { + // size(1024, 500); + size(1024, 600, P3D); + // Use this to make fullscreen + // fullScreen(); + + // Use this to make fullscreen and use P3D for 3D graphics + // fullScreen(P3D, SPAN); + } + + public void setup() { + startMinim(); + + // Call loadAudio to load an audio file to process + loadAudio("Squidward's Tiki Land Psy-Trance Remix.mp3"); + + // Call this instead to read audio from the microphone + // startListening(); + + wf = new WaveForm(this); + abv = new AudioBandsVisual(this); + ip = new IriaVis(this); + mv = new MusicVisualizer(); + } + + public void keyPressed() { + if (key == ' ') { + getAudioPlayer().cue(0); + getAudioPlayer().play(); + isPlaying = true; + } else { + mode = key; + } + } + + public void draw() { + background(0); + + // switch case method + switch (mode) { + case '1': + + wf.render(); + break; + case '2': + ip.render(getAudioBuffer()); + + break; + + default: + break; + } + + try { + // Call this if you want to use FFT data + calculateFFT(); + } catch (VisualException e) { + e.printStackTrace(); + } + + // Call this is you want to use frequency bands + calculateFrequencyBands(); + + // Call this is you want to get the average amplitude + calculateAverageAmplitude(); + } +}