/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function findBlingPoints(o:*, n:Number, s:String="right"){ var myBitmapData:BitmapData = new BitmapData(o.width, o.height, true, 0x000000); myBitmapData.draw(o); var pixelValue:uint; var pointArray:Array = []; var currPixel:Boolean = false; var lastPixel:Boolean = false; for(var i=0; i<myBitmapData.width; i++){ pixelValue = myBitmapData.getPixel32(i, n); if(pixelValue==0){currPixel=false}else{currPixel=true}; switch (s){ case "right": if(!currPixel&&lastPixel){ pointArray[pointArray.length]=i; pointArray[pointArray.length]=n; } break; case "left": if(!lastPixel&&currPixel){ pointArray[pointArray.length]=i; pointArray[pointArray.length]=n; } break; case "both": if(lastPixel!=currPixel){ pointArray[pointArray.length]=i; pointArray[pointArray.length]=n; } break; } lastPixel = currPixel; } return pointArray; }