Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file modified java/bin/.DS_Store
Binary file not shown.
Binary file added java/bin/ie/.DS_Store
Binary file not shown.
Binary file modified java/src/.DS_Store
Binary file not shown.
121 changes: 121 additions & 0 deletions java/src/d20125581/sphere.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

package d20125581;

import ddf.minim.AudioBuffer;
import ddf.minim.AudioInput;
import ddf.minim.AudioPlayer;
import ddf.minim.Minim;
import processing.core.PApplet;

public class sphere extends PApplet {
Minim minim;
AudioPlayer ap;
AudioInput ai;
AudioBuffer ab;

int mode = 0;
float y = 0;
float smoothedY = 0;
float smoothedAmplitude = 0;

public void keyPressed() {
if (key >= '0' && key <= '9') {
mode = key - '0';
}
if (keyCode == ' ') {
if (ap.isPlaying()) {
ap.pause();
} else {
ap.rewind();
ap.play();
}
}
}

public void settings() {
size(1024, 1000);
// fullScreen(P3D, SPAN);
}

public void setup() {

minim = new Minim(this);
ap = minim.loadFile("java/data/horizon.mp3", 1024);
ap.play();
ab = ap.mix;
colorMode(HSB);
y = height / 2;
smoothedY = y;

}

float off = 0;
float lerpedBuffer[] = new float[1024];

public void draw() {
float average = 0;
float sum = 0;
off += 1;

// Calculate sum and average of the samples
// Also lerp each element of buffer;
for (int i = 0; i < ab.size(); i++) {
sum += abs(ab.get(i));
lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f);
}
average = sum / (float) ab.size();

smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f);

// Calculate sum and average of the samples
// Also lerp each element of buffer;
for (int i = 0; i < ab.size(); i++) {
sum += abs(ab.get(i));
lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f);
}
average = sum / (float) ab.size();

smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f);

background(0);
noFill();
translate(width / 2, height / 2);

// Draw the sphere
float sphereRadius = 300;
int sphereDetail = 30;
for (float i = 0; i < PI; i += PI / sphereDetail) {
float r1 = sin(i) * sphereRadius;
float r2 = sin(i + PI / sphereDetail) * sphereRadius;
for (float j = 0; j < TWO_PI; j += TWO_PI / sphereDetail) {
float theta = random(0, PI);
float x1 = cos(j) * r1;
float y1 = sin(j) * r1;
float x2 = cos(j) * r2;
float y2 = sin(j) * r2;
float c = (int) ((theta / PI) * 255);
stroke(c, 255, 255);
line(x1, y1, -cos(i) * sphereRadius, x2, y2, -cos(i + PI / sphereDetail) * sphereRadius);
}
}

// Draw the dots
int numDots = 700;
for (int i = 0; i < numDots; i++) {
float theta1 = random(0, PI);
float theta2 = random(0, TWO_PI);
float x = sin(theta1) * cos(theta2) * sphereRadius;
float y = sin(theta1) * sin(theta2) * sphereRadius;
float z = -cos(theta1) * sphereRadius;
float movement = map(smoothedAmplitude, 0, 1, 0, 100); // map amplitude to movement range
x += random(-movement, movement);
y += random(-movement, movement);
z += random(-movement, movement);
float dotSize = map(smoothedAmplitude, 0, 1, 1, 10); // map amplitude to dot size range
ellipse(x, y, dotSize, dotSize);
int hue = (int) ((theta1 / PI) * 255);
fill(hue, 255, 255);
}

}
}
94 changes: 94 additions & 0 deletions java/src/d20125581/spiralNodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package d20125581;

import ddf.minim.AudioPlayer;
import ddf.minim.Minim;
import processing.core.PApplet;
import processing.core.PVector;
import ddf.minim.analysis.*;

public class spiralNodes extends PApplet {
Minim m;
AudioPlayer player;
FFT fft;

Node[] nodes = new Node[1200];

class Node {
PVector loc;
PVector velocity = new PVector(random(-2, 2), random(-2, 2));
float size = 10;
float angle = random(0, TWO_PI);

Node(float x, float y) {
this.loc = new PVector(x, y);
}

void run(float freq) {
this.display();
this.move(freq);
this.bounce();
}

void display() {
point(loc.x, loc.y);
}

void move(float freq) {
float spiralSpeed = freq * 0.1f;
angle += spiralSpeed;
float radius = freq * 0.5f;
loc.x += cos(angle) * radius;
loc.y += sin(angle) * radius;
}

void bounce() {
if ((this.loc.x > width) || (this.loc.x < 0)) {
velocity.x = velocity.x * -1;
}
if ((this.loc.y > height) || (this.loc.y < 0)) {
velocity.y = velocity.y * -1;
}
}
}

public void settings() {
size(1024, 1000);
}

public void setup() {
smooth();

for (int i = 0; i < nodes.length; i++) {
nodes[i] = new Node(random(width), random(height));
}

m = new Minim(this);
player = m.loadFile("java/data/horizon.mp3", 1024);
fft = new FFT(player.bufferSize(), player.sampleRate());
player.play();

}

public void draw() {
noStroke();
noCursor();
background(40, 40, 80);
fft.forward(player.mix);

for (int i = 0; i < nodes.length; i++) {
float freq = fft.getFreq((float) (dist(nodes[i].loc.x, nodes[i].loc.y, width / 2, height / 2) * 2.2));

strokeWeight(freq / 10);
stroke((1 - nodes[i].loc.y / 800) * 255, (nodes[i].loc.x / 800) * 255, (nodes[i].loc.y / 800) * 255);
for (int j = i + 1; j < nodes.length; j++) {
Node other = nodes[j];
float dist = nodes[i].loc.dist(other.loc);
if (dist > 0 && dist < 60) {
line(nodes[i].loc.x, nodes[i].loc.y, other.loc.x, other.loc.y);
}
}
stroke(255);
nodes[i].run(freq);
}
}
}
Binary file added java/src/ie/.DS_Store
Binary file not shown.