diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..3c063e988 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,75 @@ +{ + "java.debug.settings.onBuildFailureProceed": true, + "java.project.referencedLibraries": { + "include": [ + "lib/**/*.jar", + "java/lib/commons-cli-1.5.0.jar", + "java/lib/core.jar", + "java/lib/gluegen-rt.jar", + "java/lib/gluegen-rt-natives-linux-aarch64.jar", + "java/lib/gluegen-rt-natives-linux-amd64.jar", + "java/lib/gluegen-rt-natives-linux-armv6hf.jar", + "java/lib/gluegen-rt-natives-linux-i586.jar", + "java/lib/gluegen-rt-natives-macosx-universal.jar", + "java/lib/gluegen-rt-natives-windows-amd64.jar", + "java/lib/gluegen-rt-natives-windows-i586.jar", + "java/lib/httpclient5-5.2.1.jar", + "java/lib/httpclient5-cache-5.2.1.jar", + "java/lib/httpclient5-fluent-5.2.1.jar", + "java/lib/httpclient5-testing-5.2.1.jar", + "java/lib/httpclient5-win-5.2.1.jar", + "java/lib/httpcore5-5.2.jar", + "java/lib/httpcore5-h2-5.2.jar", + "java/lib/httpcore5-reactive-5.2.jar", + "java/lib/httpcore5-testing-5.2.jar", + "java/lib/javafx.base.jar", + "java/lib/javafx.controls.jar", + "java/lib/javafx.fxml.jar", + "java/lib/javafx.graphics.jar", + "java/lib/javafx.media.jar", + "java/lib/javafx.swing.jar", + "java/lib/javafx.web.jar", + "java/lib/javafx-swt.jar", + "java/lib/jl1.0.1.jar", + "java/lib/jna-5.12.1.jar", + "java/lib/jna-platform-5.12.1.jar", + "java/lib/jogl-all.jar", + "java/lib/jogl-all-natives-linux-aarch64.jar", + "java/lib/jogl-all-natives-linux-amd64.jar", + "java/lib/jogl-all-natives-linux-armv6hf.jar", + "java/lib/jogl-all-natives-linux-i586.jar", + "java/lib/jogl-all-natives-macosx-universal.jar", + "java/lib/jogl-all-natives-windows-amd64.jar", + "java/lib/jogl-all-natives-windows-i586.jar", + "java/lib/jsminim.jar", + "java/lib/minim.jar", + "java/lib/mp3spi1.9.5.jar", + "java/lib/reactive-streams-1.0.4.jar", + "java/lib/rxjava-2.2.21.jar", + "java/lib/rxjava-3.1.5.jar", + "java/lib/slf4j-api-1.7.36.jar", + "java/lib/sqlite-jdbc-3.23.1.jar", + "java/lib/tritonus_aos.jar", + "java/lib/tritonus_share.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\commons-cli-1.5.0.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpclient5-5.2.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpclient5-cache-5.2.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpclient5-fluent-5.2.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpclient5-testing-5.2.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpclient5-win-5.2.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpcore5-5.2.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpcore5-h2-5.2.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpcore5-reactive-5.2.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\httpcore5-testing-5.2.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\jna-5.12.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\jna-platform-5.12.1.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\reactive-streams-1.0.4.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\rxjava-2.2.21.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\rxjava-3.1.5.jar", + "d:\\User\\Ernest John Decina\\Downloads\\httpcomponents-client-5.2.1-bin\\lib\\slf4j-api-1.7.36.jar" + ], + "exclude": [ + "d:\\java\\lib\\json-20140107.jar" + ] + } +} \ No newline at end of file diff --git a/Images/ErnestVisualOne.png b/Images/ErnestVisualOne.png new file mode 100644 index 000000000..4181ae1bd Binary files /dev/null and b/Images/ErnestVisualOne.png differ diff --git a/Images/ErnestVisualThree.png b/Images/ErnestVisualThree.png new file mode 100644 index 000000000..fe808c7c8 Binary files /dev/null and b/Images/ErnestVisualThree.png differ diff --git a/Images/ErnestVisualTwo.png b/Images/ErnestVisualTwo.png new file mode 100644 index 000000000..4042e98c5 Binary files /dev/null and b/Images/ErnestVisualTwo.png differ diff --git a/Images/HowItWork.jpg b/Images/HowItWork.jpg new file mode 100644 index 000000000..8a9da080f Binary files /dev/null and b/Images/HowItWork.jpg differ diff --git a/Images/RonVisualOne.jpg b/Images/RonVisualOne.jpg new file mode 100644 index 000000000..745fd4180 Binary files /dev/null and b/Images/RonVisualOne.jpg differ diff --git a/Images/RonVisualTwo.jpg b/Images/RonVisualTwo.jpg new file mode 100644 index 000000000..6a5fbc47d Binary files /dev/null and b/Images/RonVisualTwo.jpg differ diff --git a/Images/alexvisual1.png b/Images/alexvisual1.png new file mode 100644 index 000000000..a3bd52669 Binary files /dev/null and b/Images/alexvisual1.png differ diff --git a/Images/alexvisual2.png b/Images/alexvisual2.png new file mode 100644 index 000000000..0a04d4ad9 Binary files /dev/null and b/Images/alexvisual2.png differ diff --git a/Images/dan1.png b/Images/dan1.png new file mode 100644 index 000000000..264e41b49 Binary files /dev/null and b/Images/dan1.png differ diff --git a/Images/dan2.png b/Images/dan2.png new file mode 100644 index 000000000..1e6faf721 Binary files /dev/null and b/Images/dan2.png differ diff --git a/Images/dan3.png b/Images/dan3.png new file mode 100644 index 000000000..ba58890d8 Binary files /dev/null and b/Images/dan3.png differ diff --git a/MusicVisuals b/MusicVisuals new file mode 160000 index 000000000..480259fbe --- /dev/null +++ b/MusicVisuals @@ -0,0 +1 @@ +Subproject commit 480259fbec7e12977ac1f141c0613429697c80c3 diff --git a/README.md b/README.md index 19ba88c75..8c2fcbe24 100644 --- a/README.md +++ b/README.md @@ -1,89 +1,406 @@ -# Music Visualiser Project +# Project Title Name: + Ron Syhmon Pingol, + Ernest Decina, + Alex Tsang, + Daniel Wu. -Student Number: +Student Number: + C21782059, + C21394933, + C21751999, + C21460524. + -## Instructions -- Fork this repository and use it a starter project for your assignment -- Create a new package named your student number and put all your code in this package. -- You should start by creating a subclass of ie.tudublin.Visual -- There is an example visualiser called MyVisual in the example package -- Check out the WaveForm and AudioBandsVisual for examples of how to call the Processing functions from other classes that are not subclasses of PApplet +Class Group: TU858 -# Description of the assignment +Include all team members names and student numbers if a team project -# Instructions +# Description + +## Video: + +(https://www.youtube.com/watch?v=zinRCbnw260&ab_channel=ErnestJohnDecina) + +## Screenshots + +### Ron Screenshots: + +![](https://github.com/ronpingol/MusicVisuals/blob/master/Images/RonVisualOne.jpg) +![](https://github.com/ronpingol/MusicVisuals/blob/master/Images/RonVisualTwo.jpg) + + +### Daniel (C21460524) Screenshots: + +![](https://github.com/Dan21460/MusicVisuals/blob/master/Images/dan1.png) +![](https://github.com/Dan21460/MusicVisuals/blob/master/Images/dan2.png) +![](https://github.com/Dan21460/MusicVisuals/blob/master/Images/dan3.png) + +### Alex Screenshots: + +![](https://github.com/Entroshock/MusicVisuals/blob/master/Images/alexvisual1.png) +![](https://github.com/Entroshock/MusicVisuals/blob/master/Images/alexvisual2.png) + +## Ernest (C21394933) Screenshots: +![](https://github.com/ErnestDecina/MusicVisuals/blob/master/Images/ErnestVisualOne.png) +![](https://github.com/ErnestDecina/MusicVisuals/blob/master/Images/ErnestVisualTwo.png) +![](https://github.com/ErnestDecina/MusicVisuals/blob/master/Images/ErnestVisualThree.png) + + +# Instructions to work Visualizer + +## Step 1 + + Make sure to be on a connected network that has a DNS that doesnt block the following domain name: ernestjohndecina.com + +## Step 2 + + Run the project using F5 (With Debugging) || CTRL + F5 (Without Debugging) + +## Step 3 + + Enter an APPROPRIATE prompt. Then wait for the Application to process your AI Generated Image. (Any inappropriate prompts will be met with a error and user must reinput a prompt). If it still doesnt work make sure you are connected to the internet for visualizer to create a AI Image # How it works +![](https://raw.githubusercontent.com/ErnestDecina/MusicVisuals/master/Images/HowItWork.jpg) -# What I am most proud of in the assignment +## Overall functionality +We first run the program in main and it initializes the MusicVisual +and it then has a counter that determines which visual will render. -# Markdown Tutorial +### StartMenuVisual (Ernest John Decina: C21394933) +This is the menu where the user will choose their AI Generated image. +It uses a textbox and get a text user input and a button to submit. +This will then send the prompt to a API server that processes the AI Image. -This is *emphasis* -This is a bulleted list +### Visual 3 (Daniel Wu: C21460524) -- Item -- Item +##### drawExample +This code draws a visual scene consisting of an earthquake effect, starfield, circle, particle system, and screen flash effect, while preserving the original transformation and style settings in Processing -This is a numbered list +##### drawCircle +This code draws a rotating, pulsating, and color-changing circle consisting of one large and four smaller circles, with the size and rotation speed influenced by audio input, while also adding particles and explosions based on the amplitude of the audio.# -1. Item -1. Item +##### drawStarfield +This code creates a starfield by drawing glowing stars of varying sizes that move to the right, with the stars wrapping around the screen width. -This is a [hyperlink](http://bryanduggan.org) +##### drawEarthquakeEffect +This code simulates an earthquake effect by translating the screen based on audio amplitude, creating a shaking movement when the amplitude exceeds a specified measurements. -# Headings -## Headings -#### Headings -##### Headings +##### createExplosion +This code uses the Particle class to use the particles to create an explosion effect -This is code: +##### Particle + Update Particle +This code defines a particle system with each particle having a position, velocity, lifespan, and color, while the updateParticles function updates their positions, displays them, and removes the dead ones. + + +### Visual 2 (Ernest John Decina: C21394933) +#### BigBangUniverse +This shows a visual of a blackhole expanding and eating the universe, This first renders a 2d array with positions for the stars in the background + +Then renders a circle that keeps increasing by a counter. + +The Rings around the blackhole was rendered with a circle in a for loop and translating it in the 3d space + +#### DisplayAIGenerateImage +This visuals renders the AI generated image using the pixels of the images with circles and increasing in resolution over time. + +#### FlyingThroughSound +This visual renders points and vertexs then applies bass to the bottom terrain and trebble to the top terrain so it moves up and down. + + +### Visual 4 (Alex Tsang: ) +For my visualizer; what I did was use math to create a rose pattern. By using sin and cos functions I was able to create the petals of the flower and also I was able to use it to give my petal lines dynamic colour. The mathematic equations using trigonometry function and polar coordinates gave this project life. -```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); -} -``` -So is this without specifying the language: +### Visual 1 (Ron Pingol: ) +This class, it got a constructor, you know, that takes in some parameters, like a PApplet object (the core thing in processing), an AudioBuffer object (the audio data), an FFT object (some analysis thingy called Fast Fourier Transform), and also the window size. +So, like, the render() method is where the real action happens, you know. It sets the background color to black and turns on the lights. Then, it calls the drawShapeField() method five times, each with a different translation to create these cool fields of spheres in different spots on the screen. +Now, the drawShapeField() method, that's the one responsible for drawing the spheres, man. First thing it does is it sets up this array of colors for the spheres. Then, it starts spinning the spheres around, you know, rotating them on the X, Y, and Z axes using the angle variable. +The audio data, it gets processed using the FFT analysis, you know. That's where the magic happens. We figure out the size of each frequency band based on the audio data we got. +Oh, and by the way, we update the angle and colorAngle variables based on the audio data, you know, using this thing called linear interpolation to make it look smoother and stuff. +Alright, so we loop through some angles, like from 0 to 360, you know, in steps of 3. For each angle, we calculate the X and Y positions of the sphere, making it move in a circle with a radius of r. The Z position is always zero, man. +We also figure out the size of the sphere based on the value of the corresponding frequency band. And we throw in some Y offset to make it bounce up and down, you know, based on the rotation angle. +The color of the sphere, it changes depending on the angle. We set the fill color accordingly, man. +And finally, we draw the sphere or box at the calculated position and size, you know. Oh, and we use this pushMatrix() and popMatrix() thing to make sure the transformations we do to one sphere don't mess up the others, man. + +# List of classes/assets + +| Class/asset | Source | Author | +|-----------|-----------|--------------| +| Galaxy.java | Self written | Daniel Wu: C21460524 | +| Galaxy2.java | Self written From [reference]() | Daniel Wu: C21460524 | +| AudioHm.java | Self written | Ron Pingol: C21782059 | +| SquaresSpace.java | Self written | Ron Pingol: C21782059 | +| HanaSaku.java | Modified from [Coding train](https://thecodingtrain.com/challenges/55-mathematical-rose-patterns) | Alex Tsang: C21751999| +| AIGenerationMenu.java | Self written | Ernest John Decina: C21394933| +| BigBangUniverse.java | Self written | Ernest John Decina: C21394933| +| DisplayAIGeneratedImage.java | Self written | Ernest John Decina: C21394933| +| FlyingThroughSound.java | Self written | Ernest John Decina: C21394933| +| TEXTBOX.java | Modified from [mitkonikov](https://github.com/mitkonikov/Processing/tree/master/Text_Box) | Ernest John Decina: C21394933| +| SubmitButton.java | Self written | Ernest John Decina: C21394933| +| DownloadAIGeneratedImage.java | Self written | Ernest John Decina: C21394933| +| PostOpenAPI.java | Self written | Ernest John Decina: C21394933| +| background-image.jpg | Refrenced From [Your Name Movie](https://www.imdb.com/title/tt5311514/) | Film Director: Mokoto Shinkai| + + + +Each team member or individual needs to write a paragraph or two explaining what they contributed to the project + +- What they did +- What they are most proud of +- What they learned + +## Visual Dimension 4: Alex Tsang (C21751999) + +### Desc + My visual consists of a rose shape pattern with added petals because of my own preference. + +### Part 1 + + The rose shape petals will constantly change colour and size will change depending on the amplitude and frequency. + +## Learning Outcomes + +### What I did + For my visualizer; what I did was use math to create a rose pattern. By using sin and cos functions I was able to create the petals of the flower and also I was able to use it to give my petal lines dynamic colour. The mathematic equations using trigonometry function and polar coordinates gave this project life. + +```Java + + pApplet.rotate(PApplet.radians(rot)); + for(float i = 0; i < PApplet.TWO_PI; i+= 0.0004f){ + float color = PApplet.map(i, 0, PApplet.TWO_PI, 0, 255); + float colorTwo = PApplet.map(i, 0, PApplet.TWO_PI, 0, 255); + float colorThree = PApplet.map(i, 0, PApplet.TWO_PI, 0, 255); + + // Use sin() and cos() functions to smoothly interpolate between colors + float timeFactor = 0.00005f * pApplet.millis(); // Adjust this factor to control the speed of color change every miilisecond + color += 255 + 255 * PApplet.sin(timeFactor); + colorTwo += 255 + 255 * PApplet.cos(timeFactor); + colorThree += 255 + 255 * PApplet.sin(timeFactor + PApplet.radians(120)); + + // Keep the colors within the range of 0 to 255 + color = color % 255; + colorTwo = colorTwo % 255; + colorThree = colorThree % 255; + + pApplet.stroke(color, colorTwo, colorThree); + + //outer petals aka dots + float r = 100 * PApplet.cos(6*i); + float x = r * PApplet.cos(i); + float y = r * PApplet.sin(i); + + pApplet.point(50 * (x * lerpedAverage), 50 *(y * lerpedAverage)); //2nd petal formation + + + // first 4 petals + r = 100 * PApplet.cos(4 * i); + x = r * PApplet.cos(i); + y = r * PApplet.sin(i); + pApplet.point(50 * (x * lerpedAverage), 50 *(y * lerpedAverage)); + } + + rot += 0.75; + pApplet.popMatrix(); + } + ``` -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); -} + +### What I am most proud of + I am most proud of being able to implement the dynamic colors on the petal lines, making the flower more attractive to look at. I think implementing the math functions was hard as well but I had guidance for that due to the tutorial. + +### What I learned + I learned how OOP can be implemented for bigger projects with multiple people. Through the usage of different classes and objects I learned how polymorphism and things like abstract classes can work in projects with multiple people. I also learned how processing works and how you can draw beautiful things with code. In the future I would like to challenge myself and draw something from scratch, though I think it will be a huge challenge. Learning minim and its methods were also very cool. + +## Visual Dimension 1: Ron Pingol (C21782059) + +### Desc + + My visual consists of multiple shapes that make up multiple rings then transitioning into a cube filled dimesnion, looking like the tesseract area in the movie Interstellar + +### Part 1 + + Multiple coloured shapes will be moving and they will be rotating on a ring. + +### Part 2 + + My Second visual, will transition from the multicoloured shaped. Then lots and lots (like lots), of cubes will appear and when they rotate their colours will change. + +### Part 3 + + This was a difficult assignment as i have never done processing before and learning these things all in one semester was a very tough task. i am proud of drawing my shapes, it made me learn alot of new methods and has opened my eyes to the more art aspect of coding. + +``` private void drawCubeField() { + pApplet.rotateX(angle / 30.0f); + pApplet.rotateY(angle * 1.3f / 30.0f); + pApplet.rotateZ(angle * 0.7f / 30.0f); + pApplet.noStroke(); + fft.forward(audioBuffer); + for (int i = 0; i < numBands; i++) { + bandSize[i] = fft.getBand(i) * 5; + } + angle += PApplet.map(bandSize[0], 0, 100, 0.01f, 0.1f); + colorAngle += PApplet.map(bandSize[1], 0, 100, 0.001f, 0.01f); + for (int i = -200; i < 200; i += 20) { + for (int j = -200; j < 200; j += 20) { + for (int k = -200; k < 200; k += 20) { + float x = i; + float y = j; + float z = k; + float size = PApplet.map(bandSize[(i + 200) / 20], 0, 255, 0, 50); + float yOffset = pApplet.noise(i * noiseScale, j * noiseScale, k * noiseScale) * noiseStrength; + // Assign a different color for each cube based on its position + int cubeColor = pApplet.color(PApplet.map(i + colorAngle, 0, 512, 0, 255), + PApplet.map(j + colorAngle, 0, 512, 0, 255), + PApplet.map(k + colorAngle, 0, 512, 0, 255)); + pApplet.fill(cubeColor); + pApplet.pushMatrix(); + pApplet.translate(x, y + yOffset, z); + pApplet.box(size); + pApplet.popMatrix(); + } + } + } + } ``` -This is an image using a relative URL: +## Visual Dimension 3: Daniel Wu (C21460524) + +### Desc + + In my visual inspired by red giant phase of the sun it first shows a big Sun that is going through its giant phase, it then splits into 4 different Sun's and then it shows the universe collapsing + and shaking and showing lots of chaos. + +### Part 1 + + The first part of my visual shows the Sun slowly growing according to the amplitude of the music. + +### Part 2 -![An image](images/p8.png) + The second part of my visual shows the Sun split into 4 smaller suns rotating around the center of the screen. + +### Part 3 -This is an image using an absolute URL: + The last part of my visual shows the screen shaking and explosions happening according to amplitude. + +### What i am Proud of -![A different image](https://bryanduggandotorg.files.wordpress.com/2019/02/infinite-forms-00045.png?w=595&h=&zoom=2) + There was lots of things that i was proud of in this assignment but the thing that i was most proud of was getting the sphere to split into four seperate sphere and adding the screen shake. I am also proud that i got the spheres to rotate around the center. + +### What i learned + + I learned a lot of things while doing this assignement but the things i learned the most was using the sin and cos libraries to help put detail on the sphere. Most importantly i learned how to work with a group to get work completed on time and to a respectable standard. -This is a youtube video: +``` private void drawCircle() { + float x = windowWidth / 2; + float y = windowHeight / 2; + float amplitude = audioBuffer.level() * 1000; + float diameter = (initialDiameter + amplitude + (timeElapsed * timeScale)) / 2; + // Map the amplitude value to a hue value + pApplet.colorMode(PConstants.HSB, 360, 100, 100); + float hue = PApplet.map(amplitude, 0, 200, 0, 360); + // Calculate the opacity based on a sine wave + float opacity = PApplet.map(PApplet.sin(pApplet.frameCount * 0.05f), -1, 1, 50, 255); + for (int k = 0; k < 4; k++) { + float offsetX = PApplet.cos(rotationAngle) * diameter * 1.5f; + float offsetY = PApplet.sin(rotationAngle) * diameter * 1.5f; + pApplet.pushMatrix(); + pApplet.pushStyle(); + pApplet.translate(x + offsetX, y + offsetY, -diameter / 2); + pApplet.noStroke(); + float adjustedRotationSpeed = PApplet.map(amplitude, 0, 200, rotationSpeed, rotationSpeed * 10); + rotationAngle += adjustedRotationSpeed; + pApplet.fill(hue, 100, 100, opacity); // Use the calculated opacity value + pApplet.rotate(rotationAngle, 1, 1, 0); + pApplet.beginShape(PConstants.TRIANGLES); + int detail = 100; + for (int j = 0; j < detail; j++) { + float theta1 = PApplet.map(j, 0, detail, 0, PConstants.TWO_PI); + float theta2 = PApplet.map(j + 1, 0, detail, 0, PConstants.TWO_PI); + for (int i = 0; i < detail; i++) { + float phi1 = PApplet.map(i, 0, detail, 0, PConstants.PI); + float phi2 = PApplet.map(i + 1, 0, detail, 0, PConstants.PI); + float x1 = diameter * PApplet.sin(phi1) * PApplet.cos(theta1); + float y1 = diameter * PApplet.sin(phi1) * PApplet.sin(theta1); + float z1 = diameter * PApplet.cos(phi1); + float x2 = diameter * PApplet.sin(phi1) * PApplet.cos(theta2); + float y2 = diameter * PApplet.sin(phi1) * PApplet.sin(theta2); + float z2 = diameter * PApplet.cos(phi1); + float x3 = diameter * PApplet.sin(phi2) * PApplet.cos(theta2); + float y3 = diameter * PApplet.sin(phi2) * PApplet.sin(theta2); + float z3 = diameter * PApplet.cos(phi2); + pApplet.vertex(x1, y1, z1); + pApplet.vertex(x2, y2, z2); + pApplet.vertex(x3, y3, z3); + pApplet.vertex(x1, y1, z1); + pApplet.vertex(x3, y3, z3); + pApplet.vertex(x2, y2, z2); + } + } + pApplet.endShape(); + if (amplitude > 20) { + particles.add(new Particle(new PVector(x + offsetX, y + offsetY), hue)); + if (amplitude > 220) { + createExplosion(x + offsetX, y + offsetY, hue, 100); + } + } + pApplet.popMatrix(); + pApplet.popStyle(); + rotationAngle += PConstants.PI / 2; // Divide the full circle into 4 equal parts for each circle + } + pApplet.noStroke(); + // Increment time elapsed + timeElapsed += 1; + } + + ``` -[![YouTube](http://img.youtube.com/vi/J2kHSSFA4NU/0.jpg)](https://www.youtube.com/watch?v=J2kHSSFA4NU) + ## Visual Dimension 2: Ernest John Decina (C21394933) -This is a table: +### Part 1 -| Heading 1 | Heading 2 | -|-----------|-----------| -|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 | + Blackhole eating the universe and eating the stars around it. + +### Part 2 + + An AI taking over from the enventual death of the universe and producing images from the past civilations of human kind. + +### Part 3 + + The last visual shows the Terrain slowly forming again over time after the take over of the AI and represents the circle of life. + +### What im most proud of? + I am most proud of getting an AI Generated image to render to the users screen, this was alot of learning using Oracle's java http library and making sure that a error is prompt to the user if there was any problems. + +### What I learned + I learned how to create POST requests using java and getting information from an API server and then processing that data else where. + +```java + String link= ""; + String payload = String.format("{\"prompt\": \"%s\"}", prompt); + try(CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { + HttpPost request = new HttpPost("https://api.ernestjohndecina.com/api/dalle/image"); + StringEntity params = new StringEntity(payload, ContentType.APPLICATION_JSON); + request.addHeader("content-type", "application/json"); + + request.setEntity(params); + ClassicHttpResponse response = (ClassicHttpResponse) httpClient.execute(request); + System.out.println(response); + String json = EntityUtils.toString(response.getEntity()); + JSONObject responseJson = new JSONObject(json); + String data = responseJson.getString("link"); + link = data; + } catch(Exception e) { + return null; + } + return link; +``` +# References +* ["Something Comforting" - Porter Robinson](https://music.youtube.com/watch?v=9uT-dsBBZew&feature=share) +* [TEXTBOX.java](https://github.com/mitkonikov/Processing/tree/master/Text_Box) +* [Your Name Background Image](https://www.imdb.com/title/tt5311514/) diff --git a/assets/images/ai-image-1.jpg b/assets/images/ai-image-1.jpg new file mode 100644 index 000000000..f25df6ef5 Binary files /dev/null and b/assets/images/ai-image-1.jpg differ diff --git a/images/p8.png b/assets/images/p8.png similarity index 100% rename from images/p8.png rename to assets/images/p8.png diff --git a/assets/song-timings/Something-Conforting-Porter-Robinson-Timings.xlsx b/assets/song-timings/Something-Conforting-Porter-Robinson-Timings.xlsx new file mode 100644 index 000000000..52a2bcfc8 Binary files /dev/null and b/assets/song-timings/Something-Conforting-Porter-Robinson-Timings.xlsx differ diff --git a/java/.classpath b/java/.classpath index 2e063e579..5e00b9944 100644 --- a/java/.classpath +++ b/java/.classpath @@ -22,5 +22,22 @@ + + + + + + + + + + + + + + + + + diff --git a/java/.project b/java/.project index 0d5afed93..7dfd58221 100644 --- a/java/.project +++ b/java/.project @@ -16,12 +16,12 @@ - 1616413840733 + 1678045629032 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/.vscode/launch.json b/java/.vscode/launch.json deleted file mode 100644 index 5f0c7af3b..000000000 --- a/java/.vscode/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "configurations": [ - { - "type": "java", - "name": "CodeLens (Launch) - Main", - "request": "launch", - "mainClass": "ie.tudublin.Main", - "projectName": "java" - } - ] -} \ No newline at end of file diff --git a/java/data/images/ai-image-0.png b/java/data/images/ai-image-0.png new file mode 100644 index 000000000..47b23ff79 Binary files /dev/null and b/java/data/images/ai-image-0.png differ diff --git a/java/data/images/ai-image-1.jpg b/java/data/images/ai-image-1.jpg new file mode 100644 index 000000000..f25df6ef5 Binary files /dev/null and b/java/data/images/ai-image-1.jpg differ diff --git a/java/data/images/background-image.jpg b/java/data/images/background-image.jpg new file mode 100644 index 000000000..70dad882b Binary files /dev/null and b/java/data/images/background-image.jpg differ diff --git a/java/data/songs/REH_AOHARU.mp3 b/java/data/songs/REH_AOHARU.mp3 new file mode 100644 index 000000000..209c96aad Binary files /dev/null and b/java/data/songs/REH_AOHARU.mp3 differ diff --git a/java/data/heroplanet.mp3 b/java/data/songs/heroplanet.mp3 similarity index 100% rename from java/data/heroplanet.mp3 rename to java/data/songs/heroplanet.mp3 diff --git a/java/data/songs/somethingComforting.mp3 b/java/data/songs/somethingComforting.mp3 new file mode 100644 index 000000000..3ce86c04e Binary files /dev/null and b/java/data/songs/somethingComforting.mp3 differ diff --git a/java/lib/commons-cli-1.5.0.jar b/java/lib/commons-cli-1.5.0.jar new file mode 100644 index 000000000..e03645653 Binary files /dev/null and b/java/lib/commons-cli-1.5.0.jar differ diff --git a/java/lib/httpclient5-5.2.1.jar b/java/lib/httpclient5-5.2.1.jar new file mode 100644 index 000000000..b9cdadc37 Binary files /dev/null and b/java/lib/httpclient5-5.2.1.jar differ diff --git a/java/lib/httpclient5-cache-5.2.1.jar b/java/lib/httpclient5-cache-5.2.1.jar new file mode 100644 index 000000000..b5421d032 Binary files /dev/null and b/java/lib/httpclient5-cache-5.2.1.jar differ diff --git a/java/lib/httpclient5-fluent-5.2.1.jar b/java/lib/httpclient5-fluent-5.2.1.jar new file mode 100644 index 000000000..8972e81c0 Binary files /dev/null and b/java/lib/httpclient5-fluent-5.2.1.jar differ diff --git a/java/lib/httpclient5-testing-5.2.1.jar b/java/lib/httpclient5-testing-5.2.1.jar new file mode 100644 index 000000000..ba82998b7 Binary files /dev/null and b/java/lib/httpclient5-testing-5.2.1.jar differ diff --git a/java/lib/httpclient5-win-5.2.1.jar b/java/lib/httpclient5-win-5.2.1.jar new file mode 100644 index 000000000..abe6d592f Binary files /dev/null and b/java/lib/httpclient5-win-5.2.1.jar differ diff --git a/java/lib/httpcore5-5.2.jar b/java/lib/httpcore5-5.2.jar new file mode 100644 index 000000000..225eb5624 Binary files /dev/null and b/java/lib/httpcore5-5.2.jar differ diff --git a/java/lib/httpcore5-h2-5.2.jar b/java/lib/httpcore5-h2-5.2.jar new file mode 100644 index 000000000..eada8ebf3 Binary files /dev/null and b/java/lib/httpcore5-h2-5.2.jar differ diff --git a/java/lib/httpcore5-reactive-5.2.jar b/java/lib/httpcore5-reactive-5.2.jar new file mode 100644 index 000000000..be7ab7398 Binary files /dev/null and b/java/lib/httpcore5-reactive-5.2.jar differ diff --git a/java/lib/httpcore5-testing-5.2.jar b/java/lib/httpcore5-testing-5.2.jar new file mode 100644 index 000000000..0fac88917 Binary files /dev/null and b/java/lib/httpcore5-testing-5.2.jar differ diff --git a/java/lib/java-json.jar b/java/lib/java-json.jar new file mode 100644 index 000000000..2f211e366 Binary files /dev/null and b/java/lib/java-json.jar differ diff --git a/java/lib/jna-5.12.1.jar b/java/lib/jna-5.12.1.jar new file mode 100644 index 000000000..77f8c7ae0 Binary files /dev/null and b/java/lib/jna-5.12.1.jar differ diff --git a/java/lib/jna-platform-5.12.1.jar b/java/lib/jna-platform-5.12.1.jar new file mode 100644 index 000000000..d39193e69 Binary files /dev/null and b/java/lib/jna-platform-5.12.1.jar differ diff --git a/java/lib/json-20140107.jar b/java/lib/json-20140107.jar new file mode 100644 index 000000000..40a325dba Binary files /dev/null and b/java/lib/json-20140107.jar differ diff --git a/java/lib/reactive-streams-1.0.4.jar b/java/lib/reactive-streams-1.0.4.jar new file mode 100644 index 000000000..e58c483f9 Binary files /dev/null and b/java/lib/reactive-streams-1.0.4.jar differ diff --git a/java/lib/rxjava-2.2.21.jar b/java/lib/rxjava-2.2.21.jar new file mode 100644 index 000000000..377d3113e Binary files /dev/null and b/java/lib/rxjava-2.2.21.jar differ diff --git a/java/lib/rxjava-3.1.5.jar b/java/lib/rxjava-3.1.5.jar new file mode 100644 index 000000000..92a1572f6 Binary files /dev/null and b/java/lib/rxjava-3.1.5.jar differ diff --git a/java/lib/slf4j-api-1.7.36.jar b/java/lib/slf4j-api-1.7.36.jar new file mode 100644 index 000000000..7d3ce68d2 Binary files /dev/null and b/java/lib/slf4j-api-1.7.36.jar differ diff --git a/java/src/com/C21394933/drawObjects/AIGenerationMenu.java b/java/src/com/C21394933/drawObjects/AIGenerationMenu.java new file mode 100644 index 000000000..e418d9f27 --- /dev/null +++ b/java/src/com/C21394933/drawObjects/AIGenerationMenu.java @@ -0,0 +1,180 @@ +package com.C21394933.drawObjects; + +import com.C21394933.network.DownloadAIGeneratedImage; +import com.C21394933.network.PostOpenAPI; +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.MusicVisualizer; +import processing.core.PApplet; +import processing.core.PImage; + +public class AIGenerationMenu extends DrawObjectAbstractClass { + static int timingsCounter; + AudioPlayer audioPlayer; + PImage background; + + boolean errorMessage = false; + boolean downloadErrorMessage = false; + boolean downloadMessage = false; + boolean downloadState = false; + int loadingDots = 0; + + private String imageLink = ""; + + + // Draw Objects + TEXTBOX textbox; + SubmitButton submitButton; + + // Constructor + public AIGenerationMenu(PApplet pApplet, AudioBuffer audioBuffer, AudioPlayer audioPlayer, FFT fft, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.audioPlayer = audioPlayer; + this.fft = fft; + + this.textbox = new TEXTBOX(pApplet); + this.submitButton = new SubmitButton(pApplet, (windowWidth / 2) + 80, (windowHeight/ 2) + 100); + this.background = pApplet.loadImage("images/background-image.jpg"); + } // End WaveFormVisualize Constructor + + int frame = 0; + boolean state, pstate; + int time = -1; + public void render() { + pApplet.pushStyle(); + pApplet.background(background); + + this.textbox.DRAW(); + this.submitButton.render(); + textboxLogic(); + checkSubmit(); + renderPrompt(); + renderDownlaodMessage(); + renderDownlaodErrorMessage(); + renderErrorMessage(); + + pApplet.popStyle(); + } + + private void renderPrompt() { + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.fill(255); + pApplet.textAlign(PApplet.CENTER); + pApplet.text("AI Image Generator", (windowWidth / 2) + 180, (windowHeight / 2) - 300); + pApplet.text("Enter image to be generated: ", (windowWidth / 2) + 180, (windowHeight / 2) - 10); + pApplet.popMatrix(); + pApplet.popStyle(); + } + + private void renderDownlaodMessage() { + if(!downloadMessage) return; + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.fill(255); + pApplet.textAlign(PApplet.CENTER); + pApplet.text("Processing AI Generated Image...", (windowWidth / 2) + 180, (windowHeight / 2) - 200); + + pApplet.popMatrix(); + pApplet.popStyle(); + } + + private void renderDownlaodErrorMessage() { + if(!downloadErrorMessage) return; + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.fill(255); + pApplet.textAlign(PApplet.CENTER); + pApplet.text("Unable to download image", (windowWidth / 2) + 180, (windowHeight / 2) - 200); + + pApplet.popMatrix(); + pApplet.popStyle(); + } + + private void renderErrorMessage() { + if(!errorMessage) return; + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.fill(255); + pApplet.textAlign(PApplet.CENTER); + pApplet.text("Cannot process that prompt", (windowWidth / 2) + 180, (windowHeight / 2) - 200); + + pApplet.popMatrix(); + pApplet.popStyle(); + } + + private void textboxLogic() { + if(pApplet.mousePressed) { + this.textbox.PRESSED(this.pApplet.mouseX, this.pApplet.mouseY); + } + + state = pApplet.keyPressed; + if( pApplet.millis() > time && time != -1 ){ + state = false; + } + if(state != pstate){ + if( state ){ + time = pApplet.millis() + 1000; + textbox.KEYPRESSED(pApplet.key, pApplet.keyCode); + } else { + time = -1; + } + } + pApplet.key = ' '; + pstate = state; // Update previous state for next loop. + } + + + + private void checkSubmit() { + if(!submitButton.getSubmitState() || downloadState) return; + + downloadState = true; + System.out.println(textbox.Text); + queryDALLE(textbox.Text); + } + + private void queryDALLE(String query) { + downloadMessage = true; + errorMessage = false; + + new Thread(() -> { + imageLink = PostOpenAPI.run(query); + if(imageLink == null) { + downloadMessage = false; + errorMessage = true; + downloadState = false; + + System.out.println("Failed query"); + this.submitButton.setSubmitStateFalse(); + textbox.resetText(); + return; + } + + // Download image + if(!DownloadAIGeneratedImage.downloadImage(imageLink)) { + downloadErrorMessage = true; + downloadState = false; + this.submitButton.setSubmitStateFalse(); + textbox.resetText(); + return; + } + + // Start Visualizer + MusicVisualizer.timingsCounter++; + audioPlayer.play(); + }).start(); + } +} diff --git a/java/src/com/C21394933/drawObjects/BigBangUniverse.java b/java/src/com/C21394933/drawObjects/BigBangUniverse.java new file mode 100644 index 000000000..b60bfdd1d --- /dev/null +++ b/java/src/com/C21394933/drawObjects/BigBangUniverse.java @@ -0,0 +1,130 @@ +package com.C21394933.drawObjects; + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.Utils; +import processing.core.PApplet; + +public class BigBangUniverse extends DrawObjectAbstractClass { + // Private Variables + float bigBangRadiusLerped = 0.0f; + float bigBangRotate = 0.0f; + float bigBangRotateSpeed = 0.02f; + float bigBangRotateLerped = 0.0f; + + float ringLerped = 0.0f; + + int[] frequencyIndex; + + int totalStars = 200; + float[][] starPositions = new float[totalStars][2]; + + // Constructor + public BigBangUniverse(PApplet pApplet2, AudioBuffer audioBuffer, FFT fft, int windowWidth, int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = fft; + + for(int counter = 0; counter < totalStars; counter++) { + starPositions[counter][0] = pApplet.random(-2000, windowWidth + 2000); + starPositions[counter][1] = pApplet.random(-2000, windowHeight + 2000); + } // End for + } // End WaveFormVisualize Constructor + + public void render() { + drawBigBang(); + } // End void render() + + private void drawBigBang() { + frequencyIndex = Utils.getHighestFrequencyIndex(fft, audioBuffer); + drawSphere(); + drawBlackHole(); + drawStarField(); + } // End void drawBigBang() + + private void drawSphere() { + float chageRadius = 10.0f; + float highestBassFrequency = fft.indexToFreq(frequencyIndex[0]); + + // Render Sun + + bigBangRadiusLerped = PApplet.lerp(bigBangRadiusLerped, highestBassFrequency, 0.2f) * 1.1f; + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.translate(windowWidth / 2, windowHeight / 2, -1000); + pApplet.rotateX(bigBangRotate); + pApplet.rotateY(bigBangRotate); + pApplet.rotateZ(bigBangRotate); + + drawRings(); + + // Planets + for(int planetIndex = 0; planetIndex < 30; planetIndex++) { + pApplet.fill(pApplet.color(200 * planetIndex % 255, 255, 255)); + pApplet.rotateZ(PApplet.radians(chageRadius + (chageRadius * planetIndex))); + pApplet.translate(0, ringLerped * (2 * planetIndex), 0); + pApplet.sphere(0.9f * planetIndex); + } + + bigBangRotate = bigBangRotate + bigBangRotateSpeed; + + + pApplet.popMatrix(); + pApplet.popStyle(); + } // End void drawSphere + + private void drawRings() { + float baseRadius = 4f; + ringLerped = PApplet.lerp(ringLerped, frequencyIndex[1], 0.4f); + + pApplet.noFill(); + pApplet.stroke(255); + for(int circleIndex = 0; circleIndex < 50; circleIndex++) { + pApplet.circle(0, 0, ringLerped * baseRadius * circleIndex); + } // End for + } + + int counter = 0; + private void drawBlackHole() { + pApplet.pushMatrix(); + + pApplet.translate(windowWidth / 2, windowHeight / 2, -1000); + + pApplet.pushStyle(); + pApplet.stroke(255); + pApplet.strokeWeight(20); + pApplet.noFill(); + pApplet.circle(0, 0, counter * 2.2f); + pApplet.noStroke(); + pApplet.popStyle(); + pApplet.pushStyle(); + pApplet.fill(0); + pApplet.noStroke(); + pApplet.sphere(counter); + + counter += 2; + pApplet.popMatrix(); + pApplet.noStroke(); + pApplet.popStyle(); + } // End void drawStarField() + + private void drawStarField() { + pApplet.pushMatrix(); + pApplet.pushStyle(); + + // Render Star Field + pApplet.translate(0, 0, -2000); + for(int starIndex = 0; starIndex < totalStars; starIndex++) { + pApplet.circle(starPositions[starIndex][0], starPositions[starIndex][1], 20); + } // End for + + + pApplet.popMatrix(); + pApplet.popStyle(); + } // End void drawStarField() +} diff --git a/java/src/com/C21394933/drawObjects/DisplayAIGeneratedImage.java b/java/src/com/C21394933/drawObjects/DisplayAIGeneratedImage.java new file mode 100644 index 000000000..c0f9a7e6b --- /dev/null +++ b/java/src/com/C21394933/drawObjects/DisplayAIGeneratedImage.java @@ -0,0 +1,86 @@ +package com.C21394933.drawObjects; + + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.Utils; +import processing.core.PApplet; +import processing.core.PImage; + +public class DisplayAIGeneratedImage extends DrawObjectAbstractClass { + // Private Feilds + PImage aiGeneratedImage; + float position = 30; + boolean loadImageState = false; + float tiles; + float tileSize; + float rotate = 10; + + public DisplayAIGeneratedImage(PApplet pApplet2, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = new FFT(2048, 44100); + } // End WaveFormVisualize Constructor + + public void render() { + loadImage(); + drawAIGeneratedImage(); + } // End void render() + + public void drawAIGeneratedImage() { + if(rotate % 5 == 0 && tiles < 512) + tiles += 1; + + tileSize = 512 / tiles; + + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.color(255, 255, 255); + pApplet.noStroke(); + + pApplet.translate((windowWidth / 2) - 256, (windowHeight / 2) - 256, 500 - rotate); + rotate += 1; + + for(int x = 0; x < tiles; x++) { + for(int y = 0; y < tiles; y++) { + + int pixelValue = aiGeneratedImage.get((int)(x * tileSize), (int)(y * tileSize)); + float size = PApplet.map(pApplet.brightness(pixelValue), 0, 255, 0, 5); + float brightness = PApplet.map(pApplet.brightness(pixelValue), 0, 255, 0, 100); + + pApplet.pushMatrix(); + pApplet.translate(0, 0, brightness); + pApplet.fill(pixelValue); + pApplet.circle((x * tileSize), (y * tileSize), size); + pApplet.popMatrix(); + } // End for + } // End for + // pApplet.image(aiGeneratedImage, windowWidth / 2, windowHeight / 2); + + + pApplet.popStyle(); + pApplet.popMatrix(); + } // End void drawWaveForm() + + public void drawFrequencySpectrum() { + int[] highestFrequencyIndex = Utils.getHighestFrequencyIndex(fft, audioBuffer); + pApplet.stroke(255); + pApplet.line(highestFrequencyIndex[0] * 2.0f, windowHeight, highestFrequencyIndex[0] * 2.0f, windowHeight - fft.getBand( highestFrequencyIndex[0]) * 5.0f); + pApplet.line(highestFrequencyIndex[1] * 2.0f, windowHeight, highestFrequencyIndex[1] * 2.0f, windowHeight - fft.getBand( highestFrequencyIndex[1]) * 5.0f); + pApplet.line(highestFrequencyIndex[2] * 2.0f, windowHeight, highestFrequencyIndex[2] * 2.0f, windowHeight - fft.getBand( highestFrequencyIndex[2]) * 5.0f); + } // End void drawFrequencySpectrum() + + + private void loadImage() { + if(loadImageState) { + loadImageState = true; + return; + } + aiGeneratedImage = pApplet.loadImage("images/ai-image-0.png"); + } +} // End class WaveFormVisualize diff --git a/java/src/com/C21394933/drawObjects/FlyingThroughSound.java b/java/src/com/C21394933/drawObjects/FlyingThroughSound.java new file mode 100644 index 000000000..67f0aba2d --- /dev/null +++ b/java/src/com/C21394933/drawObjects/FlyingThroughSound.java @@ -0,0 +1,120 @@ +package com.C21394933.drawObjects; + +import java.util.ArrayList; + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.Utils; +import processing.core.PApplet; + +public class FlyingThroughSound extends DrawObjectAbstractClass { + // Private Fields + private int cols; + private int rows; + private int scale = 20; + private int terrainWidth = 3000; + private int terrainHeight = 2000; + private float flyingPosition; + private ArrayList> terrainBassArrayList; + private ArrayList> terrainTrebbleArrayList; + private int colourR = 0; + private int colourG = 0; + private int colourB = 0; + private int oldHighest = 0; + + + public FlyingThroughSound(PApplet pApplet2, AudioBuffer audioBuffer, FFT fft, int windowWidth, int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = fft; + + this.cols = terrainWidth / scale; + this.rows = terrainHeight / scale; + this.terrainBassArrayList = new ArrayList>(); + this.terrainTrebbleArrayList = new ArrayList>(); + + setup(); + } // End FlyingThroughSound Constructor + + private void setup() { + for(int indexCols = 0; indexCols < cols; indexCols++) { + terrainBassArrayList.add(indexCols, new ArrayList()); + terrainTrebbleArrayList.add(indexCols, new ArrayList()); + for(int indexRows = 0; indexRows < rows; indexRows++) { + terrainBassArrayList.get(indexCols).add(indexRows, 0.0f); + terrainTrebbleArrayList.get(indexCols).add(indexRows, 0.0f); + } // End for + } // End for + } + + public void render() { + drawTerrain(); + } // End void render() + + + private void drawTerrain() { + pApplet.pushMatrix(); + pApplet.pushStyle(); + + int highestBass = Utils.getHighestFrequencyIndex(fft, audioBuffer)[0]; + int highestTrebble = Utils.getHighestFrequencyIndex(fft, audioBuffer)[1]; + + flyingPosition -= -.1; + + float yoff = flyingPosition; + for(int y = 0; y < rows; y++) { + float xoff = 0; + for(int x = 0; x < cols; x++) { + terrainTrebbleArrayList.get(x).set(y, PApplet.map(pApplet.noise(xoff, yoff), 0, 1, -100, highestTrebble * 5)); + terrainBassArrayList.get(x).set(y, PApplet.map(pApplet.noise(xoff, yoff), 0, 1, -100, highestBass * 10)); + xoff += 0.2; + } // End for + yoff += 0.2; + } // End for + oldHighest = highestBass; + + pApplet.background(0); + pApplet.translate(+300, 300); + pApplet.rotateX(PApplet.PI / 2.5f); + // pApplet.fill(200, 200, 200, 150); + + if(colourB < 200) colourB++; + else if(colourR < 200) colourR++; + else colourG++; + + pApplet.translate(-terrainWidth / 2, -terrainHeight / 2); + + for(int y = 0; y < rows - 1; y++) { + pApplet.beginShape(PApplet.TRIANGLE_STRIP); + + for(int x = 0; x < cols; x++) { + pApplet.fill(terrainBassArrayList.get(x).get(y) + colourR, terrainBassArrayList.get(x).get(y) + colourG, terrainBassArrayList.get(x).get(y) + colourB, 1000); + pApplet.vertex(x * scale, y * scale, terrainBassArrayList.get(x).get(y)); + pApplet.vertex(x * scale, (y + 1) * scale, terrainBassArrayList.get(x).get(y + 1)); + } // End for + + pApplet.endShape(); + } // End for + + for(int y = 0; y < rows - 1; y++) { + pApplet.beginShape(PApplet.TRIANGLE_STRIP); + + for(int x = 0; x < cols; x++) { + pApplet.fill(terrainBassArrayList.get(x).get(y) + colourR, terrainBassArrayList.get(x).get(y) + colourG, terrainBassArrayList.get(x).get(y) + 80, 1000); + pApplet.vertex(x * scale, y * scale + 200, -terrainTrebbleArrayList.get(x).get(y) + 250); + pApplet.vertex(x * scale, ((y + 1) * scale) + 200, -terrainTrebbleArrayList.get(x).get(y + 1) + 250); + } // End for + + pApplet.endShape(); + } // End for + + + + + pApplet.popMatrix(); + pApplet.popStyle(); + } // End void drawTerrain() +} // End class FlyingThroughSound diff --git a/java/src/com/C21394933/drawObjects/SubmitButton.java b/java/src/com/C21394933/drawObjects/SubmitButton.java new file mode 100644 index 000000000..073d884ac --- /dev/null +++ b/java/src/com/C21394933/drawObjects/SubmitButton.java @@ -0,0 +1,86 @@ +package com.C21394933.drawObjects; + +import ie.tudublin.DrawObjectAbstractClass; +import processing.core.PApplet; + +public class SubmitButton extends DrawObjectAbstractClass { + private int x; + private int y; + private int rectSizeX = 200; + private int rectSizeY = 50; + private boolean submitState = false; + + + // Constructor + public SubmitButton(PApplet pApplet, int x, int y) { + this.pApplet = pApplet; + this.x = x; + this.y = y; + } // End WaveFormVisualize Constructor + + public void render() { + drawButton(); + onClick(); + } + + private void drawButton() { + pApplet.pushMatrix(); + pApplet.pushStyle(); + + // Draw button + pApplet.stroke(255); + pApplet.fill(190); + + if(hoverRect()) pApplet.fill(150); + if(submitState) pApplet.fill(0,150, 0); + pApplet.rect(x, y, rectSizeX, rectSizeY); + textDraw(); + + pApplet.popMatrix(); + pApplet.popStyle(); + } + + private void textDraw() { + pApplet.pushMatrix(); + pApplet.pushStyle(); + + // Draw button + pApplet.fill(255); + pApplet.textAlign(PApplet.CENTER); + pApplet.text("Submit", x + (rectSizeX / 2), y + (rectSizeY / 2) + 8); + + pApplet.popMatrix(); + pApplet.popStyle(); + } + + private boolean hoverRect() { + if (pApplet.mouseX >= x && pApplet.mouseX <= x+rectSizeX && pApplet.mouseY >= y && pApplet.mouseY <= y+rectSizeY) { + return true; + } else { + return false; + } + } + + private boolean onClick() { + if (pApplet.mouseX >= x && pApplet.mouseX <= x+rectSizeX && pApplet.mouseY >= y && pApplet.mouseY <= y+rectSizeY) { + if(!pApplet.mousePressed || submitState) return false; + submitState = true; + return true; + } + else { + return false; + } + } + + public void setSubmitStateTrue() { + this.submitState = true; + } + + public void setSubmitStateFalse() { + this.submitState = false; + } + + public boolean getSubmitState() { + return submitState; + } +} diff --git a/java/src/com/C21394933/drawObjects/TEXTBOX.java b/java/src/com/C21394933/drawObjects/TEXTBOX.java new file mode 100644 index 000000000..35ab2f9d2 --- /dev/null +++ b/java/src/com/C21394933/drawObjects/TEXTBOX.java @@ -0,0 +1,124 @@ +package com.C21394933.drawObjects; + +import ie.tudublin.DrawObjectAbstractClass; +import processing.core.PApplet; + +public class TEXTBOX extends DrawObjectAbstractClass { + public int X = 0, Y = 0, H = 50, W = 600; + public int TEXTSIZE = 24; + + // COLORS + public int Background; + public int Foreground; + public int BackgroundSelected; + public int Border; + + public boolean BorderEnable = false; + public int BorderWeight = 1; + + public String Text = ""; + public int TextLength = 0; + + private boolean selected = false; + + TEXTBOX(PApplet pApplet) { + this.pApplet = pApplet; + + Background = pApplet.color(140, 140, 140); + Foreground = pApplet.color(0, 0, 0); + BackgroundSelected = pApplet.color(160, 160, 160); + Border = pApplet.color(30, 30, 30); + + X = (this.pApplet.width / 2) - 300; + Y = this.pApplet.height / 2; + } + + void DRAW() { + // DRAWING THE BACKGROUND + if (selected) { + pApplet.fill(BackgroundSelected); + } else { + pApplet.fill(Background); + } + + if (BorderEnable) { + pApplet.strokeWeight(BorderWeight); + pApplet.stroke(Border); + } else { + pApplet.noStroke(); + } + + pApplet.rect(X, Y, W, H); + + // DRAWING THE TEXT ITSELF + pApplet.fill(Foreground); + pApplet.textSize(TEXTSIZE); + pApplet.text(Text, X + (pApplet.textWidth("a") / 2), Y + TEXTSIZE); + } + + // IF THE KEYCODE IS ENTER RETURN 1 + // ELSE RETURN 0 + boolean KEYPRESSED(char KEY, int KEYCODE) { + if (selected) { + if (KEYCODE == (int)PApplet.BACKSPACE) { + BACKSPACE(); + } else if (KEY == ' ') { + // SPACE + addText(' '); + } else if (KEYCODE == (int)PApplet.ENTER) { + return true; + } else { + // CHECK IF THE KEY IS A LETTER OR A NUMBER + boolean isKeyCapitalLetter = (KEY >= 'A' && KEY <= 'Z'); + boolean isKeySmallLetter = (KEY >= 'a' && KEY <= 'z'); + boolean isKeyNumber = (KEY >= '0' && KEY <= '9'); + + if (isKeyCapitalLetter || isKeySmallLetter || isKeyNumber) { + addText(KEY); + } + } + } + + return false; + } + + private void addText(char text) { + // IF THE TEXT WIDHT IS IN BOUNDARIES OF THE TEXTBOX + if (pApplet.textWidth(Text + text) < W) { + Text += text; + TextLength++; + } + } + + public void resetText() { + TextLength = 0; + Text = ""; + } + + private void BACKSPACE() { + if (TextLength - 1 >= 0) { + Text = Text.substring(0, TextLength - 1); + TextLength--; + } + } + + // FUNCTION FOR TESTING IS THE POINT + // OVER THE TEXTBOX + private boolean overBox(int x, int y) { + if (x >= X && x <= X + W) { + if (y >= Y && y <= Y + H) { + return true; + } + } + + return false; + } + + void PRESSED(int x, int y) { + if (overBox(x, y)) { + selected = true; + } else { + selected = false; + } + } + } \ No newline at end of file diff --git a/java/src/com/C21394933/drawObjects/WaveFormVisualize.java b/java/src/com/C21394933/drawObjects/WaveFormVisualize.java new file mode 100644 index 000000000..b75b66c43 --- /dev/null +++ b/java/src/com/C21394933/drawObjects/WaveFormVisualize.java @@ -0,0 +1,53 @@ +package com.C21394933.drawObjects; + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.Utils; +import processing.core.PApplet; + +public class WaveFormVisualize extends DrawObjectAbstractClass { + // Private Feilds + float position = 30; + + public WaveFormVisualize(PApplet pApplet2, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = new FFT(2048, 44100); + } // End WaveFormVisualize Constructor + + public void render() { + // Utils.waitFor(200); + // drawFrequencySpectrum(); + drawWaveForm(); + } // End void render() + + public void drawWaveForm() { + float half = windowHeight / 2; + + for (int i = 0; i < audioBuffer.size(); i++) { + pApplet.strokeWeight(2); + pApplet.stroke(255); + pApplet.point(i, position + audioBuffer.get(i) * (half - 400)); + pApplet.stroke(0); + pApplet.line(i, position, i, position + audioBuffer.get(i) * (half - 400)); + } // End for + + position += 10; + + if (position >= 740) { + position = 0; + pApplet.background(0); + } // End ifF + } // End void drawWaveForm() + + public void drawFrequencySpectrum() { + int[] highestFrequencyIndex = Utils.getHighestFrequencyIndex(fft, audioBuffer); + pApplet.stroke(255); + pApplet.line(highestFrequencyIndex[0] * 2.0f, windowHeight, highestFrequencyIndex[0] * 2.0f, windowHeight - fft.getBand( highestFrequencyIndex[0]) * 5.0f); + pApplet.line(highestFrequencyIndex[1] * 2.0f, windowHeight, highestFrequencyIndex[1] * 2.0f, windowHeight - fft.getBand( highestFrequencyIndex[1]) * 5.0f); + pApplet.line(highestFrequencyIndex[2] * 2.0f, windowHeight, highestFrequencyIndex[2] * 2.0f, windowHeight - fft.getBand( highestFrequencyIndex[2]) * 5.0f); + } // End void drawFrequencySpectrum() +} // End class WaveFormVisualize diff --git a/java/src/com/C21394933/network/DownloadAIGeneratedImage.java b/java/src/com/C21394933/network/DownloadAIGeneratedImage.java new file mode 100644 index 000000000..ea4e1d779 --- /dev/null +++ b/java/src/com/C21394933/network/DownloadAIGeneratedImage.java @@ -0,0 +1,35 @@ +package com.C21394933.network; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.net.URL; + + +public class DownloadAIGeneratedImage { + public static boolean downloadImage(String link) { + try { + URL url = new URL(link); + InputStream in = new BufferedInputStream(url.openStream()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[1024]; + int n = 0; + while (-1!=(n=in.read(buf))){ + out.write(buf, 0, n); + } + out.close(); + in.close(); + byte[] response = out.toByteArray(); + + FileOutputStream fos = new FileOutputStream("./java/data/images/ai-image-0.png"); + fos.write(response); + fos.close(); + System.out.println("Download Complete"); + } catch(Exception e) { + return false; + } + + return true; + } // End void downloadImage +} diff --git a/java/src/com/C21394933/network/PostOpenAPI.java b/java/src/com/C21394933/network/PostOpenAPI.java new file mode 100644 index 000000000..3620daa2f --- /dev/null +++ b/java/src/com/C21394933/network/PostOpenAPI.java @@ -0,0 +1,40 @@ +package com.C21394933.network; + +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.entity.StringEntity; +import org.json.JSONArray; +import org.json.JSONObject; + +public class PostOpenAPI { + static public String run(String prompt) { + String link= ""; + + String payload = String.format("{\"prompt\": \"%s\"}", prompt); + + try(CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { + HttpPost request = new HttpPost("https://api.ernestjohndecina.com/api/dalle/image"); + StringEntity params = new StringEntity(payload, ContentType.APPLICATION_JSON); + request.addHeader("content-type", "application/json"); + + + request.setEntity(params); + ClassicHttpResponse response = (ClassicHttpResponse) httpClient.execute(request); + System.out.println(response); + + String json = EntityUtils.toString(response.getEntity()); + JSONObject responseJson = new JSONObject(json); + String data = responseJson.getString("link"); + link = data; + } catch(Exception e) { + return null; + } + + return link; + } // End void postOpenAPI + +} diff --git a/java/src/com/C21394933/visual2/StartMenuVisual.java b/java/src/com/C21394933/visual2/StartMenuVisual.java new file mode 100644 index 000000000..89a8edafa --- /dev/null +++ b/java/src/com/C21394933/visual2/StartMenuVisual.java @@ -0,0 +1,39 @@ +package com.C21394933.visual2; + +import com.C21394933.drawObjects.AIGenerationMenu; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ie.tudublin.VisualAbstractClass; +import processing.core.PApplet; + +public class StartMenuVisual extends VisualAbstractClass { + // Private Variables + + // Draw Objects + AIGenerationMenu aiGenerationMenu; + + + // LEAVE ALONE + public StartMenuVisual(PApplet pApplet, AudioBuffer audioBuffer, AudioPlayer audioPlayer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.audioPlayer = audioPlayer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + + loadRenderObjects(); + } // End Visual2 Constructor + + // Draw Function for Start Menu Visual + public void drawVisual() { + aiGenerationMenu.render(); + } // End drawVisual2 + + + // Load Render Objects + private void loadRenderObjects() { + this.aiGenerationMenu = new AIGenerationMenu(this.pApplet, this.audioBuffer, this.audioPlayer, this.fft, this.windowHeight, this.windowHeight); + } // End void oadRenderObjects + +} diff --git a/java/src/com/C21394933/visual2/Visual2.java b/java/src/com/C21394933/visual2/Visual2.java new file mode 100644 index 000000000..25ff9dab0 --- /dev/null +++ b/java/src/com/C21394933/visual2/Visual2.java @@ -0,0 +1,73 @@ +package com.C21394933.visual2; + +// Dependencies +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.VisualAbstractClass; +import processing.core.PApplet; +import java.util.ArrayList; + + +// Draw Objects +import com.C21394933.drawObjects.WaveFormVisualize; +import com.C21394933.drawObjects.BigBangUniverse; +import com.C21394933.drawObjects.DisplayAIGeneratedImage; +import com.C21394933.drawObjects.FlyingThroughSound; + +public class Visual2 extends VisualAbstractClass { + // Private Variables + int[] visual2Timings = {780, 935, 1075}; + int drawObjectsIndex = 0; + ArrayList drawObjects; + + // Render Objects + WaveFormVisualize waveFormVisualize; + BigBangUniverse bigBangUniverse; + DisplayAIGeneratedImage displayAIGeneratedImage; + FlyingThroughSound flyingThroughSound; + + // LEAVE ALONE + public Visual2(PApplet pApplet, AudioBuffer audioBuffer, AudioPlayer audioPlayer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.audioPlayer = audioPlayer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.fft = new FFT(2048, 44100); + + drawObjects = new ArrayList(); + loadRenderObjects(); + } // End Visual2 Constructor + + // Draw Function for Visual 2 + public void drawVisual() { + changeDrawObject(); + + drawObjects.get(drawObjectsIndex).render(); + } // End drawVisual2 + + + + // Load Render Objects + private void loadRenderObjects() { + // Create your draw Objects here + this.waveFormVisualize = new WaveFormVisualize(this.pApplet, this.audioBuffer, this.windowHeight, this.windowHeight); + this.bigBangUniverse = new BigBangUniverse(pApplet, audioBuffer, fft, windowWidth, windowHeight); + this.displayAIGeneratedImage = new DisplayAIGeneratedImage(pApplet, audioBuffer, windowWidth, windowHeight); + this.flyingThroughSound = new FlyingThroughSound(pApplet, audioBuffer, fft, windowWidth, windowHeight); + + + drawObjects.add(bigBangUniverse); + drawObjects.add(displayAIGeneratedImage); + drawObjects.add(flyingThroughSound); + drawObjects.add(flyingThroughSound); + } // End void oadRenderObjects + + + private void changeDrawObject() { + if(audioPlayer.position() / 100 > visual2Timings[drawObjectsIndex]) + drawObjectsIndex++; + } +} // End class Visual2 diff --git a/java/src/com/C21460524/drawObjects/ExampleDraw.java b/java/src/com/C21460524/drawObjects/ExampleDraw.java new file mode 100644 index 000000000..75ba78d5b --- /dev/null +++ b/java/src/com/C21460524/drawObjects/ExampleDraw.java @@ -0,0 +1,25 @@ +package com.C21460524.drawObjects; + +// Dependencies +import ddf.minim.AudioBuffer; +import ie.tudublin.DrawObjectAbstractClass; +import processing.core.PApplet; + +public class ExampleDraw extends DrawObjectAbstractClass { + // Private Feilds + PApplet pApplet; + int windowWidth; + int windowHeight; + + AudioBuffer audioBuffer; + public ExampleDraw(PApplet pApplet, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + } // End ExampleDraw Constructor + + public void drawExample() { + pApplet.circle(windowWidth / 2, windowHeight / 2, 500); + } // End void drawExample() +} // End class ExampleDraw diff --git a/java/src/com/C21460524/drawObjects/Galaxy.java b/java/src/com/C21460524/drawObjects/Galaxy.java new file mode 100644 index 000000000..ff3057369 --- /dev/null +++ b/java/src/com/C21460524/drawObjects/Galaxy.java @@ -0,0 +1,194 @@ +package com.C21460524.drawObjects; + + +// Dependencies +import ddf.minim.AudioBuffer; +import processing.core.PApplet; +import processing.core.PConstants; +import ie.tudublin.DrawObjectAbstractClass; + + +public class Galaxy extends DrawObjectAbstractClass +{ + + // Private Fields + PApplet pApplet; + int windowWidth; + int windowHeight; + + AudioBuffer audioBuffer; + + // Star fields + int numStars = 50; + Star[] stars = new Star[numStars]; + float starSpeed = 1.5f; // speed at which stars move + + + + public Galaxy(PApplet pApplet, AudioBuffer audioBuffer, int windowWidth, int windowHeight) + { + + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + + // Initialize stars + for (int i = 0; i < numStars; i++) + { + + float x = i * windowWidth / numStars; // evenly space stars along the x axis + float y = pApplet.random(0, windowHeight); + stars[i] = new Star(x, y); + + } + } + + + public void drawExample() + { + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + pApplet.background(0); + pApplet.stroke(255); + pApplet.strokeWeight(2); + + // Draw starfield + drawStarfield(); + + // Draw Circle + drawCircle(); + + // Screen flash effect + drawScreenFlash(); + + pApplet.popMatrix(); + pApplet.popStyle(); + + } + + private float timeElapsed = 0; + private float timeScale = 0.04f; // controls the rate at which the diameter increases + private float initialDiameter = 300; + private float rotationAngle = 0; + private float rotationSpeed = 0.01f; // controls the speed of rotation + + private void drawCircle() + { + + float x = windowWidth / 2; + float y = windowHeight / 2; + + float amplitude = audioBuffer.level() * 1000; + float diameter = initialDiameter + amplitude + (timeElapsed * timeScale); + + // Map the amplitude value to a hue value + pApplet.colorMode(PConstants.HSB, 360, 100, 100); + float hue = PApplet.map(amplitude, 0, 200, 0, 360); + pApplet.fill(hue, 100, 100); + + // Draw sphere + pApplet.pushMatrix(); + pApplet.pushStyle(); + pApplet.translate(x, y, -diameter / 2); + + + pApplet.noStroke(); + + float adjustedRotationSpeed = PApplet.map(amplitude, 0, 350, rotationSpeed, rotationSpeed * 40); + rotationAngle += adjustedRotationSpeed; + + pApplet.rotate(rotationAngle, 1, 1, 0); + pApplet.beginShape(PConstants.TRIANGLES); + + int detail = 100; + for (int j = 0; j < detail; j++) { + float theta1 = PApplet.map(j, 0, detail, 0, PConstants.TWO_PI); + float theta2 = PApplet.map(j + 1, 0, detail, 0, PConstants.TWO_PI); + + for (int i = 0; i < detail; i++) { + float phi1 = PApplet.map(i, 0, detail, 0, PConstants.PI); + float phi2 = PApplet.map(i + 1, 0, detail, 0, PConstants.PI); + float x1 = diameter * PApplet.sin(phi1) * PApplet.cos(theta1); + float y1 = diameter * PApplet.sin(phi1) * PApplet.sin(theta1); + float z1 = diameter * PApplet.cos(phi1); + float x2 = diameter * PApplet.sin(phi1) * PApplet.cos(theta2); + float y2 = diameter * PApplet.sin(phi1) * PApplet.sin(theta2); + float z2 = diameter * PApplet.cos(phi1); + float x3 = diameter * PApplet.sin(phi2) * PApplet.cos(theta2); + float y3 = diameter * PApplet.sin(phi2) * PApplet.sin(theta2); + float z3 = diameter * PApplet.cos(phi2); + pApplet.vertex(x1, y1, z1); + pApplet.vertex(x2, y2, z2); + pApplet.vertex(x3, y3, z3); + pApplet.vertex(x1, y1, z1); + pApplet.vertex(x3, y3, z3); + pApplet.vertex(x2, y2, z2); + + } + + } + + pApplet.endShape(); + pApplet.popMatrix(); + pApplet.popStyle(); + + + pApplet.noStroke(); + + // Increment time elapsed + timeElapsed += 1; + } + + public void render() { + drawExample(); + } // End void render() + + + private void drawScreenFlash() { + float amplitude = audioBuffer.level() * 1000; + float flashOpacity = PApplet.map(amplitude, 0, 800, 0, 255); + pApplet.fill(255, 255, 255, flashOpacity); + pApplet.rect(0, 0, windowWidth, windowHeight); + } + + + + private void drawStarfield() { + for (int i = 0; i < numStars; i++) { + Star star = stars[i]; + float radius = pApplet.random(1, 3); + float diameter = radius * 2; + // Move star to the right + star.x = (star.x + starSpeed) % windowWidth; + + // Draw star with a glowing effect + int glowAlpha = 100; + int numGlowLayers = 3; + for (int j = numGlowLayers; j > 0; j--) { + pApplet.fill(255, glowAlpha / j); + pApplet.ellipse(star.x, star.y, diameter * j, diameter * j); + } + } + } + + + + // Inner class representing a star object + private class Star + { + float x; + + float y; + + public Star(float x, float y) { + this.x = x; + this.y = y; + } + + } + + +} diff --git a/java/src/com/C21460524/drawObjects/Galaxy2.java b/java/src/com/C21460524/drawObjects/Galaxy2.java new file mode 100644 index 000000000..5fae9c02f --- /dev/null +++ b/java/src/com/C21460524/drawObjects/Galaxy2.java @@ -0,0 +1,263 @@ +package com.C21460524.drawObjects; + +import java.util.ArrayList; + +// Dependencies +import ddf.minim.AudioBuffer; +import processing.core.PApplet; +import processing.core.PConstants; +import processing.core.PVector; +import ie.tudublin.DrawObjectAbstractClass; + +public class Galaxy2 extends DrawObjectAbstractClass { + + // Private Fields + PApplet pApplet; + int windowWidth; + int windowHeight; + + AudioBuffer audioBuffer; + + // Star fields + int numStars = 50; + Star[] stars = new Star[numStars]; + float starSpeed = 1.5f; // speed at which stars move + + public Galaxy2(PApplet pApplet, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + + // Initialize stars + for (int i = 0; i < numStars; i++) { + + float x = i * windowWidth / numStars; // evenly space stars along the x axis + float y = pApplet.random(0, windowHeight); + stars[i] = new Star(x, y); + + } + } + + // Particle system + ArrayList particles = new ArrayList<>(); + + + public void drawExample() { + + pApplet.pushMatrix(); + pApplet.pushStyle(); + + // Draw earthquake effect + drawEarthquakeEffect(); + + pApplet.background(0); + pApplet.stroke(255); + pApplet.strokeWeight(2); + + // Draw starfield + drawStarfield(); + + // Draw Circle + drawCircle(); + + // Draw particle system + updateParticles(); + + // Screen flash effect + drawScreenFlash(); + + pApplet.popMatrix(); + pApplet.popStyle(); + + } + + private float timeElapsed = 0; + private float timeScale = 0.04f; // controls the rate at which the diameter increases + private float initialDiameter = 300; + private float rotationAngle = 0; + private float rotationSpeed = 0.005f; // controls the speed of rotation + + private void drawCircle() { + float x = windowWidth / 2; + float y = windowHeight / 2; + float amplitude = audioBuffer.level() * 1000; + float diameter = (initialDiameter + amplitude + (timeElapsed * timeScale)) / 2; + + // Map the amplitude value to a hue value + pApplet.colorMode(PConstants.HSB, 360, 100, 100); + float hue = PApplet.map(amplitude, 0, 200, 0, 360); + + // Calculate the opacity based on a sine wave + float opacity = PApplet.map(PApplet.sin(pApplet.frameCount * 0.05f), -1, 1, 50, 255); + + for (int k = 0; k < 4; k++) { + float offsetX = PApplet.cos(rotationAngle) * diameter * 1.5f; + float offsetY = PApplet.sin(rotationAngle) * diameter * 1.5f; + + pApplet.pushMatrix(); + pApplet.pushStyle(); + pApplet.translate(x + offsetX, y + offsetY, -diameter / 2); + + pApplet.noStroke(); + + float adjustedRotationSpeed = PApplet.map(amplitude, 0, 200, rotationSpeed, rotationSpeed * 10); + rotationAngle += adjustedRotationSpeed; + + pApplet.fill(hue, 100, 100, opacity); // Use the calculated opacity value + pApplet.rotate(rotationAngle, 1, 1, 0); + pApplet.beginShape(PConstants.TRIANGLES); + + int detail = 100; + for (int j = 0; j < detail; j++) { + float theta1 = PApplet.map(j, 0, detail, 0, PConstants.TWO_PI); + float theta2 = PApplet.map(j + 1, 0, detail, 0, PConstants.TWO_PI); + + for (int i = 0; i < detail; i++) { + float phi1 = PApplet.map(i, 0, detail, 0, PConstants.PI); + float phi2 = PApplet.map(i + 1, 0, detail, 0, PConstants.PI); + float x1 = diameter * PApplet.sin(phi1) * PApplet.cos(theta1); + float y1 = diameter * PApplet.sin(phi1) * PApplet.sin(theta1); + float z1 = diameter * PApplet.cos(phi1); + float x2 = diameter * PApplet.sin(phi1) * PApplet.cos(theta2); + float y2 = diameter * PApplet.sin(phi1) * PApplet.sin(theta2); + float z2 = diameter * PApplet.cos(phi1); + float x3 = diameter * PApplet.sin(phi2) * PApplet.cos(theta2); + float y3 = diameter * PApplet.sin(phi2) * PApplet.sin(theta2); + float z3 = diameter * PApplet.cos(phi2); + pApplet.vertex(x1, y1, z1); + pApplet.vertex(x2, y2, z2); + pApplet.vertex(x3, y3, z3); + pApplet.vertex(x1, y1, z1); + pApplet.vertex(x3, y3, z3); + pApplet.vertex(x2, y2, z2); + } + } + + pApplet.endShape(); + + if (amplitude > 20) { + particles.add(new Particle(new PVector(x + offsetX, y + offsetY), hue)); + if (amplitude > 220) { + createExplosion(x + offsetX, y + offsetY, hue, 100); + } + } + + pApplet.popMatrix(); + pApplet.popStyle(); + rotationAngle += PConstants.PI / 2; // Divide the full circle into 4 equal parts for each circle + } + + pApplet.noStroke(); + + // Increment time elapsed + timeElapsed += 1; + } + + public void render() { + drawExample(); + } // End void render() + + private void drawEarthquakeEffect() { + float amplitude = audioBuffer.level() * 1000; + if (amplitude > 150) { // You can adjust the threshold as needed + float shakeIntensity = PApplet.map(amplitude, 50, 300, 5, 100); + float shakeX = pApplet.random(-shakeIntensity, shakeIntensity); + float shakeY = pApplet.random(-shakeIntensity, shakeIntensity); + pApplet.translate(shakeX, shakeY); + } + } + + private void createExplosion(float x, float y, float hue, int numParticles) { + for (int i = 0; i < numParticles; i++) { + PVector velocity = PVector.random2D(); + velocity.mult(pApplet.random(4, 8)); + Particle particle = new Particle(new PVector(x, y), hue); + particle.velocity = velocity; + particles.add(particle); + } + } + + // Particle System + private void updateParticles() { + pApplet.noStroke(); + for (int i = particles.size() - 1; i >= 0; i--) { + Particle particle = particles.get(i); + particle.update(); + particle.display(); + if (particle.isDead()) { + particles.remove(i); + } + } + } + + private class Particle { + PVector position; + PVector velocity; + float lifespan; + float hue; + + Particle(PVector position, float hue) { + this.position = position.copy(); + this.velocity = new PVector(pApplet.random(-2, 2), pApplet.random(-2, 2)); + this.lifespan = 255; + this.hue = hue; + } + + void update() { + position.add(velocity); + lifespan -= 3; // Decrease the value for a slower fade-out effect + velocity.mult(0.95f); // Add some friction to the particle movement + } + + void display() { + float particleSize = pApplet.random(2, 6); + pApplet.fill(hue, 100, 100, lifespan); + pApplet.ellipse(position.x, position.y, particleSize, particleSize); + } + + boolean isDead() { + return lifespan <= 0; + } + } + + private void drawScreenFlash() { + float amplitude = audioBuffer.level() * 1000; + float flashOpacity = PApplet.map(amplitude, 0, 800, 0, 255); + pApplet.fill(255, 255, 255, flashOpacity); + pApplet.rect(0, 0, windowWidth, windowHeight); + } + + private void drawStarfield() { + for (int i = 0; i < numStars; i++) { + Star star = stars[i]; + float radius = pApplet.random(1, 3); + float diameter = radius * 2; + // Move star to the right + star.x = (star.x + starSpeed) % windowWidth; + + // Draw star with a glowing effect + int glowAlpha = 100; + int numGlowLayers = 3; + for (int j = numGlowLayers; j > 0; j--) { + pApplet.fill(255, glowAlpha / j); + pApplet.ellipse(star.x, star.y, diameter * j, diameter * j); + } + } + } + + // Inner class representing a star object + private class Star { + float x; + + float y; + + public Star(float x, float y) { + this.x = x; + this.y = y; + } + + } + +} diff --git a/java/src/com/C21460524/drawObjects/Test.java b/java/src/com/C21460524/drawObjects/Test.java new file mode 100644 index 000000000..c990f6d77 --- /dev/null +++ b/java/src/com/C21460524/drawObjects/Test.java @@ -0,0 +1,25 @@ +package com.C21460524.drawObjects; + +// Dependencies + +import ddf.minim.AudioBuffer; +import processing.core.PApplet; + +public class Test extends PApplet { + // Private Feilds + PApplet pApplet; + int windowWidth; + int windowHeight; + + AudioBuffer audioBuffer; + public Test(PApplet pApplet, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + } // End ExampleDraw Constructor + + public void drawExample() { + pApplet.circle(windowWidth / 2, windowHeight / 2, 500); + } // End void drawExample() +} // End class ExampleDraw diff --git a/java/src/c123456/BryansVisual.java b/java/src/com/C21460524/drawObjects/tempCodeRunnerFile.java similarity index 100% rename from java/src/c123456/BryansVisual.java rename to java/src/com/C21460524/drawObjects/tempCodeRunnerFile.java diff --git a/java/src/com/C21460524/visual3/Visual3.java b/java/src/com/C21460524/visual3/Visual3.java new file mode 100644 index 000000000..a52cabacc --- /dev/null +++ b/java/src/com/C21460524/visual3/Visual3.java @@ -0,0 +1,75 @@ +package com.C21460524.visual3; + +import java.util.ArrayList; + +import com.C21460524.drawObjects.ExampleDraw; +import com.C21460524.drawObjects.Galaxy; +import com.C21460524.drawObjects.Galaxy2; + +// Dependencies +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.VisualAbstractClass; +import processing.core.PApplet; + +// Draw Objects + + +public class Visual3 extends VisualAbstractClass { + // Private Variables + int windowWidth; + int windowHeight; + PApplet pApplet; + AudioBuffer audioBuffer; + + int[] visual3Timings = { 300,802}; + + int drawObjectsIndex = 0; + ArrayList drawObjects; + + // Render Objects + // Place Objects Here + ExampleDraw exampleDraw; + Galaxy stars; + Galaxy2 stars2; + // + // + // + + // LEAVE ALONE + public Visual3(PApplet pApplet, AudioBuffer audioBuffer, AudioPlayer audioPlayer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.audioPlayer = audioPlayer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.fft = new FFT(2048, 44100); + + drawObjects = new ArrayList(); + loadRenderObjects(); +} // End Visual2 Constructor + + // Draw Function for Visual 3 + public void drawVisual() { + if(audioPlayer.position() / 100 > visual3Timings[drawObjectsIndex]) + drawObjectsIndex++; + + drawObjects.get(drawObjectsIndex).render(); + } // End drawVisual2 + + + // Load Render Objects + private void loadRenderObjects() { + // Create your draw Objects here + this.stars = new Galaxy(pApplet, audioBuffer, windowWidth, windowHeight); + this.stars2 = new Galaxy2(pApplet, audioBuffer, windowWidth, windowHeight); + //galaxy = new Test(this.pApplet, this.audioBuffer, this.windowWidth, this.windowHeight); + + drawObjects.add(stars); + drawObjects.add(stars2); + drawObjects.add(stars2); + } // End void oadRenderObjects + +} // End class Visual3 diff --git a/java/src/com/C21751999/drawObjects/ExampleDraw.java b/java/src/com/C21751999/drawObjects/ExampleDraw.java new file mode 100644 index 000000000..51435b20a --- /dev/null +++ b/java/src/com/C21751999/drawObjects/ExampleDraw.java @@ -0,0 +1,24 @@ +package com.C21751999.drawObjects; + +import ddf.minim.AudioBuffer; +import ie.tudublin.DrawObjectAbstractClass; +import processing.core.PApplet; + +public class ExampleDraw extends DrawObjectAbstractClass { + // Private Feilds + PApplet pApplet; + int windowWidth; + int windowHeight; + + AudioBuffer audioBuffer; + public ExampleDraw(PApplet pApplet, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + } // End ExampleDraw Constructor + + public void drawExample() { + pApplet.circle(windowWidth / 2, windowHeight / 2, 5); + } // End void drawExample() +} diff --git a/java/src/com/C21751999/drawObjects/HanaSaku.java b/java/src/com/C21751999/drawObjects/HanaSaku.java new file mode 100644 index 000000000..f543b8e6b --- /dev/null +++ b/java/src/com/C21751999/drawObjects/HanaSaku.java @@ -0,0 +1,75 @@ +package com.C21751999.drawObjects; +import ddf.minim.analysis.FFT; +import ddf.minim.AudioBuffer; +import ie.tudublin.DrawObjectAbstractClass; +import processing.core.*; + +public class HanaSaku extends DrawObjectAbstractClass { + float rot = 0; + float lerpedAverage = 0; + + + public HanaSaku(PApplet pApplet2, AudioBuffer audioBuffer, FFT fft, int windowWidth, int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = fft; + + } + + public void render(){ + pApplet.noFill(); + pApplet.pushMatrix(); + pApplet.camera(0, 0, 200, 0, 0, 0, 1, 0, 0); + pApplet.translate(0, 0, -200); + pApplet.strokeWeight(2); + fft.forward(audioBuffer); + int startBin = 20; + int endBin = 500; + float sum = 0; + for (int i = startBin; i <= endBin; i++) { + sum += fft.getBand(i); + } + lerpedAverage = sum / (endBin - startBin + 1) / 17.0f; + + pApplet.rotate(PApplet.radians(rot)); + for(float i = 0; i < PApplet.TWO_PI; i+= 0.0004f){ + float color = PApplet.map(i, 0, PApplet.TWO_PI, 0, 255); + float colorTwo = PApplet.map(i, 0, PApplet.TWO_PI, 0, 255); + float colorThree = PApplet.map(i, 0, PApplet.TWO_PI, 0, 255); + + // Use sin() and cos() functions to smoothly interpolate between colors + float timeFactor = 0.00005f * pApplet.millis(); // Adjust this factor to control the speed of color change + color += 255 + 255 * PApplet.sin(timeFactor); + colorTwo += 255 + 255 * PApplet.cos(timeFactor); + colorThree += 255 + 255 * PApplet.sin(timeFactor + PApplet.radians(120)); + + // Keep the colors within the range of 0 to 255 + color = color % 255; + colorTwo = colorTwo % 255; + colorThree = colorThree % 255; + + pApplet.stroke(color, colorTwo, colorThree); + + //outer petals aka dots + float r = 100 * PApplet.cos(6*i); + float x = r * PApplet.cos(i); + float y = r * PApplet.sin(i); + + pApplet.point(50 * (x * lerpedAverage), 50 *(y * lerpedAverage)); //2nd petal formation + + + // first 4 petals + r = 100 * PApplet.cos(4 * i); + x = r * PApplet.cos(i); + y = r * PApplet.sin(i); + pApplet.point(50 * (x * lerpedAverage), 50 *(y * lerpedAverage)); + } + + rot += 0.75; + pApplet.popMatrix(); + } + + +} \ No newline at end of file diff --git a/java/src/com/C21751999/visual4/Visual4.java b/java/src/com/C21751999/visual4/Visual4.java new file mode 100644 index 000000000..babedf3cf --- /dev/null +++ b/java/src/com/C21751999/visual4/Visual4.java @@ -0,0 +1,50 @@ +package com.C21751999.visual4; + +import com.C21460524.drawObjects.ExampleDraw; +import com.C21751999.drawObjects.HanaSaku; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; +import ie.tudublin.VisualAbstractClass; +import processing.core.PApplet; + +public class Visual4 extends VisualAbstractClass { + // Private Variables + int windowWidth; + int windowHeight; + PApplet pApplet; + AudioBuffer audioBuffer; + + // Render Objects + // Place Objects Here + ExampleDraw exampleDraw; + HanaSaku hana; + // + // + + // LEAVE ALONE + public Visual4(PApplet pApplet, AudioBuffer audioBuffer, AudioPlayer audioPlayer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.audioPlayer = audioPlayer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.fft = new FFT(2048, 44100); + loadRenderObjects(); +} // End Visual4 Constructor + + // Draw Function for Visual 3 + public void drawVisual() { + // Call Draw Functions in here + hana.render(); + } // End drawVisual2 + + + // Load Render Objects + private void loadRenderObjects() { + // Create your draw Objects here + // exampleDraw = new ExampleDraw(this.pApplet, this.audioBuffer, this.windowWidth, this.windowHeight); + hana = new HanaSaku(pApplet, audioBuffer, fft, windowWidth, windowHeight); + } // End void oadRenderObjects +} // End clas Visual4 diff --git a/java/src/com/C21782059/drawObjects/AudioHm.java b/java/src/com/C21782059/drawObjects/AudioHm.java new file mode 100644 index 000000000..f9308d9db --- /dev/null +++ b/java/src/com/C21782059/drawObjects/AudioHm.java @@ -0,0 +1,118 @@ +package com.C21782059.drawObjects; + +import ie.tudublin.DrawObjectAbstractClass; + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import processing.core.PApplet; + +public class AudioHm extends DrawObjectAbstractClass { + + // Constructor + public AudioHm(final PApplet pApplet2, final AudioBuffer audioBuffer, final FFT fft, final int windowWidth, + final int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = fft; + + } + + int numBands = 512; + float[] bandSize = new float[numBands]; + + float angle = 0; + float colorAngle = 0; + + public void render() { + pApplet.background(0); // Set the background color to black + pApplet.lights(); // Enable lighting + + // Sphere field in top-left corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4, windowHeight / 4, -100); + drawShapeField(); + pApplet.popMatrix(); + + // Sphere field in top-right corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4 * 3, windowHeight / 4, -100); + drawShapeField(); + pApplet.popMatrix(); + + // Sphere field in bottom-right corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4 * 3, windowHeight / 4 * 3, -100); + drawShapeField(); + pApplet.popMatrix(); + + // Sphere field in bottom-left corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4, windowHeight / 4 * 3, -100); + drawShapeField(); + pApplet.popMatrix(); + + // Sphere field in center of screen + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 2, windowHeight / 2, -100); + drawShapeField(); + pApplet.popMatrix(); + } + + private void drawShapeField() { + + // Initialize sphereColors after pApplet is initialized + int[] sphereColors = { + pApplet.color(255, 0, 0), + pApplet.color(0, 255, 0), + pApplet.color(0, 0, 255), + pApplet.color(255, 255, 0), + pApplet.color(0, 255, 255) + }; + + pApplet.rotateX(angle / 30.0f); // Rotate the spheres around the X axis + pApplet.rotateY(angle * 1.3f / 30.0f); // Rotate the spheres around the Y axis + pApplet.rotateZ(angle * 0.7f / 30.0f); // Rotate the spheres around the Z axis + pApplet.noStroke(); // Disable stroke drawing + final float r = 200; // The radius of the sphere field + fft.forward(audioBuffer); // Perform the FFT analysis on the audio data + + // Calculate the size of each frequency band + for (int i = 0; i < numBands; i++) { + bandSize[i] = fft.getBand(i) * 5; + } + + // storing previous angles + float prevAngle = angle; + float prevColorAngle = colorAngle; + + // Update the rotation angle and color angle based on the audio data + angle = PApplet.lerp(prevAngle, prevAngle + PApplet.map(bandSize[0], 0, 100, 0.01f, 0.1f), 0.5f); + colorAngle = PApplet.lerp(prevColorAngle, prevColorAngle + PApplet.map(bandSize[1], 0, 100, 0.001f, 0.01f), + 0.5f); + + // can change increment, this will change the visual + for (int i = 0; i < 360; i += 3) { + float x = r * PApplet.cos(PApplet.radians(i)); // Calculate the X position of the sphere + float y = r * PApplet.sin(PApplet.radians(i)); // Calculate the Y position of the sphere + float z = 0; // The Z position of the sphere (always 0) + float size = PApplet.map(bandSize[i / 5], 0, 255, 0, 30); // Calculate the size of the sphere based on the + // frequency band + float yOffset = PApplet.map(PApplet.sin(angle + i), -1, 1, -50, 50); // Calculate the Y offset of the sphere + // based on the rotation angle + int colorIndex = (i / 5) % sphereColors.length; // Calculate the index of the color to use + int c = sphereColors[colorIndex]; // Get the color for the sphere + pApplet.fill(c); // Set the fill color + pApplet.pushMatrix(); // Save the current transformation matrix + pApplet.translate(x, y + yOffset, z); // Translate to the position of the sphere + if (i % 2 == 0) { + pApplet.box(size); + } else { + pApplet.sphere(size); + } + pApplet.popMatrix(); + } + } + +} diff --git a/java/src/com/C21782059/drawObjects/ExampleDraw.java b/java/src/com/C21782059/drawObjects/ExampleDraw.java new file mode 100644 index 000000000..e303def16 --- /dev/null +++ b/java/src/com/C21782059/drawObjects/ExampleDraw.java @@ -0,0 +1,25 @@ +package com.C21782059.drawObjects; + +import ddf.minim.AudioBuffer; +import ie.tudublin.DrawObjectAbstractClass; +import processing.core.PApplet; + +public class ExampleDraw extends DrawObjectAbstractClass { + // Private Fields + PApplet pApplet; + int windowWidth; + int windowHeight; + + AudioBuffer audioBuffer; + + public ExampleDraw(PApplet pApplet, AudioBuffer audioBuffer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + } // End ExampleDraw Constructor + + public void drawExample() { + pApplet.circle(windowWidth / 2, windowHeight / 2, 5); + } // End void drawExample() +} diff --git a/java/src/com/C21782059/drawObjects/SquaresSpace.java b/java/src/com/C21782059/drawObjects/SquaresSpace.java new file mode 100644 index 000000000..a6644cbae --- /dev/null +++ b/java/src/com/C21782059/drawObjects/SquaresSpace.java @@ -0,0 +1,106 @@ +package com.C21782059.drawObjects; + +import ie.tudublin.DrawObjectAbstractClass; + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import processing.core.PApplet; + +public class SquaresSpace extends DrawObjectAbstractClass { + + // Constructor + public SquaresSpace(final PApplet pApplet2, final AudioBuffer audioBuffer, final FFT fft, final int windowWidth, + final int windowHeight) { + this.pApplet = pApplet2; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.audioBuffer = audioBuffer; + this.fft = fft; + + } + + FFT fft; + int numBands = 512; + float[] bandSize = new float[numBands]; + + float angle = 0; + float colorAngle = 0; + float noiseScale = 0.05f; + float noiseStrength = 100; + + public void render() { + pApplet.background(0); + pApplet.lights(); + + // Cube field in top-left corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4, windowHeight / 4, -100); + drawCubeField(); + pApplet.popMatrix(); + + // Cube field in top-right corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4 * 3, windowHeight / 4, -100); + drawCubeField(); + pApplet.popMatrix(); + + // Cube field in bottom-right corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4 * 3, windowHeight / 4 * 3, -100); + drawCubeField(); + pApplet.popMatrix(); + + // Cube field in bottom-left corner + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 4, windowHeight / 4 * 3, -100); + drawCubeField(); + pApplet.popMatrix(); + + // Cube field in center of screen + pApplet.pushMatrix(); + pApplet.translate(windowWidth / 2, windowHeight / 2, -100); + drawCubeField(); + pApplet.popMatrix(); + } + + private void drawCubeField() { + + // Rotating angles + pApplet.rotateX(angle / 30.0f); + pApplet.rotateY(angle * 1.3f / 30.0f); + pApplet.rotateZ(angle * 0.7f / 30.0f); + pApplet.noStroke(); + fft.forward(audioBuffer); + + // get size of freq band + for (int i = 0; i < numBands; i++) { + bandSize[i] = fft.getBand(i) * 5; + } + + // update angle, colour depending on freq band + angle += PApplet.map(bandSize[0], 0, 100, 0.01f, 0.1f); + colorAngle += PApplet.map(bandSize[1], 0, 100, 0.001f, 0.01f); + + // draw cubes + for (int i = -200; i < 200; i += 20) { + for (int j = -200; j < 200; j += 20) { + for (int k = -200; k < 200; k += 20) { + float x = i; + float y = j; + float z = k; + float size = PApplet.map(bandSize[(i + 200) / 20], 0, 255, 0, 50); + float yOffset = pApplet.noise(i * noiseScale, j * noiseScale, k * noiseScale) * noiseStrength; + // Assign a different color for each cube based on its position + int cubeColor = pApplet.color(PApplet.map(i + colorAngle, 0, 512, 0, 255), + PApplet.map(j + colorAngle, 0, 512, 0, 255), + PApplet.map(k + colorAngle, 0, 512, 0, 255)); + pApplet.fill(cubeColor); + pApplet.pushMatrix(); // save curr matrix + pApplet.translate(x, y + yOffset, z); + pApplet.box(size); + pApplet.popMatrix(); // get prev matrix + } + } + } + } +} diff --git a/java/src/example/AudioBandsVisual.java b/java/src/com/C21782059/example/AudioBandsVisual.java similarity index 93% rename from java/src/example/AudioBandsVisual.java rename to java/src/com/C21782059/example/AudioBandsVisual.java index b6b99d6e5..0284a51d3 100644 --- a/java/src/example/AudioBandsVisual.java +++ b/java/src/com/C21782059/example/AudioBandsVisual.java @@ -1,25 +1,25 @@ -package example; - -import processing.core.*; - -// This is an example of a visual that uses the audio bands -public class AudioBandsVisual -{ - MyVisual mv; - - public AudioBandsVisual(MyVisual mv) - { - this.mv = mv; - } - - public void render() - { - float gap = mv.width / (float) mv.getBands().length; - mv.noStroke(); - for(int i = 0 ; i < mv.getBands().length ; i ++) - { - mv.fill(PApplet.map(i, 0, mv.getBands().length, 255, 0), 255, 255); - mv.rect(i * gap, mv.height, gap,-mv.getSmoothedBands()[i] * 0.2f); - } - } +package com.C21782059.example; + +import processing.core.*; + +// This is an example of a visual that uses the audio bands +public class AudioBandsVisual +{ + MyVisual mv; + + public AudioBandsVisual(MyVisual mv) + { + this.mv = mv; + } + + public void render() + { + float gap = mv.width / (float) mv.getBands().length; + mv.noStroke(); + for(int i = 0 ; i < mv.getBands().length ; i ++) + { + mv.fill(PApplet.map(i, 0, mv.getBands().length, 255, 0), 255, 255); + mv.rect(i * gap, mv.height, gap,-mv.getSmoothedBands()[i] * 0.2f); + } + } } \ No newline at end of file diff --git a/java/src/example/CubeVisual.java b/java/src/com/C21782059/example/CubeVisual.java similarity index 95% rename from java/src/example/CubeVisual.java rename to java/src/com/C21782059/example/CubeVisual.java index ff8e58798..e63349aab 100644 --- a/java/src/example/CubeVisual.java +++ b/java/src/com/C21782059/example/CubeVisual.java @@ -1,90 +1,90 @@ -package example; - -import ie.tudublin.Visual; - -public class CubeVisual extends Visual -{ - boolean twocubes = false; - - public void settings() - { - size(800, 800, P3D); - println("CWD: " + System.getProperty("user.dir")); - //fullScreen(P3D, SPAN); - } - - public void keyPressed() - { - if (key == ' ') - { - getAudioPlayer().cue(0); - getAudioPlayer().play(); - - } - if (key == '1') - { - twocubes = ! twocubes; - - } - } - - public void setup() - { - colorMode(HSB); - noCursor(); - - setFrameSize(256); - - startMinim(); - loadAudio("heroplanet.mp3"); - //getAp().play(); - //startListening(); - - } - - float smoothedBoxSize = 0; - - public void draw() - { - calculateAverageAmplitude(); - background(0); - noFill(); - lights(); - stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); - camera(0, 0, 0, 0, 0, -1, 0, 1, 0); - translate(0, 0, -250); - - float boxSize = 50 + (getAmplitude() * 300);//map(average, 0, 1, 100, 400); - smoothedBoxSize = lerp(smoothedBoxSize, boxSize, 0.2f); - if (twocubes) - { - pushMatrix(); - translate(-100, 0, 0); - rotateY(angle); - rotateX(angle); - box(smoothedBoxSize); - //strokeWeight(1); - //sphere(smoothedBoxSize); - popMatrix(); - pushMatrix(); - translate(100, 0, 0); - rotateY(angle); - rotateX(angle); - strokeWeight(5); - box(smoothedBoxSize); - popMatrix(); - } - else - { - rotateY(angle); - rotateX(angle); - //strokeWeight(1); - //sphere(smoothedBoxSize/ 2); - strokeWeight(5); - - box(smoothedBoxSize); - } - angle += 0.01f; - } - float angle = 0; +package com.C21782059.example; + +import ie.tudublin.Visual; + +public class CubeVisual extends Visual +{ + boolean twocubes = false; + + public void settings() + { + size(800, 800, P3D); + println("CWD: " + System.getProperty("user.dir")); + //fullScreen(P3D, SPAN); + } + + public void keyPressed() + { + if (key == ' ') + { + getAudioPlayer().cue(0); + getAudioPlayer().play(); + + } + if (key == '1') + { + twocubes = ! twocubes; + + } + } + + public void setup() + { + colorMode(HSB); + noCursor(); + + setFrameSize(256); + + startMinim(); + loadAudio("heroplanet.mp3"); + //getAp().play(); + //startListening(); + + } + + float smoothedBoxSize = 0; + + public void draw() + { + calculateAverageAmplitude(); + background(0); + noFill(); + lights(); + stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); + camera(0, 0, 0, 0, 0, -1, 0, 1, 0); + translate(0, 0, -250); + + float boxSize = 50 + (getAmplitude() * 300);//map(average, 0, 1, 100, 400); + smoothedBoxSize = lerp(smoothedBoxSize, boxSize, 0.2f); + if (twocubes) + { + pushMatrix(); + translate(-100, 0, 0); + rotateY(angle); + rotateX(angle); + box(smoothedBoxSize); + //strokeWeight(1); + //sphere(smoothedBoxSize); + popMatrix(); + pushMatrix(); + translate(100, 0, 0); + rotateY(angle); + rotateX(angle); + strokeWeight(5); + box(smoothedBoxSize); + popMatrix(); + } + else + { + rotateY(angle); + rotateX(angle); + //strokeWeight(1); + //sphere(smoothedBoxSize/ 2); + strokeWeight(5); + + box(smoothedBoxSize); + } + angle += 0.01f; + } + float angle = 0; } \ No newline at end of file diff --git a/java/src/example/CubeVisual1.java b/java/src/com/C21782059/example/CubeVisual1.java similarity index 93% rename from java/src/example/CubeVisual1.java rename to java/src/com/C21782059/example/CubeVisual1.java index 8eebd97f8..422566bbb 100644 --- a/java/src/example/CubeVisual1.java +++ b/java/src/com/C21782059/example/CubeVisual1.java @@ -1,53 +1,53 @@ -package example; - -import ie.tudublin.Visual; - -public class CubeVisual1 extends Visual -{ - public void settings() - { - size(800, 600, P3D); - //fullScreen(P3D, SPAN); - } - - public void setup() - { - startMinim(); - //startListening(); - loadAudio("heroplanet.mp3"); - colorMode(HSB); - } - - public void keyPressed() - { - if (key == ' ') - { - getAudioPlayer().cue(0); - getAudioPlayer().play(); - } - } - - float angle = 0; - - public void draw() - { - background(0); - calculateAverageAmplitude(); - stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); - strokeWeight(5); - noFill(); - lights(); - pushMatrix(); - // - camera(0, 0, 0, 0, 0, -1, 0, 1, 0); - translate(0, 0, -200); - rotateX(angle); - rotateZ(angle); - float boxSize = 50 + (200 * getSmoothedAmplitude()); - box(boxSize); - popMatrix(); - angle += 0.01f; - } - - +package com.C21782059.example; + +import ie.tudublin.Visual; + +public class CubeVisual1 extends Visual +{ + public void settings() + { + size(800, 600, P3D); + //fullScreen(P3D, SPAN); + } + + public void setup() + { + startMinim(); + //startListening(); + loadAudio("heroplanet.mp3"); + colorMode(HSB); + } + + public void keyPressed() + { + if (key == ' ') + { + getAudioPlayer().cue(0); + getAudioPlayer().play(); + } + } + + float angle = 0; + + public void draw() + { + background(0); + calculateAverageAmplitude(); + stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); + strokeWeight(5); + noFill(); + lights(); + pushMatrix(); + // + camera(0, 0, 0, 0, 0, -1, 0, 1, 0); + translate(0, 0, -200); + rotateX(angle); + rotateZ(angle); + float boxSize = 50 + (200 * getSmoothedAmplitude()); + box(boxSize); + popMatrix(); + angle += 0.01f; + } + + } \ No newline at end of file diff --git a/java/src/example/MyVisual.java b/java/src/com/C21782059/example/MyVisual.java similarity index 94% rename from java/src/example/MyVisual.java rename to java/src/com/C21782059/example/MyVisual.java index 849e71bc2..6f9d4c41c 100644 --- a/java/src/example/MyVisual.java +++ b/java/src/com/C21782059/example/MyVisual.java @@ -1,65 +1,65 @@ -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 com.C21782059.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(); + } +} diff --git a/java/src/example/RotatingAudioBands.java b/java/src/com/C21782059/example/RotatingAudioBands.java similarity index 94% rename from java/src/example/RotatingAudioBands.java rename to java/src/com/C21782059/example/RotatingAudioBands.java index 72fd7a223..b83ec3a66 100644 --- a/java/src/example/RotatingAudioBands.java +++ b/java/src/com/C21782059/example/RotatingAudioBands.java @@ -1,89 +1,89 @@ -package example; - -import ie.tudublin.Visual; -import ie.tudublin.VisualException; - -public class RotatingAudioBands extends Visual { - - - public void settings() - { - size(800, 800, P3D); - println("CWD: " + System.getProperty("user.dir")); - //fullScreen(P3D, SPAN); - } - - public void keyPressed() - { - if (key == ' ') - { - getAudioPlayer().cue(0); - getAudioPlayer().play(); - - } - - } - - public void setup() - { - colorMode(HSB); - noCursor(); - - setFrameSize(256); - - startMinim(); - loadAudio("heroplanet.mp3"); - getAudioPlayer().play(); - //startListening(); - - } - - float radius = 200; - - float smoothedBoxSize = 0; - - float rot = 0; - - public void draw() - { - calculateAverageAmplitude(); - try - { - calculateFFT(); - } - catch(VisualException e) - { - e.printStackTrace(); - } - calculateFrequencyBands(); - background(0); - noFill(); - stroke(255); - lights(); - stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); - camera(0, -500, 500, 0, 0, 0, 0, 1, 0); - //translate(0, 0, -250); - - rot += getAmplitude() / 8.0f; - - rotateY(rot); - float[] bands = getSmoothedBands(); - for(int i = 0 ; i < bands.length ; i ++) - { - float theta = map(i, 0, bands.length, 0, TWO_PI); - - stroke(map(i, 0, bands.length, 0, 255), 255, 255); - float x = sin(theta) * radius; - float z = cos(theta) * radius; - float h = bands[i]; - pushMatrix(); - translate(x, - h / 2 , z); - rotateY(theta); - box(50, h, 50); - popMatrix(); - } - - } - float angle = 0; - +package com.C21782059.example; + +import ie.tudublin.Visual; +import ie.tudublin.VisualException; + +public class RotatingAudioBands extends Visual { + + + public void settings() + { + size(800, 800, P3D); + println("CWD: " + System.getProperty("user.dir")); + //fullScreen(P3D, SPAN); + } + + public void keyPressed() + { + if (key == ' ') + { + getAudioPlayer().cue(0); + getAudioPlayer().play(); + + } + + } + + public void setup() + { + colorMode(HSB); + noCursor(); + + setFrameSize(256); + + startMinim(); + loadAudio("heroplanet.mp3"); + getAudioPlayer().play(); + //startListening(); + + } + + float radius = 200; + + float smoothedBoxSize = 0; + + float rot = 0; + + public void draw() + { + calculateAverageAmplitude(); + try + { + calculateFFT(); + } + catch(VisualException e) + { + e.printStackTrace(); + } + calculateFrequencyBands(); + background(0); + noFill(); + stroke(255); + lights(); + stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); + camera(0, -500, 500, 0, 0, 0, 0, 1, 0); + //translate(0, 0, -250); + + rot += getAmplitude() / 8.0f; + + rotateY(rot); + float[] bands = getSmoothedBands(); + for(int i = 0 ; i < bands.length ; i ++) + { + float theta = map(i, 0, bands.length, 0, TWO_PI); + + stroke(map(i, 0, bands.length, 0, 255), 255, 255); + float x = sin(theta) * radius; + float z = cos(theta) * radius; + float h = bands[i]; + pushMatrix(); + translate(x, - h / 2 , z); + rotateY(theta); + box(50, h, 50); + popMatrix(); + } + + } + float angle = 0; + } \ No newline at end of file diff --git a/java/src/com/C21782059/example/RotatingBands.java b/java/src/com/C21782059/example/RotatingBands.java new file mode 100644 index 000000000..1b6240925 --- /dev/null +++ b/java/src/com/C21782059/example/RotatingBands.java @@ -0,0 +1 @@ +package com.C21782059.example; diff --git a/java/src/example/WaveForm.java b/java/src/com/C21782059/example/WaveForm.java similarity index 93% rename from java/src/example/WaveForm.java rename to java/src/com/C21782059/example/WaveForm.java index 5d38aa700..0261f2d39 100644 --- a/java/src/example/WaveForm.java +++ b/java/src/com/C21782059/example/WaveForm.java @@ -1,31 +1,31 @@ -package example; - -import processing.core.*; - -// This is an example of a visual that renders the waveform -public class WaveForm -{ - MyVisual mv; - float cy = 0; - - public WaveForm(MyVisual mv) - { - this.mv = mv; - cy = this.mv.height / 2; - } - - public void render() - { - mv.colorMode(PApplet.HSB); - for(int i = 0 ; i < mv.getAudioBuffer().size() ; i ++) - { - mv.stroke( - PApplet.map(i, 0, mv.getAudioBuffer().size(), 0, 255) - , 255 - , 255 - ); - - mv.line(i, cy, i, cy + cy * mv.getAudioBuffer().get(i)); - } - } +package com.C21782059.example; + +import processing.core.*; + +// This is an example of a visual that renders the waveform +public class WaveForm +{ + MyVisual mv; + float cy = 0; + + public WaveForm(MyVisual mv) + { + this.mv = mv; + cy = this.mv.height / 2; + } + + public void render() + { + mv.colorMode(PApplet.HSB); + for(int i = 0 ; i < mv.getAudioBuffer().size() ; i ++) + { + mv.stroke( + PApplet.map(i, 0, mv.getAudioBuffer().size(), 0, 255) + , 255 + , 255 + ); + + mv.line(i, cy, i, cy + cy * mv.getAudioBuffer().get(i)); + } + } } \ No newline at end of file diff --git a/java/src/com/C21782059/visual1/Visual1.java b/java/src/com/C21782059/visual1/Visual1.java new file mode 100644 index 000000000..cdeb7bd47 --- /dev/null +++ b/java/src/com/C21782059/visual1/Visual1.java @@ -0,0 +1,71 @@ +package com.C21782059.visual1; + +import com.C21782059.drawObjects.AudioHm; +import com.C21782059.drawObjects.SquaresSpace; + +// Dependencies +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; +import ie.tudublin.DrawObjectAbstractClass; +import ie.tudublin.VisualAbstractClass; +import processing.core.PApplet; +import java.util.ArrayList; + +public class Visual1 extends VisualAbstractClass { + // Private Variables + int windowWidth; + int windowHeight; + PApplet pApplet; + AudioBuffer audioBuffer; + + int[] visual1Timings = { 1990, 2263, 4370}; + int drawObjectsIndex = 0; + ArrayList drawObjects; + + // Render Objects + AudioHm audioHm; + SquaresSpace squaresSpace; + //ExampleDraw exampleDraw; + // + // + // + + // LEAVE ALONE + public Visual1(PApplet pApplet, AudioBuffer audioBuffer, AudioPlayer audioPlayer, int windowWidth, int windowHeight) { + this.pApplet = pApplet; + this.audioBuffer = audioBuffer; + this.audioPlayer = audioPlayer; + this.windowWidth = windowWidth; + this.windowHeight = windowHeight; + this.fft = new FFT(2048, 44100); + + drawObjects = new ArrayList(); + + loadRenderObjects(); +} // End Visual2 Constructor + + // Draw Function for Visual 3 + public void drawVisual() { + // Call Draw Functions in here + //audioHm.render(); + //System.out.println("hello"); + if(audioPlayer.position() / 100 > visual1Timings[drawObjectsIndex]) + drawObjectsIndex++; + + drawObjects.get(drawObjectsIndex).render(); + } // End drawVisual2 + + + // Load Render Objects + private void loadRenderObjects() { + // Create your draw Objects here + //exampleDraw = new ExampleDraw(this.pApplet, this.audioBuffer, this.windowWidth, this.windowHeight); + this.audioHm = new AudioHm(pApplet, audioBuffer, fft, windowWidth, windowHeight); + this.squaresSpace = new SquaresSpace(pApplet, audioBuffer, fft, windowWidth, windowHeight); + + drawObjects.add(audioHm); + drawObjects.add(squaresSpace); + drawObjects.add(squaresSpace); + } // End void oadRenderObjects +} // End class Visual1 diff --git a/java/src/example/RotatingBands.java b/java/src/example/RotatingBands.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/java/src/ie/tudublin/DrawObjectAbstractClass.java b/java/src/ie/tudublin/DrawObjectAbstractClass.java new file mode 100644 index 000000000..7ce8dcfb2 --- /dev/null +++ b/java/src/ie/tudublin/DrawObjectAbstractClass.java @@ -0,0 +1,16 @@ +package ie.tudublin; + +import ddf.minim.AudioBuffer; +import ddf.minim.analysis.FFT; +import processing.core.PApplet; + +public abstract class DrawObjectAbstractClass { + // Private Variables + protected PApplet pApplet; + protected int windowWidth; + protected int windowHeight; + protected AudioBuffer audioBuffer; + protected FFT fft; + + public void render() {}; +} diff --git a/java/src/ie/tudublin/Main.java b/java/src/ie/tudublin/Main.java index 27489f824..902de2778 100644 --- a/java/src/ie/tudublin/Main.java +++ b/java/src/ie/tudublin/Main.java @@ -1,21 +1,16 @@ package ie.tudublin; -import example.CubeVisual; -import example.MyVisual; -import example.RotatingAudioBands; public class Main { - - public void startUI() + public static void main(String[] args) { - String[] a = {"MAIN"}; - processing.core.PApplet.runSketch( a, new MyVisual()); + startMusicVisualizer(); } - public static void main(String[] args) + public static void startMusicVisualizer() { - Main main = new Main(); - main.startUI(); + String[] a = {"MAIN"}; + processing.core.PApplet.runSketch( a, new MusicVisualizer()); } } \ No newline at end of file diff --git a/java/src/ie/tudublin/MusicVisualizer.java b/java/src/ie/tudublin/MusicVisualizer.java new file mode 100644 index 000000000..49fe0385e --- /dev/null +++ b/java/src/ie/tudublin/MusicVisualizer.java @@ -0,0 +1,115 @@ +package ie.tudublin; + +// Dependencies +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import java.util.ArrayList; + +// Visuals +import com.C21782059.visual1.Visual1; +import com.C21394933.visual2.StartMenuVisual; +import com.C21394933.visual2.Visual2; +import com.C21460524.visual3.Visual3; +import com.C21751999.visual4.Visual4; + + +public class MusicVisualizer extends PApplet { + // Render Visuals + // C21394933 (Ernest John Decina) + StartMenuVisual startMenuVisual; + Visual1 visual1; + // + Visual2 visual2; + // + Visual3 visual3; + // + Visual4 visual4; + + // Private Variables + int windowHeight = 720; + int windowWidth = 1080; + ArrayList visualList; + + Minim minim; + AudioInput audioInput; + AudioPlayer audioPlayer; + AudioBuffer audioBuffer; + + int frameSize = 1024; + int sampleRate = 96000; // 44100; + int bitDepth = 16; + + float lerpedR = 0; + + int[] timings = {5, 667, 1075, 1328, 1868, 2262, 5000}; + public static int timingsCounter = 0; + int currentTime = 0; + + + public MusicVisualizer() { + visualList = new ArrayList(); + } // End MusicVisualizer + + public void settings() { + size(windowWidth, windowHeight, P3D); + } // End void settings() + + public void setup() { + colorMode(RGB); + + frameRate(60); + loadSong(); + loadVisuals(); + } // End void setup() + + public void draw() { + background(0); + playVisuals(); + } // End void draw() + + + // Onload Functions + private void loadSong() { + // Initialize minim + this.minim = new Minim(this); + this.audioPlayer = minim.loadFile("songs/somethingComforting.mp3", 2048); + this.audioBuffer = audioPlayer.mix; + + //this.audioPlayer.play(); + //Utils.skipSecondsSong(audioPlayer, 132.7f); + } // End void loadSong() + + private void loadVisuals() { + this.startMenuVisual = new StartMenuVisual(this, this.audioBuffer, this.audioPlayer, this.windowWidth, this.windowHeight); + this.visual2 = new Visual2(this, this.audioBuffer, this.audioPlayer, this.windowWidth, this.windowHeight); + this.visual3 = new Visual3(this, this.audioBuffer, this.audioPlayer, this.windowWidth, this.windowHeight); + this.visual1 = new Visual1(this, this.audioBuffer, this.audioPlayer, this.windowWidth, this.windowHeight); + this.visual4 = new Visual4(this, this.audioBuffer, this.audioPlayer, this.windowWidth, this.windowHeight); + + + visualList.add(startMenuVisual); + visualList.add(visual3); + visualList.add(visual2); + visualList.add(visual4); + visualList.add(visual1); + visualList.add(visual1); + visualList.add(visual1); + visualList.add(visual1); + } // End void loadVisuals + + private void playVisuals() + { + currentTime = audioPlayer.position(); + + //System.out.println((float)currentTime / 100); + if(currentTime / 100 > timings[timingsCounter]) + timingsCounter++; + + visualList.get(timingsCounter).drawVisual(); + + } // End void playVisual + +} // End class MusicVisualizer \ No newline at end of file diff --git a/java/src/ie/tudublin/Utils.java b/java/src/ie/tudublin/Utils.java new file mode 100644 index 000000000..e6f5ccb7c --- /dev/null +++ b/java/src/ie/tudublin/Utils.java @@ -0,0 +1,79 @@ +package ie.tudublin; + + +// Dependencies +import processing.core.PApplet; + + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; + +public class Utils extends PApplet { + // Frequency Functions + public static float getHighestFrequency(FFT fft) { + int highestIndex = 0; + for(int i = 0; i < fft.specSize() / 2; i++) { + if(fft.getBand(i) > fft.getBand(highestIndex)) { + highestIndex = i; + } // End if + } // End for + + return fft.indexToFreq(highestIndex); + } // End float getHighestFrequency() + + public static int[] getHighestFrequencyIndex(FFT fft, AudioBuffer audioBuffer) { + int[] loudestFrequencies = {0, 0, 0}; + fft.forward(audioBuffer); + + // Draw Bass + // 20 Hz - 261 Hz + for(int i = 0; i < 12; i++) { + // pApplet.line(i * scale, windowHeight, i * scale, windowHeight - fft.getBand(i) * 5.0f); + if(fft.getBand(i) > 60) { + if(fft.getBand(i) > fft.getBand(loudestFrequencies[0])) { + loudestFrequencies[0] = i; + } // End if + } // End if + + } // End for + + // Draw Mids + // 261 Hz - 1046 + for(int i = 12; i < 49; i++) { + // pApplet.line(i * scale, windowHeight, i * scale, windowHeight - fft.getBand(i) * 5.0f); + if(fft.getBand(i) > 90) { + if(fft.getBand(i) > fft.getBand(loudestFrequencies[1])) { + loudestFrequencies[1] = i; + } // End if + } + } // End for + + // Draw Highs + for(int i = 49; i < 390; i++) { + // pApplet.line(i * scale, windowHeight, i * scale, windowHeight - fft.getBand(i) * 5.0f); + if(fft.getBand(i) > 5) { + if(fft.getBand(i) > fft.getBand(loudestFrequencies[2])) { + loudestFrequencies[2] = i; + } // End if + } + } // End for + + return loudestFrequencies; + } // End float getHighestFrequency() + + + // Wait for X amount of Seconds + public static void waitFor(long milliSeconds) { + try { + Thread.sleep(milliSeconds); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }// End void waitFor(float milliSeconds) + + public static void skipSecondsSong(AudioPlayer audioPlayer, float skipSeconds) { + int milliSeconds = (int) (skipSeconds * 1000); + audioPlayer.skip(milliSeconds); + } // End void skipSecondsSongs +} // End class Utils diff --git a/java/src/ie/tudublin/VisualAbstractClass.java b/java/src/ie/tudublin/VisualAbstractClass.java new file mode 100644 index 000000000..9f7523072 --- /dev/null +++ b/java/src/ie/tudublin/VisualAbstractClass.java @@ -0,0 +1,19 @@ +package ie.tudublin; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioPlayer; +import ddf.minim.analysis.FFT; +import processing.core.PApplet; + +public abstract class VisualAbstractClass extends PApplet { + // Private Variables + protected int windowWidth; + protected int windowHeight; + protected PApplet pApplet; + protected AudioPlayer audioPlayer; + protected AudioBuffer audioBuffer; + protected FFT fft; + + public void drawVisual() {}; + // private void loadRenderObjects() {}; +}