int riceMax = 100; Rice[] riceList = new Rice[riceMax]; MidiOut midiOut; int screenCache = 0; String[] noteList = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}; int[] maj = {0,4,7};//0 int[] minor = {0,3,7}; int[] maj7 = {0,4,7,11};//2 int[] seven = {0,4,7,10}; int[] seven13 = {0,4,5,7,10};//4 int[] m7 = {0,3,7,10}; int[] majb5 = {0,4,6};//6 int[] dim = {0,3,6}; int[] dim7 = {0,3,6,10};//8 int[] maj4 = {0,4,5,7}; int[] maj2 = {0,2,4,7};//10 int[] maj6 = {0,4,7,9}; int[] maj7b = {0,4,7,10};//12 int[] m11 = {0,2,3,7,10}; int[] m13 = {0,3,5,7,10};//14 int[] m6 = {0,3,5,9}; int[] seven9 = {0,2,4,10};//16 int[] seven5 = {0,4,10};//17 int[] song1 = {5,5 ,7,7,7,0,5,6 ,5,5 ,7,7,7,0,5,5 ,6,6,11,11,6,6, 2, 2,7,7, 3, 3,9,2 ,7,0 };//keyShift int[] song2 = {2,11,4,3,5,2,2,17,2,11,4,3,5,2,2,11,2,2,16,16,5,5,16,16,5,5,16,16,5,16,5,16 };//currentChord color[] colorBank = new color[16]; int[][] chordList = {maj,minor,maj7,seven,seven13,m7,majb5,dim,dim7,maj4,maj2,maj6,maj7b,m11,m13,m6,seven9,seven5}; String[] chordListName = {"","m","maj7","7","13","m7","majb5","dim","dim7","add4","add2","6","7b","m11","m13","m6","7#9","7#5"}; int currentChord; int keyShift; int relationMax = 500; Relation[] relationList = new Relation[relationMax]; BFont DIN; int token; float timer = 0; color bg,tbg,cbg; float camX,camY; float tcamX,tcamY; float panX,panY; float tpanX,tpanY; int beat = 0; void setup() { size(640, 480); framerate(60); colorMode(RGB,256); colorBank[0] = color(70,110,120); colorBank[1] = color(209,34,47); colorBank[2] = color(160,110,13); colorBank[3] = color(20,113,86); colorBank[4] = color(139,121,0); colorBank[5] = color(143,125,0); colorBank[6] = color(230,109,2); colorBank[7] = color(97,43,0); colorBank[8] = color(165,198,145); colorBank[9] = color(22,111,83); colorBank[10] = color(216,200,63); colorBank[11] = color(92,57,64); colorBank[12] = color(162,162,134); colorBank[13] = color(152,162,134); colorBank[14] = color(162,152,134); colorBank[15] = color(162,162,124); bg = color(162,162,134); cbg = color(162,162,134); tbg = colorBank[int(random(15.4))]; for (int i=0; i 150){ timer =0; beat++; if(beat >= song1.length)beat = 0; // if(random(100)>50)keyShift = (keyShift+7+12)%12; // currentChord = int(random(13)); keyShift = song1[beat]; currentChord = song2[beat]; tbg = colorBank[int(random(15.4))]; colorMode(HSB,256); tbg = color(hue(tbg),saturation(tbg)*0.5,brightness(tbg)*0.4); tcamX = tcamX+random(-200,200); tcamY = tcamY+random(-200,200); tpanX = random(-100,100); tpanY = random(-100,100); } camX = camX*0.9 + tcamX*0.1; camY = camY*0.9 + tcamY*0.1; panX = panX*0.9 + tpanX*0.1; panY = panY*0.9 + tpanY*0.1; color bg = color(0,0,0,4); fill(bg); // rect(0,0,width,height); token++; if(token>=riceMax)token=0; for (int i=0; i 100){ // dir = -1; // pos = 100; // dir *= -1; pos = 0; midiOut.setNoteOff(0,riceList[index2].pitch); midiOut.setNoteOn(0,riceList[index2].pitch, max(127-int(speed*4),30)); riceList[index2].voice += (max(127-int(speed*2),30))*0.35; riceList[index2].speed2 += 20; // midiOut.setNoteOff(0,riceList[index1].pitch); playNote = false; int next; if(riceList[index2].relationP==-1 || riceList[index2].relationN==-1){// end of group next = index; }else if(riceList[index2].relationP != index){ next = riceList[index2].relationP; }else{ next = riceList[index2].relationN; } relationList[next].a = 100; relationList[next].playNote = true; if(relationList[next].index1 != index2){ int tmp1 = relationList[next].index1; int tmp2 = relationList[next].index2; relationList[next].index1 = tmp2; relationList[next].index2 = tmp1; } }else{ noFill(); float dx = riceList[index2].cx-riceList[index1].cx; float dy = riceList[index2].cy-riceList[index1].cy; float dz = riceList[index2].cz-riceList[index1].cz; push(); translate(width/2+panX,height/2+panY,-100); // rotateX((mouseY-height/2)*0.01); // rotateY((mouseX-width/2)*0.01); rotateX(camX*0.01); rotateY(camY*0.01); translate(-width/2,-height/2); ellipseMode(CENTER_DIAMETER); translate(riceList[index1].cx+dx*pos/100, riceList[index1].cy+dy*pos/100,riceList[index1].cz+dz*pos/100); // translate(riceList[index1].cx+dx*pos/100, riceList[index1].cy+dy*pos/100); rotateY(camY*-0.01); rotateX(camX*-0.01); // rotateY((mouseX-width/2)*-0.01); // rotateX((mouseY-height/2)*-0.01); stroke(hue(relationList[group].c),saturation(relationList[group].c),brightness(relationList[group].c),a*0.6); ellipse(0,0, 3, 3); stroke(hue(relationList[group].c),saturation(relationList[group].c),brightness(relationList[group].c),a*0.3); ellipse(0,0, 6, 6); pop(); } } } void spawn(int Index1,int Index2){ index1 = Index1; index2 = Index2; connected = 1; connected2 =1; a = 0; group = index; playNote = true; } void checkGroup(){ int group2 = group; if(riceList[index1].relationP!=-1)group = min(group,relationList[riceList[index1].relationP].group); if(riceList[index1].relationN!=-1)group = min(group,relationList[riceList[index1].relationN].group); if(riceList[index2].relationP!=-1)group = min(group,relationList[riceList[index2].relationP].group); if(riceList[index2].relationN!=-1)group = min(group,relationList[riceList[index2].relationN].group); if(group2!=group){ playNote = false; } } void resetGroup(int Group){ for(int i=0; i< relationMax; i++){ if(relationList[i] != null){ if(relationList[i].group == Group){ relationList[i].group = relationList[i].index; relationList[i].playNote = true; } } } } int countGroup(int Group){ int Count = 0; for(int i=0; i< relationMax; i++){ if(relationList[i] != null){ if(relationList[i].group == Group){ Count++; } } } return Count; } void drawCurve(int Group, int Count){ if(Count >= 4){ stroke(relationList[group].c); beginShape(LINE_LOOP); for(int i=0; i< relationMax; i++){ if(relationList[i] != null){ if(relationList[i].group == Group){ float x = riceList[relationList[i].index1].cx*0.5 + riceList[relationList[i].index2].cx*0.5; float y = riceList[relationList[i].index1].cy*0.5 + riceList[relationList[i].index2].cy*0.5; curveVertex(x,y); } } } endShape(); } } void setSpeed(int Group, float Speed){ for(int i=0; i< relationMax; i++){ if(relationList[i] != null){ if(relationList[i].group == Group){ relationList[i].speed = Speed; } } } } void checkTension(){ int keyInChord1 = 0; for(int a=0;a 360 || keyInChord1==0 || keyInChord2==0)&&connected==1 ){ //////////// breakup connected = 0; if(riceList[index1].indexP == index2)riceList[index1].indexP = -1;riceList[index1].relationP = -1; if(riceList[index1].indexN == index2)riceList[index1].indexN = -1;riceList[index1].relationN = -1; if(riceList[index2].indexP == index1)riceList[index2].indexP = -1;riceList[index2].relationP = -1; if(riceList[index2].indexN == index1)riceList[index2].indexN = -1;riceList[index2].relationN = -1; resetGroup(group); /* if(riceList[index1].indexP == index2)riceList[index1].indexP = -1; if(riceList[index1].indexN == index2)riceList[index1].indexN = -1; if(riceList[index2].indexP == index1)riceList[index2].indexP = -1; if(riceList[index2].indexN == index1)riceList[index2].indexN = -1;*/ // midiOut.setNoteOff(0,riceList[index1].pitch); // midiOut.setNoteOff(0,riceList[index2].pitch); ////////////////// } } } /////////////////////////////////////////////////////////// class Rice{ // float x,y; // root position float cx, cy, cz;// current position int index, indexP, indexN; int relationP,relationN; int controller; int pitch,pitch2,octave; // pitch2 = 0-11 int col,row; String note; String actionFoot,actionHead; float angle,angleB, speed, speed2, energy, torque, standTimer, stareTimer; int torqueDir; float voice; float a;//alpha boolean connectionFull; color c; Rice(int I){ // x= random(width); // y= random(height); cx= random(width/2-200,width/2+200); cy= random(height/2-200,height/2+200); cz = random(-200,200); index = I; indexP = -1; indexN = -1; pitch = int(random(30,100)); pitch2 = pitch%12; octave = int(Math.floor(pitch/12)); note = noteList[pitch2]; actionFoot = "walk"; actionHead = "turn"; angle = random(0,PI*2);angleB = random(0,PI*2); speed = random(0.2,1); speed2 = 0; energy = random(5,20); torque = random(5,20); torqueDir = int(random(-10,10)); standTimer = stareTimer = 0; voice = 0; a = 0; connectionFull = false; relationP =relationN = -1; c = colorBank[pitch2]; } void refreshPosition(){ speed2 = speed2*0.7; if(energy> 2 && actionFoot!="stand"){ walk(); }else{ if(actionFoot!="stand"){ standTimer = random(1,10); } stand(); } if(torque> 2 && actionHead!="stare"){ turn(); }else{ if(actionHead!="stare"){ torqueDir = int(random(-10,10)); stareTimer = random(5,20); } stare(); } float cxSum,cySum,czSum,proportionX, proportionY,proportionZ; cxSum = cx*20;cySum = cy*20;czSum = cz*20; proportionX =20 ;proportionY =20;proportionZ =20; if(indexP !=-1){ float t; if(relationP!=-1){ t = relationList[relationP].d/5000; }else{ t = 0.01; } cxSum += riceList[indexP].cx*t; cySum += riceList[indexP].cy*t; czSum += riceList[indexP].cz*t; proportionX += t; proportionY += t; proportionZ += t; } if(indexN !=-1){ float t; if(relationN!=-1){ t = relationList[relationN].d/5000; }else{ t = 0.01; } cxSum += riceList[indexN].cx* t; cySum += riceList[indexN].cy* t; czSum += riceList[indexN].cz* t; proportionX += t; proportionY += t; proportionZ += t; } if(indexP != -1 || indexN != -1){ // cxSum += float(pitch)/128*width * 0.07; // proportionX += 0.07; cxSum += width/2 * 0.02; proportionX += 0.02; cySum += height/2 * 0.02; proportionY += 0.02; czSum += 0 * 0.02; proportionZ += 0.02; } cx = cxSum/proportionX; cy = cySum/proportionY; cz = czSum/proportionZ; } void turn(){ actionHead = "turn"; if(torqueDir>0){ angle += float(torque)/180*PI; angleB += float(torque)/300*PI; } if(torqueDir<=0){ angle -= float(torque)/180*PI; angleB -= float(torque)/300*PI; } torque--; } void stare(){ torque++; stareTimer--; if(stareTimer>0){ actionHead = "stare"; }else{ actionHead = "turn"; } } void walk(){ actionFoot = "walk"; float comx = cos(angle); float comy = sin(angle); float h = speed+speed2; float comz = sin(angleB); float dz = h*comz; cz += dz; float h2 = sqrt(h*h -dz*dz); cx += h2*comx; cy += h2*comy; energy--; } void stand(){ energy = energy + 10; standTimer--; if(standTimer>0){ actionFoot = "stand"; }else{ actionFoot = "walk"; } } void checkConnection(){ float dx,dy,dz,d; for(int i=index+1;i