Interactive Authoring: Visual Music

import ddf.minim.*;
import ddf.minim.analysis.*;

import codeanticode.tablet.*;
Tablet tablet;

Minim minim;
AudioPlayer player;
AudioInput input;
AudioPlayer song;
BeatDetect beat;

int d = 0;
float spin = 0.0;
float eRadius;
int step = 1;
int c1 = 0;
int c2 = 255;
int c3 = 0;
boolean background = false;
boolean circlebeat = false;

void setup() {
size(800, 800, P3D);
smooth(4);
tablet = new Tablet(this);
minim = new Minim(this);

song = minim.loadFile(“spectrum.mp3”,1024);
song.play();
beat = new BeatDetect();
ellipseMode(RADIUS);
}

void draw() {
float a = map(eRadius, 20, 80, 60, 255);
beat.detect(song.mix);

noCursor();

if (background == false) {
fill(0);
rect(-20,-20,850,850);
if(circlebeat == true){
if ( beat.isOnset() ) eRadius = 300;
strokeWeight(4);
ellipse(400, 400, eRadius, eRadius);
eRadius = 250;
}
}
lights();
// sphere code from https://www.openprocessing.org/sketch/154
pushMatrix();
strokeWeight(1);
translate(400, 400, 0.0);
rotateY(spin);
drawSphere(0.0, 0.0, 100.0); // origin X, origin Y, radius, level inward, degrees roatation, num of total degrees
popMatrix();

if (spin <= TWO_PI) spin = spin + 0.006;
else spin = 0.0;

if (d < 360) d++; else d = 0; if (mousePressed) { strokeWeight(20 * tablet.getPressure()); } if (keyPressed) { if (key == CODED) { if (keyCode == SHIFT) { noStroke(); fill(c1,c2,c3); rect(random(800),random(800),random(50,100),random(50,100)); rect(random(800),random(800),random(50,100),random(50,100)); rect(random(800),random(800),random(50,100),random(50,100)); rect(random(800),random(800),random(50,100),random(50,100)); rect(random(800),random(800),random(50,100),random(50,100)); rect(random(800),random(800),random(50,100),random(50,100)); rect(random(800),random(800),random(50,100),random(50,100)); } } if (key == CODED) { if (keyCode == ALT) { fill(c1,c2,c3); strokeWeight(3); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); line(400,400,random(0,800),random(0,800)); } } if (key == CODED) { if (keyCode == CONTROL) { strokeWeight(3); fill(c1,c2,c3); line(0,800,mouseX+400,mouseY); line(0,800,mouseX+400,mouseY-40); line(0,800,mouseX+400,mouseY-80); line(0,800,mouseX+400,mouseY-120); line(0,800,mouseX+400,mouseY-160); line(0,800,mouseX+400,mouseY-200); line(0,800,mouseX+400,mouseY-240); line(0,800,mouseX+400,mouseY-280); line(0,800,mouseX+400,mouseY-320); line(0,800,mouseX+400,mouseY-360); //other side line(800,800,mouseX-400,mouseY); line(800,800,mouseX-400,mouseY-40); line(800,800,mouseX-400,mouseY-80); line(800,800,mouseX-400,mouseY-120); line(800,800,mouseX-400,mouseY-160); line(800,800,mouseX-400,mouseY-200); line(800,800,mouseX-400,mouseY-240); line(800,800,mouseX-400,mouseY-280); line(800,800,mouseX-400,mouseY-320); line(800,800,mouseX-400,mouseY-360); } } if (key == ‘2’ ) { if (circlebeat == false) { circlebeat = true; } } if (key == ‘3’ ) { if (circlebeat == true){ circlebeat = false; } } } } void drawSphere(float x, float y, float radius) { noFill(); stroke(c1,c2,c3); pushMatrix(); translate(x, y, 0); sphere(radius*2.5); popMatrix(); if (c2 >= 255) {
step = 1;
}

if (step ==1) {
c1 = c1 + 3;
c2 = c2 – 3;
c3 = c3 – 3;
}

if (c2 <= 0) { step = 2; } if (step ==2) { c1 = c1 – 2; c2 = 0; c3 = c3 + 4; } if (c3 >= 255) {
step = 3;
}
if(step == 3){
c2 = c2 +3;
c3 = c3 -3;
c1 = 0;
}
}

void keyPressed(){
if (key == ‘1’ ) {
if (background == true){
background = false;
}
else if (background == false){
background = true;
}
}
}

Advertisements
This entry was posted in interactive, time based and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s