Ciao 访客, welcome back to old school! :p
//导入类库import ddf.minim.*;int counter, degree, incre;int i, j;float baseRadius;float[]xPos = new float[360];float[]yPos = new float[360];float[]xPos20 = new float[20];float[]yPos20 = new float[20];float[]xPosMinMax = new float[36];float[]yPosMinMax = new float[36];float[]xPosLerp = new float[18];float[]yPosLerp = new float[18];boolean shutterStartDraw, shutterMinMax;//声明minim 与in 对象Minim minim;AudioInput in;void setup(){ frameRate(100); size(600, 600); strokeWeight(3); smooth(); //初始化minim 以及in minim = new Minim(this); in = minim.getLineIn(Minim.STEREO, 360); //初始化计数器,原始半径,开关 counter = 1; baseRadius = 150; shutterStartDraw = false; shutterMinMax = false;}void draw(){ //残影效果 noStroke(); fill(0, 20); rect(0, 0, width, height); //移动坐标原点 translate(width/2, height/2); stroke(255); //将声音输入变量与圆弧上的点相关联,每一次draw循环给圆弧上的18个点赋予坐标值 for (int degree = 0; degree < 360; degree += 20) { xPos[degree+counter-1] = cos(radians(degree))*(baseRadius+(in.left.get(degree)+in.right.get(degree))*40); yPos[degree+counter-1] = sin(radians(degree))*(baseRadius+(in.left.get(degree)+in.right.get(degree))*40); } counter ++; //判断draw循环执行20次,每个点有了20组候选坐标值,准备开始画圆 if (counter > 20) { shutterStartDraw = true; //重置计数器 counter = 1; //在每个点的20组候选坐标值中,选取最大最小两个峰值,给lerp函数使用 for (int i = 0; i < 36; i += 2) { //在新的一轮20组赋值开始后,将后面lerp函数末值赋给首值,保证每个点移动的连续性 xPosMinMax[i] = xPosMinMax[i+1]; yPosMinMax[i] = yPosMinMax[i+1]; //将每个点的20组候选坐标值存入数组待选 for (int j = 0; j < 20; j++) { xPos20[j] = xPos[10*i+j]; yPos20[j] = yPos[10*i+j]; } //为后面lerp函数里的末值选取一个峰值,用shutterMinMax逻辑开关实现在不同轮中交替选取Min值与Max值 //需分象限讨论 //第一象限(右下),xy值皆为正 if (i < 9) { if (shutterMinMax) { xPosMinMax[i+1] = max(xPos20); yPosMinMax[i+1] = max(yPos20); } else { xPosMinMax[i+1] = min(xPos20); yPosMinMax[i+1] = min(yPos20); } } //第二象限(左下),x为负,y为正 else if (i > 9 && i < 19) { if (shutterMinMax) { xPosMinMax[i+1] = min(xPos20); yPosMinMax[i+1] = max(yPos20); } else { xPosMinMax[i+1] = max(xPos20); yPosMinMax[i+1] = min(yPos20); } } //第三象限(左上),xy值皆为负 else if (i > 19 && i < 27) { if (shutterMinMax) { xPosMinMax[i+1] = min(xPos20); yPosMinMax[i+1] = min(yPos20); } else { xPosMinMax[i+1] = max(xPos20); yPosMinMax[i+1] = max(yPos20); } } //第四象限(右上),x为正,y为负 else { if (shutterMinMax) { xPosMinMax[i+1] = max(xPos20); yPosMinMax[i+1] = min(yPos20); } else { xPosMinMax[i+1] = min(xPos20); yPosMinMax[i+1] = max(yPos20); } } } //最大值最小值逻辑开关进行运算 shutterMinMax = !shutterMinMax; } //开始画圆 if (shutterStartDraw) { //让每一点在最大值与最小值之间平移 for (int i = 0; i < 36; i += 2) { xPosLerp[i/2] = lerp(xPosMinMax[i], xPosMinMax[i+1], incre/100.0); yPosLerp[i/2] = lerp(yPosMinMax[i], yPosMinMax[i+1], incre/100.0); } //各点连线 beginShape(); curveVertex(xPosLerp[0], yPosLerp[0]); for (int i = 0; i < 18; i++) { curveVertex(xPosLerp[i], yPosLerp[i]); } curveVertex(xPosLerp[0], yPosLerp[0]); curveVertex(xPosLerp[0], yPosLerp[0]); endShape(); //平移增量累加 incre += 5; } //每一轮结束后,重置平移增量 if (incre > 95) incre = 0;}void stop(){ in.close(); minim.stop(); super.stop();}
float [][] xpos = new float[10][10];for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ xpos[i][j] = random(10); }}
beginShape();for(int i=0;i<xpos.length;i++){ for(int j=0;j<ypos.length;j++){ curveVertex(xpos[i],ypos[j]); }}curveVertex(xpos[0],ypos[0]);curveVertex(xpos[1],ypos[1]);curveVertex(xpos[2],ypos[2]);endShape(CLOSE);
import ddf.minim.*;float degree;float [] xPos,yPos;float baseRadius;int complexity;float mapping;AudioPlayer player;Minim minim;float x;void setup(){ size(600, 600); background(0); complexity = 360; mapping = float(360/complexity); minim = new Minim(this); player = minim.loadFile("groove.mp3",complexity); player.loop(); baseRadius = 150; xPos = new float[complexity]; yPos = new float[complexity]; rectMode(CENTER); for(int degree = 0; degree < complexity; degree++){ xPos[degree] = cos(radians(degree))*baseRadius; yPos[degree] = sin(radians(degree))*baseRadius; } smooth();}void draw(){ background(0); translate(width/2,height/2); rotate(radians(x)); strokeWeight(1); stroke(255); noFill(); beginShape(); for(int degree = 0; degree < complexity; degree++){ float radiusT = (baseRadius+(player.left.get(degree)+player.right.get(degree))*500); float xPosT = cos(radians(degree*mapping))*radiusT; float yPosT = sin(radians(degree*mapping))*radiusT; xPos[degree] = lerp(xPos[degree],xPosT,0.2); yPos[degree] = lerp(yPos[degree],yPosT,0.2); curveVertex(xPos[degree],yPos[degree]); } curveVertex(xPos[0],yPos[0]); curveVertex(xPos[1],yPos[1]); curveVertex(xPos[2],yPos[2]); endShape(CLOSE); x+=0.5;}void stop(){ player.close(); minim.stop(); super.stop();}
float radiusT = (baseRadius+(player.left.get(degree)+player.right.get(degree))*500);