ブラーフィルターでじわじわおえかき
ブラーフィルターさんの練習中。
ドラッグ!ドラッグ!
一定のあたい以上黒いところからは白線になるよ!
どうしても黒に白が負けてしまう現象をどうにかしたい
/**
* Copyright maxcaffy ( http://wonderfl.net/user/maxcaffy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hcfU
*/
//ブラーフィルターさんの練習中。
//ドラッグ!ドラッグ!
//一定のあたい以上黒いところからは白線になるよ!
//どうしても黒に白が負けてしまう現象をどうにかしたい
package {
import flash.display.Sprite;
import com.actionscriptbible.Example;
import flash.display.Shape;
public class FlashTest extends Example {
private var s:Shape = new Shape();
private var blur_fields:BlurFields;
public function FlashTest() {
// write as3 code here..
//trace("A");
//s.graphics.beginFill(0x000000);
//s.graphics.drawCircle(100,100,50);
//addChild(s);
blur_fields = new BlurFields(stage,stage.stageWidth,stage.stageHeight,0x000000,0xFFFFFF);
addChild(blur_fields);
}
}
}
import flash.display.Shape;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.filters.BlurFilter;
class BlurFields extends Bitmap{
private var buffer:BitmapData; //ぼかし用フィールド
private var canvas:Shape = new Shape(); //ベクタ用
private var flag_drag:Boolean = false; //ドラッグしてるよー
private var blur:BlurFilter = new BlurFilter(5,5);
private var i:int = 0, k:int = 0;
private var temp_col:uint = 0;
private var flag_toggle:Boolean = false;
private var mouse_prevX:Number = 0, mouse_prevY:Number = 0;
public function BlurFields(stage:Stage,width:int,height:int,linecolor:uint = 0x000000,backcolor:uint = 0xFFFFFF){
super(new BitmapData(width,height,false,backcolor));
//このクラス自身のサイズ決定 よくわからないけどsuperが必要なんだね!
buffer = new BitmapData(width,height,false,backcolor);
stage.addEventListener("enterFrame",_entFunc);
stage.addEventListener("mouseUp",_mouseUp);
stage.addEventListener("mouseDown",_mouseDown);
stage.addEventListener("mouseMove",_mouseMove);
}
private function _entFunc(event:Event):void{
//
//canvas.graphics.lineStyle(3,0x000000);
//canvas.graphics.moveTo(mouse_prevX,mouse_prevY);
//canvas.graphics.lineTo(mouseX,mouseY);
//temp_col = 0;
//for(i=0;i<10;i++){
// for(k=0;k<10;k++){
// temp_col += bitmapData.getPixel(i*(stage.stageWidth/10),k*(stage.stageWidth/10));
// }
//}
//if(temp_col/100 < 0x777777){
// flag_toggle = true;//黒側
//}else{
// flag_toggle = false;
//}
if(flag_toggle){
// buffer.draw(canvas,null,null,"overlay");
buffer.draw(canvas,null,null,"add");
}else{
buffer.draw(canvas,null,null,"overlay");
}
buffer.applyFilter(buffer,buffer.rect,buffer.rect.topLeft,blur);
bitmapData.draw(buffer);
}
private function _mouseUp(event:MouseEvent):void{
flag_drag = false;
canvas.graphics.clear();
}
private function _mouseDown(event:MouseEvent):void{
mouse_prevX = mouseX;
mouse_prevY = mouseY;
flag_drag = true;
if(bitmapData.getPixel(mouseX,mouseY) < 0x800000){
flag_toggle = true;
}else{
flag_toggle = false;
}
}
private function _mouseMove(event:MouseEvent):void{
if(flag_drag){
if(flag_toggle){
canvas.graphics.lineStyle(5,0xFFFFFF);
}else{
canvas.graphics.lineStyle(5,0x000000);
}
canvas.graphics.moveTo(mouse_prevX,mouse_prevY);
canvas.graphics.lineTo(mouseX,mouseY);
mouse_prevX = mouseX;
mouse_prevY = mouseY;
}
}
}