import rwmidi.*; MidiOutput output; int scale[] = new int[] {12, 10, 8, 7, 5, 3, 2, 0 }; int prevPitch = 0; int MAX = 100; //set up some global variables as arrays now int[] xspeed = new int[MAX]; int[] yspeed = new int[MAX]; int[] x = new int[MAX]; int[] y = new int[MAX]; float[] r = new float[MAX]; color []elColor = new color [MAX]; //our setup function void setup() { size(800,600); //define size //initialize all arrays for (int i = 0; i < MAX; i++) { random(i); xspeed[i] = int(random(-10,2)); yspeed[i] = int(random(-5,2)); x[i] = mouseX; y[i] = mouseY; r[i] = 10; elColor[i]= color(0,0,0,0); } MidiOutputDevice devices[] = RWMidi.getOutputDevices(); output = RWMidi.getOutputDevices()[0].createOutput(); //ESTE FOR ES PARA QUE APAGUE AL PRINCIPIO CUALQUIER NOTA QUE QUEDE SONANDO for(int i=0; i<=127; i++){ notoutput(i); } } //METODOS int pitchValue(int x, int y) { return (x + y) % 3 * 12 + 40; } void output(int y) { output.sendNoteOn(0, y+20, 100); } void notoutput(int y) { output.sendNoteOff(0, y+20, 100); } void draw() { background(50); //first we draw the background ellipseMode(CENTER); //set our ellipse mode noStroke(); for (int i = 0; i < MAX; i++) { fill(elColor[i]); //set ellipse color ellipse(x[i],y[i],r[i],r[i]); //draw ellipse //radius always decreases back to 10 if it's bigger if (r[i] > (10)) { r[i]--; elColor[i]= color(random(0,255),0,0); notoutput(prevPitch); if(i%2 == 0){ int posPitch = floor(map(i, 0, MAX, 0, 7)); int pitch = scale[posPitch]; output(pitch); prevPitch=pitch; } } //adjust x,y based on speed x[i] = x[i] + xspeed[i]; y[i] = y[i] + yspeed[i]; //acount for bouncing off edges if ((x[i] > width) || (x[i] < 0)) { xspeed[i] = xspeed[i] * -1; r[i] = random(10,100); //adjust radius when bouncing elColor[i]= color(0,255,0); notoutput(prevPitch); if(i%2 == 0){ int posPitch = floor(map(i, 0, MAX, 0, 7)); int pitch = scale[posPitch]; output(pitch); prevPitch=pitch; } } if ((y[i] > height) || (y[i] < 0)) { yspeed[i] = yspeed[i] * -1; r[i] = random(10,100); elColor[i]= color(0,0,255); notoutput(prevPitch); if(i%2 == 0){ int posPitch = floor(map(i, 0, MAX, 0, 7)); int pitch = scale[posPitch]; output(pitch); prevPitch=pitch; } notoutput(prevPitch); } } }