diff --git a/.vscode/launch.json b/.vscode/launch.json index 5f0c7af3b..27128eb5c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,10 +1,17 @@ { "configurations": [ + { + "type": "java", + "name": "Launch Main", + "request": "launch", + "mainClass": "C19326126.Main", + "projectName": "java" + }, { "type": "java", "name": "CodeLens (Launch) - Main", "request": "launch", - "mainClass": "ie.tudublin.Main", + "mainClass": "C19326126.Main", "projectName": "java" } ] diff --git a/java/.project b/java/.project index 160e3c189..a48058a53 100644 --- a/java/.project +++ b/java/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1616171615251 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/java/bin/C19326126/Practice b/java/bin/C19326126/Practice new file mode 100644 index 000000000..e69de29bb diff --git a/java/src/C19326126/Example.java b/java/src/C19326126/Example.java new file mode 100644 index 000000000..50f07eb94 --- /dev/null +++ b/java/src/C19326126/Example.java @@ -0,0 +1,41 @@ +package C19326126; + +import processing.core.PApplet; + +public class Example extends PApplet{ + float r; + float ex, ey; + + public void settings(){ + size(800,800); + } + + public void setup(){ + ex = 140; + ey = 0; + } + + public void draw(){ + background(0); + //beginning matrix + pushMatrix(); + translate(width/2, height/2); //middle of screen + rotate(radians(r)); //starting rotation + //sun + fill(255,255,0); //placing first sphere + ellipse(0,0,100,100); + //earth + fill(0,255,100); //placing second sphere + ellipse(ex,ey,20,20); + pushMatrix(); + //moon + translate(ex,ey); //sets center to center of the earth + rotate(radians(-r*3)); + fill(255); + ellipse(25,ey,5,5); + popMatrix(); + popMatrix(); + r += 1; + } + +} \ No newline at end of file diff --git a/java/src/C19326126/Main.java b/java/src/C19326126/Main.java new file mode 100644 index 000000000..3442b38e3 --- /dev/null +++ b/java/src/C19326126/Main.java @@ -0,0 +1,33 @@ +package C19326126; + +import example.AudioBandsVisual; +import example.CubeVisual; +import example.MyVisual; +import example.RotatingAudioBands; + +public class Main +{ + + public void StarSystem() + { + String[] a = {"MAIN"}; + processing.core.PApplet.runSketch( a, new StarSystem()); + } + + public void Example() + { + String[] a = {"MAIN"}; + processing.core.PApplet.runSketch( a, new Example()); + } + public void Work() + { + String[] a = {"MAIN"}; + processing.core.PApplet.runSketch( a, new Work()); + } + + public static void main(String[] args) + { + Main main = new Main(); + main.StarSystem(); + } +} \ No newline at end of file diff --git a/java/src/C19326126/Practice b/java/src/C19326126/Practice new file mode 100644 index 000000000..e69de29bb diff --git a/java/src/C19326126/StarSystem.java b/java/src/C19326126/StarSystem.java new file mode 100644 index 000000000..a1bf2d6bd --- /dev/null +++ b/java/src/C19326126/StarSystem.java @@ -0,0 +1,189 @@ +package C19326126; + +import processing.core.PApplet; + +public class StarSystem extends PApplet{ + float rotation; + float rotation2; + float rotation3; + float rotation4; + float rotation5; + Boolean generation = false; + + //Star Coordinates & Sizes + float x [] = new float[200]; + float y [] = new float[200]; + float z [] = new float[200]; + float size[] = new float[200]; + float x2 [] = new float[200]; + float y2 [] = new float[200]; + float z2 [] = new float[200]; + float size2[] = new float[200]; + + Sun Sun1, Sun2, Sun3, Sun4, Sun5, Sun6, Sun7, Sun8; + + + + public void settings(){ + fullScreen(P3D, SPAN); + //color, position X/Y, size + Sun1 = new Sun(color(255, 255, 0), 0, 0, 50);//Sun + Sun2 = new Sun(color(0, 255, 0), 10, 0, 20);//Earth + Sun3 = new Sun(color(0, 0, 255), 10, 0, 5);//Moon + Sun4 = new Sun(color(255, 0, 50), 10, 0, 18);//Mars + Sun5 = new Sun(color(255, 0, 50), 10, 0, 4);//Moon2 + Sun6 = new Sun(color(255, 0, 50), 10, 0, 6);//Moon3 + Sun7 = new Sun(color(200, 100, 20), 10, 0, 15);//Mercury + Sun8 = new Sun(color(200,180,40), 10, 0, 35);//Jupiter + } + + + public void setup(){ + + } + + public void draw(){ + background(0); + lights(); + camera(mouseX*2, mouseY, (height/2) / tan(PI/5), width/2, height/2, 0, 0, 1, 0); + + pushMatrix();//Sun + translate(width/2, height/2); + rotate(radians(rotation)); + Sun1.display(); + + Mercury(); + + Earth(); + + Mars(); + + Jupiter(); + + popMatrix(); //end Sun + + pushMatrix(); //begin star generation + + translate(width/2, height/2); + StarField(); + + popMatrix(); //end star genertaion + + //rotational constants for different planets + rotation += .15; + rotation2 += .85; + rotation3 += 1.5; + rotation4 += .65; + rotation5 -= .1; + } + private void StarField(){ + if(!generation){ + + //seperate i's with if statements to be able to make stars of diff audio bands + //eg if i > 25 &&i < 50 stroke map diffcolor * bands.length + + + for(int i = 0; i < 200; i++){ + x[i] = random(-3500,3500); + y[i] = random(-3000,3000); + z[i] = random(50,3000); + size[i] = random(3,18); + } + for(int j = 0; j < 200; j++){ + x2[j] = random(-3500,3500); + y2[j] = random(-3000,3000); + z2[j] = random(-3000,-50); + size2[j] = random(3,18); + } + + + generation = true; + } + for(int i = 0; i < 200; i++){ + //Z values ensure Planets won't strike a star + pushMatrix(); + translate(x[i], y[i], z[i]); + fill(120,120,255); + sphere(size[i]); + popMatrix(); + } + for(int j = 0; j < 200; j++){ + pushMatrix(); + translate(x2[j], y2[j], z2[j]); + fill(120,120,255); + sphere(size2[j]); + popMatrix(); + } + }//end StarField + + private void Mercury() { + pushMatrix(); + rotate(radians(rotation)); + translate(-150, -10); + Sun7.display(); + popMatrix(); + }//End Mercury + + + private void Earth() { + pushMatrix();//Earth + rotate(radians(rotation2)); + + translate(350, 0); + Sun2.display(); + rotate(radians(rotation2)); + pushMatrix(); //Moon + translate(40, 0); + Sun3.display(); + popMatrix(); //End Moon + popMatrix(); //End earth + }//End Earth + + + void Mars(){ + pushMatrix(); + translate(480,0); + rotate(radians(rotation4)); + Sun4.display();//Mars + pushMatrix(); //Mars Moons + rotate(radians(rotation3)); + translate(29, 0); + Sun5.display(); + popMatrix(); + pushMatrix(); + rotate(radians(rotation)); + translate(40, 15); + Sun5.display(); + popMatrix(); //End Mars Moon + popMatrix(); //End Mars + }//End Mars + + private void Jupiter() { + pushMatrix(); + rotate(radians(rotation5)); + translate(-650, 30); + Sun8.display(); + popMatrix(); + } + + public class Sun{ + int c; + int s; + float xpos = 0; + float ypos = 0; + + Sun(int tempC, float tempXpos, float tempYpos, int size){ + c = tempC; + xpos= tempXpos; + ypos= tempYpos; + s = size; + }//End Sun + + public void display(){ + //For loops for music and changing stroke and size + noStroke(); + fill(c); + sphere(s); + }//End display + } +} diff --git a/java/src/C19326126/Work.java b/java/src/C19326126/Work.java new file mode 100644 index 000000000..a1bc6f097 --- /dev/null +++ b/java/src/C19326126/Work.java @@ -0,0 +1,46 @@ +package C19326126; + +import processing.core.PApplet; +import ddf.minim.analysis.*; +import ddf.minim.*; + + +public class Work extends PApplet{ + AudioPlayer player; + Minim minim; + + public void settings(){ + size(1920, 1080, P3D); + } + + public void setup(){ + smooth(8); + minim = new Minim(this); + player = minim.loadFile("heroplanet.mp3"); + player.play(); + } + + public void draw(){ + translate(width/2, height/2); + background(0); + rotateY( (float) 1.6); + for( int i = 0; i< player.bufferSize() -1; i++){ + rotateX(50+player.right.get(i)/100); + + pushMatrix(); + fill(255,0,0); + popMatrix(); + strokeWeight(1+player.right.get(i)); + + stroke(0); + box(10,10,55+player.right.get(i)*200); + box(55 + player.right.get(i)*50,10,10); + box(10,55 + player.right.get(i)*50, 10); + + + + + } + } + +} diff --git a/java/src/example/RotatingAudioBands.java b/java/src/example/RotatingAudioBands.java index 72fd7a223..75af3eb5d 100644 --- a/java/src/example/RotatingAudioBands.java +++ b/java/src/example/RotatingAudioBands.java @@ -7,14 +7,14 @@ public class RotatingAudioBands extends Visual { public void settings() - { + { size(800, 800, P3D); println("CWD: " + System.getProperty("user.dir")); //fullScreen(P3D, SPAN); } public void keyPressed() - { + { //space key to pause and unpause if (key == ' ') { getAudioPlayer().cue(0); @@ -25,61 +25,76 @@ public void keyPressed() } public void setup() - { + { //HSB color code, frameSize at 256, colorMode(HSB); noCursor(); setFrameSize(256); - + //starting audio library startMinim(); - loadAudio("heroplanet.mp3"); - getAudioPlayer().play(); + loadAudio("heroplanet.mp3"); //loading song + getAudioPlayer().play(); //start playing song immediately on load //startListening(); } - + //radius the squares sit in float radius = 200; - float smoothedBoxSize = 0; + float smoothedBoxSize = 0; //boxsize Default + //rotation float rot = 0; public void draw() { - calculateAverageAmplitude(); + //calc average amplitude. Gets size of audio buffer, builds a total value and divides by buffer size + calculateAverageAmplitude(); try { - calculateFFT(); + calculateFFT(); //acquire frequency } catch(VisualException e) { e.printStackTrace(); } - calculateFrequencyBands(); + calculateFrequencyBands(); //gets the bands of frequency and calculates their size background(0); noFill(); stroke(255); - lights(); + lights(); //adds lighting to the amo,atopm stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); - camera(0, -500, 500, 0, 0, 0, 0, 1, 0); + camera(0, -500, 500, 0, 0, 0, 0, 1, 0); //set camera position //translate(0, 0, -250); - + //rotation speed increase in speed alongside amplitude gain rot += getAmplitude() / 8.0f; + //Y rotates rotateY(rot); + //Smoothed bads is the % increase/decrease rather then snappy moves when audio increases float[] bands = getSmoothedBands(); + //for i through the audio bands for(int i = 0 ; i < bands.length ; i ++) { + //creating the boxes to the spun and changed + + //this is mapping the positions for the boxes to be generated in, 2 PI creates a circle float theta = map(i, 0, bands.length, 0, TWO_PI); + //seperates the boxes into seperate colors depending on band length stroke(map(i, 0, bands.length, 0, 255), 255, 255); + //giving x value coordinates float x = sin(theta) * radius; + //z value coordinates + //both needed to form the circle float z = cos(theta) * radius; + //changes height depending on i inside of bands float h = bands[i]; + //begin 3d box creation pushMatrix(); + //keeps them on 1 plane and is needed for being placed in a circle translate(x, - h / 2 , z); - rotateY(theta); - box(50, h, 50); + rotateY(theta); //rotate in speed with bands + box(50, h, 50); //placing boxes popMatrix(); } diff --git a/java/src/example/SpiralRotation.java b/java/src/example/SpiralRotation.java new file mode 100644 index 000000000..9edfa895b --- /dev/null +++ b/java/src/example/SpiralRotation.java @@ -0,0 +1,74 @@ +package ie.tudublin; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; + + +public class SpiralRotation extends PApplet{ + Minim minim; // Connect to minim + AudioInput ai; // How to connect to mic + AudioPlayer ap; + AudioBuffer ab; // Samples + float[] lerpedBuffer; //buffer size of song playing, so the current volume level + float angle = 0; //angle of spin + float c; //for changing stroke colour + + int angleChange = 2;//amount spin is incremented by + final int ANGLE_LIMIT = 360; //max rotation + + int gap = 20; //gap between arcs + int thickness = 2; //thickness of each arc + + public void settings(){ + size(600,600, P3D); //screen size + } + + public void setup(){ + minim = new Minim(this); //calling minim libraries + //ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + ap = minim.loadFile("MONTEL.mp3", width); + ap.play(); + ab = ap.mix; // Connect the buffer to the mp3 file + //ab = ai.mix; + lerpedBuffer = new float[width]; + colorMode(HSB); + noFill(); + strokeWeight(thickness); + } + + float lerpedAverage = 0; + + public void draw(){ + background(0); + pushMatrix(); //prevents entire canvas from being transformed + translate(width/2, height/2); //move the 0,0 position to the center of the screen so w/2, h/2 + rotate(radians(-angle)); //rotate negative so it rotates the direction I want + + for(int j = 0; j< ab.size(); j++){ //for loop through the total size of the audio buffer, used for expanding arc lines + for(int i = gap; i< width-gap; i+= gap){ //used to create the maximum size the spiral can become + //Colour formatting + float c = map(i, 0, ab.size(), 0, 255); + stroke(c, 255, 255); + + + //angle of the arcs and the lerped buffer given it's value which will constantly change depending on music frequency buffer size + float angle = radians(i); + lerpedBuffer[j] = lerp(lerpedBuffer[j], ab.get(j), 0.1f); + + //arc starting at 0,0 so middle of the screen after the translate and the final value is using lerped buffer to let the arc length change + arc(0, 0, i, i, angle, angle + (lerpedBuffer[j] * 5)); + } + } + //incrementing angle of rotation + angle += angleChange; + //if it hits 360 then it will reset to 0 + if (angle >= ANGLE_LIMIT || angle < 0) + { + angle = 0; + } + popMatrix(); + } +} diff --git a/java/src/example/practiceVisual.java b/java/src/example/practiceVisual.java new file mode 100644 index 000000000..423b102be --- /dev/null +++ b/java/src/example/practiceVisual.java @@ -0,0 +1,68 @@ +package ie.tudublin; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; + + +public class Rendering extends PApplet{ + Minim minim; // Connect to minim + AudioInput ai; // How to connect to mic + AudioPlayer ap; + AudioBuffer ab; // Samples + float[] lerpedBuffer; + float angle; + float c; + + + int gap = 20; //gap between arcs + int thickness = 2; //thickness of each arc + + public void settings(){ + size(600,600, P3D); + } + + public void setup(){ + minim = new Minim(this); + //ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + ap = minim.loadFile("heroplanet.mp3", width); + ap.play(); + ab = ap.mix; // Connect the buffer to the mp3 file + //ab = ai.mix; + lerpedBuffer = new float[width]; + colorMode(HSB); + noFill(); + strokeWeight(thickness); + } + + float lerpedAverage = 0; + + public void draw(){ + background(0); + pushMatrix(); //prevents entire canvas from being transformed + translate(width/2, height/2); + angle = 5; + c = cos(angle); + + + + + for(int j = 0; j< ab.size(); j++){ + for(int i = gap; i< width-gap; i+= gap){ + //Colour formatting + float c = map(i, 0, ab.size(), 0, 255); + stroke(c, 255, 255); + + + //angle of rotation for the spiral and buffer for lerped + float angle = radians(i); + lerpedBuffer[j] = lerp(lerpedBuffer[j], ab.get(j), 0.1f); + + arc(0, 0, i, i, angle, angle + (lerpedBuffer[j] * 5)); + } + } + popMatrix(); + } +} diff --git a/java/src/ie/tudublin/Main.java b/java/src/ie/tudublin/Main.java index d94cec656..0a411f9ae 100644 --- a/java/src/ie/tudublin/Main.java +++ b/java/src/ie/tudublin/Main.java @@ -1,5 +1,6 @@ package ie.tudublin; +import example.AudioBandsVisual; import example.CubeVisual; import example.MyVisual; import example.RotatingAudioBands; @@ -10,7 +11,7 @@ public class Main public void startUI() { String[] a = {"MAIN"}; - processing.core.PApplet.runSketch( a, new RotatingAudioBands()); + processing.core.PApplet.runSketch( a, new CubeVisual()); } public static void main(String[] args)