Recitation 7: Neopixel Music Visualization
Step1: I connected the circuit just as illustrated.
Step2:I applied the code, it worked quite well! Controlling the NeoPixel Stripe by clicking and moving mouse is interesting and beautiful.
Step3: The music I selected was called ‘uchiage hanabi’, a Japanese song, which is my favorite one. Using a software, I converted the .flac version into the .aiff version so that it can be used in processing. Then, I changed the code so that it can play the song. I also added some animations. Since the song is somehow about fireworks, so the animation is also about this, a small problem is that I hope to present the animation of firework blooming in the night sky, but I forgot to adjust the color of the background when I was recording, which make the project not that perfect. I also changed the light, mainly make them blinking and changing colors with the rhythm. The following is the code and the video of my work.
import processing.sound.*; SoundFile sample; Amplitude analysis; import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; int NUM = 60; //amount of pixels int[] r = new int[NUM]; //red of each tile int[] g = new int[NUM]; //red of each tile int[] b = new int[NUM]; //red of each tile void setup() { size(600, 600); // load and play a sound file in a loop sample = new SoundFile(this, "dashanghuahuo.aiff"); sample.loop(); // create the Amplitude analysis object analysis = new Amplitude(this); // analyze the playing sound file analysis.input(sample); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 4); serialRecord.logToCanvas(false); } void draw() { int n=floor(random(1,60)); r[n] = floor(random(255)); g[n] = floor(random(255)); b[n] = floor(random(255)); serialRecord.values[0] = n; // which pixel we change (0-59) serialRecord.values[1] = r[n]; // how much red (0-255) serialRecord.values[2] = g[n]; // how much green (0-255) serialRecord.values[3] = b[n]; // how much blue (0-255) serialRecord.send(); // send it! long t=millis(); if(t>59500){ firework(235,212); } if(t>62500){ firework(420,438); } if(t>65000){ firework(344,388); } if(t>67000){ firework(138,460); } if(t>70500){ firework(442,190); } if(t>72500){ firework(160,230); } if(t>76000){ firework(324,520); } /*if(t>8000){ firework(358,110); }*/ } void firework(float x, float y){ stroke(x,y,x+y); line(x-37,y-30,x-16,y-10); line(x-22,y-44,x-10,y-16); line(x,y-22,x-10,y-50); line(x+4,y-56,x+4,y-30); line(x+22,y-60,x+10,y-20); line(x+30,y-50,x+20,y-28); line(x+30,y-38,x+24,y-25); line(x+60,y-42,x+22,y-18); line(x+48,y-18,x+30,y-12); line(x+26,y-4,x+38,y-4); line(x+22,y,x+60,y+20); line(x+20,y+10,x+28,y+15); line(x+14,y+14,x+36,y+50); line(x+10,y+20,x+14,y+30); line(x+4,y+20,x+6,y+48); line(x-4,y+20,x-8,y+35); line(x-10,y+15,x-24,y+58); line(x-20,y+20,x-25,y+30); line(x-25,y+15,x-55,y+40); line(x-27,y+5,x-60,y+15); line(x-50,y-10,x-32,y-5); }
Leave a Reply