What if the edge is the score?
What if our shape is music?
What if the time we spend and the gesture we make is Music?
import mx.transitions.Tween;
import flash.display.BitmapData;
import flash.geom.*;
// panelEDGE : collect & display the edge from panelBMP's analysis
// panelBMP : show the BMP finally generated from the panelPIC
// panelPIC : generate the picture pattern
// butExec :
// butEdge : exec findEDGE()
stgW = 700;
stgH = 400;
edgeThickness = 0;
edgeColorUp = 0x0000FF;
edgeColorDown = 0x00FF00;
edgeAlpha = 100;
//
var BMPdata:BitmapData = new BitmapData(stgW, stgH, false, 0x000000);
panelBMP.attachBitmap(BMPdata,this.getNextHighestDepth());
//
//
function genScreen(iconMode, picTotal, choice) {
// 1 load pic to panelPIC
allPicContainer = panelPIC.createEmptyMovieClip("allPicContainer", 0);
allPicContainer._y = stgH;
t = picTotal-1;
attachID = "graphic_Icon"+choice;
allPicContainer.onEnterFrame = function() {
iconMC = allPicContainer.attachMovie(attachID, "mc"+t, t);
iconMC._x = (picTotal-t)*50;
iconMC.gotoAndStop(t+1);
t--;
if (t<0) {
delete this.onEnterFrame;
}
//
allPicContainer._width = stgW;
allPicContainer._yscale = allPicContainer._xscale;
// 2 map the visual to the panelBMP
if (iconMode == 0) {
BMPdata.fillRect(new Rectangle(0, 0, stgW, stgH),0x000000);
}
BMPdata.draw(panelPIC);
};
}
function findEdge() {
pianoUpArray = new Array();
pianoDownArray = new Array();
// compare top pixel profile line
for (i=0; i<stgW; i++) {
for (j=0; j<stgH; j++) {
var pixelValue = BMPdata.getPixel(i, j);
if (pixelValue != 0) {
pianoUpArray.push([i, j, pixelValue]);
break;
}
}
}
// compare down pixel profile line
for (i=0; i<stgW; i++) {
for (j=stgH-1; j>=0; j--) {
var pixelValue = BMPdata.getPixel(i, j);
if (pixelValue != 0) {
pianoDownArray.push([i, j, pixelValue]);
break;
}
}
}
// draw the edge
panelEDGE.clear();
//
panelEDGE.lineStyle(edgeThickness,edgeColorUp,edgeAlpha);
panelEDGE.moveTo(pianoUpArray[0][0],pianoUpArray[0][1]);
//
for (var e = 1; e<pianoUpArray.length; e++) {
panelEDGE.lineTo(pianoUpArray[e][0],pianoUpArray[e][1]);
}
//
//
panelEDGE.lineStyle(edgeThickness,edgeColorDown,edgeAlpha);
panelEDGE.moveTo(pianoUpArray[0][0],pianoUpArray[0][1]);
for (var e = 0; e<pianoDownArray.length; e++) {
panelEDGE.lineTo(pianoDownArray[e][0],pianoDownArray[e][1]);
}
//
var panelEDGE_twnAlpha:Tween = new Tween(panelEDGE, "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 1, true);
var panelPIC_twnAlpha:Tween = new Tween(panelBMP, "_alpha", mx.transitions.easing.Strong.easeOut, 100, 50, 1, true);
}
function playPiano() {
interval = 25;
walk = 0;
soundFile = "piano_lines";
//
piano0.stop();
piano1.stop();
piano0 = new Sound();
piano1 = new Sound();
//
piano0.attachSound(soundFile);
piano1.attachSound(soundFile);
//
playHead.onEnterFrame = function() {
step = walk%stgW;
this._x = step;
//
if (this.hitTest(panelEDGE) && step%interval == 0) {
// UP
for (u=0; u<pianoUpArray.length; u++) {
var activeNoteX = pianoUpArray[u][0];
var activeNoteY = int(pianoUpArray[u][1]/stgH*80);
if (step == activeNoteX) {
piano0.setVolume(random(71)+30);
piano0.start(activeNoteY,1);
trace("activeNoteY0 : "+activeNoteY);
}
}
// DOWN
for (u=0; u<pianoDownArray.length; u++) {
var activeNoteX = pianoDownArray[u][0];
var activeNoteY = int(pianoDownArray[u][1]/stgH*80);
if (step == activeNoteX) {
piano1.setVolume(random(71)+30);
piano1.start(activeNoteY,1);
trace("activeNoteY1 : "+activeNoteY);
}
}
piano0.setVolume(piano0.getVolume()-1);
piano1.setVolume(piano1.getVolume()-1);
} else {
if (piano0.getVolume()>0) {
piano0.setVolume(piano0.getVolume()-2);
}
if (piano1.getVolume()>0) {
piano1.setVolume(piano1.getVolume()-2);
}
}
//
walk++;
};
}
function resetApp() {
allPicContainer.removeMovieClip();
//
BMPdata.fillRect(new Rectangle(0, 0, stgW, stgH),0x000000);
panelBMP._alpha = 100;
panelEDGE.clear();
//
delete playHead.onEnterFrame;
playHead._x = -10;
//
piano0.stop();
piano1.stop();
}
butExec.onPress = function() {
genScreen(random(2),random(26)+5,random(2));
};
butEdge.onPress = function() {
findEdge();
};
butSing.onPress = function() {
playPiano();
};
butReset.onPress = function() {
resetApp();
};
