Ciao 访客, welcome back to old school! :p
import ddf.minim.*;import ddf.minim.signals.*; Minim minim;AudioOutput out;SineWave sine;PImage a;int[] aPixels;int direction = 1;boolean onetime = true;float signal; void setup(){ size(800, 535); aPixels = new int[width*height]; noFill(); stroke(255); frameRate(50); a = loadImage("test4.jpg"); for(int i=0; i<width*height; i++) { aPixels[i] = a.pixels[i]; } minim = new Minim(this); // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16 out = minim.getLineOut(Minim.STEREO); // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out sine = new SineWave(440, 0.5, out.sampleRate()); // set the portamento speed on the oscillator to 200 milliseconds sine.portamento(10); // add the oscillator to the line out out.addSignal(sine);} void draw(){ if (signal > width*height-1 || signal < 0) { direction = direction * -1; } if(mousePressed) { if(mouseY > height-1) { mouseY = height-1; } if(mouseY < 0) { mouseY = 0; } signal = mouseY*width+mouseX; } else { signal += (0.33*direction); } loadPixels(); for (int i=0; i<width*height; i++) { pixels[i] = aPixels[i]; } updatePixels(); rect(signal%width-5, int(signal/width)-5, 10, 10); point(signal%width, int(signal/width)); // with portamento on the frequency will change smoothly float freq = map(hue(aPixels[int(signal)]), 0, 255, 261.63, 523.25); //aPixels[int(signal)]; sine.setFreq(freq); // pan always changes smoothly to avoid crackles getting into the signal // note that we could call setPan on out, instead of on sine // this would sound the same, but the waveforms in out would not reflect the panning float pan = map(pixels[int(signal)], 0, width, -1, 1); sine.setPan(pan); print ("\n Brillo= " + brightness (aPixels[int(signal)]) + " hue= " + hue (aPixels[int(signal)]) + " Freq= " + freq);}
import processing.video.*; import ddf.minim.*;import ddf.minim.signals.*;Capture video; PImage prevFrame; float threshold = 150;Minim minim;AudioOutput out;SineWave sine;PImage a;float signal;int[] aPixels;int Mx = 0;int My = 0;int ave = 0; int ballX = width/2;int ballY = height/2;int rsp = 25; void setup() { size(800, 535); // aPixels = new int[width*height]; //noFill(); //stroke(255); //frameRate(50); //a = loadImage("test4.jpg"); aPixels = new int[width*height]; video = new Capture(this, width, height, 30); prevFrame = createImage(video.width,video.height,RGB); for(int i=0; i<width*height; i++) { a = prevFrame; aPixels[i] = a.pixels[i]; }} // print ("chech point 3"); void draw() { if (video.available()) { prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height); prevFrame.updatePixels(); video.read(); for(int i=0; i<width*height; i++) { a = prevFrame; aPixels[i] = a.pixels[i]; } } loadPixels(); video.loadPixels(); prevFrame.loadPixels(); Mx = 0; My = 0; ave = 0; for (int x = 0; x < video.width; x ++ ) { for (int y = 0; y < video.height; y ++ ) { int loc = x + y*video.width; color current = video.pixels[loc]; color previous = prevFrame.pixels[loc]; float r1 = red(current); float g1 = green(current); float b1 = blue(current); float r2 = red(previous); float g2 = green(previous); float b2 = blue(previous); float diff = dist(r1,g1,b1,r2,g2,b2); if (diff > threshold) { pixels[loc] = video.pixels[loc]; Mx += x; My += y; ave++; } else { pixels[loc] = video.pixels[loc]; } } } //print ("chech point 2"); fill(255); rect(0,0, width, height); if(ave != 0){ Mx = Mx/ave; My = My/ave; } if (Mx > ballX + rsp/2 && Mx > 50){ ballX+= rsp; }else if (Mx < ballX - rsp/2 && Mx > 50){ ballX-= rsp; } if (My > ballY + rsp/2 && My > 50){ ballY+= rsp; }else if (My < ballY - rsp/2 && My > 50){ ballY-= rsp; } // updatePixels(); //print ("chech point 1"); minim = new Minim(this); // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16 out = minim.getLineOut(Minim.STEREO); // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out sine = new SineWave(440, 0.5, out.sampleRate()); // set the portamento speed on the oscillator to 200 milliseconds sine.portamento(10); // add the oscillator to the line out out.addSignal(sine); signal = ballY*width+ballX; float freq = map(hue(aPixels[int(signal)]), 0, 255, 261.63, 987.77)/2 ; //aPixels[int(signal)]; sine.setFreq(freq); // pan always changes smoothly to avoid crackles getting into the signal // note that we could call setPan on out, instead of on sine // this would sound the same, but the waveforms in out would not reflect the panning float pan = map(pixels[int(signal)], 0, width, -1, 1); sine.setPan(pan); print ("\n Brillo= " + brightness (aPixels[int(signal)]) + " hue= " + hue (aPixels[int(signal)]) + " Freq= " + freq); //print ("ballX = "+ ballX + " ballY =" + ballY); //print("signal =" + signal); //print("freq =" + freq); updatePixels(); noFill(); //noStroke(); //fill(0,0,0); ellipse(ballX, ballY, 25, 25); }
import ddf.minim.*;import ddf.minim.signals.*; Minim minim;AudioOutput out;SineWave sine;PImage a;
如果报错,请帖错误信息大于10行的代码我是肯定不会看的请尊重帮你解答问题的人
请这样引用代码,编辑工具里的“#” 程序代码import ddf.minim.*;import ddf.minim.signals.*; Minim minim;AudioOutput out;SineWave sine;PImage a;