水彩画描画
import flash.text.*;
import flash.display.*;
import flash.events.*;
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qaLO
*/
package {
import flash.text.*;
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import com.adobe.images.PNGEncoder;
public class Drawing extends Sprite {
private var j1:oil_draw;
private var prevX:int;
private var prevY:int;
private var startPosX:int;
private var startPosY:int;
private var disX:Number;
private var disY:Number;
private var color:uint;
private var Menu:TabMenu;//フルスクリーン
private var Menu2:TabMenu;//クリア
private var Menu3:TabMenu;
private var s:Sprite;
private var text1:TextField;
public function Drawing() {
text1 = new TextField();
text1.text = "아";
text1.y=20;
addChild(text1);
j1 = new oil_draw();
addChild(j1);
//メニュー1設定
Menu = new TabMenu();
addChild(Menu);
Menu.x = 70; Menu.y = 0;
Menu.init({id: 1, label: "fullscreen", width: 80, direction: TabMenu.DOWN});
Menu.addEventListener(MouseEvent.CLICK, fullscreen);
//メニュー2の設定
Menu2 = new TabMenu();
addChild(Menu2);
Menu2.x = 140; Menu2.y = 0;
Menu2.init({id:2,label:"clear",whdth:80, direction: TabMenu.DOWN});
Menu2.addEventListener(MouseEvent.CLICK,clear);
Menu3 = new TabMenu();
addChild(Menu3);
Menu3.x = 320; Menu3.y = 0;
Menu3.init({id:3,label:"save",whdth:80, direction: TabMenu.DOWN});
stage.addEventListener(MouseEvent.MOUSE_MOVE, on_MouseMove2);//マウス座標取得
init();
}
private function clear(event:MouseEvent):void{
j1.clear();
j1.color = Math.random() * 0xFFFFFF;
j1.Alpha = Math.random() * 1.0;
}
//画面モード切り替え
private function fullscreen( event:MouseEvent ):void{
if(stage.displayState == StageDisplayState.FULL_SCREEN){
stage.displayState = StageDisplayState.NORMAL;//元に戻す
}
else{
stage.displayState = StageDisplayState.FULL_SCREEN;//フルスクリーンモード
}
event.stopPropagation();//イベントの伝播を止める
}
private function init():void {
//ラインスタイル
s.graphics.lineStyle(2,//線の太さ
0x000000,//カラー
0.5,//アルファ値
true,//ヒンディング最適化
"normal",//スケールモード
"round",//線の先の種類
"round");//角の種類
s.addEventListener(MouseEvent.MOUSE_DOWN, on_MouseDown);
s.addEventListener(MouseEvent.MOUSE_UP, on_MouseUp);
s.addEventListener(MouseEvent.MOUSE_WHEEL, wheel);
}
private function wheel(event:MouseEvent):void {
if(0<event.delta){
j1.scaleX *= 1.05;
j1.scaleY *= 1.05;
}
else if(event.delta<0){
j1.scaleX /= 1.05;
j1.scaleY /= 1.05;
}
}
private function on_MouseMove2(event:MouseEvent):void{
text1.text = "x="+ event.stageX + " y="+ event.stageY +" ";
}
private function on_MouseDown(event:MouseEvent):void {
//s.graphics.moveTo(event.localX,event.localY);
//s.addEventListener(MouseEvent.MOUSE_MOVE, on_MouseMove);
//jackson.graphics.moveTo(event.localX,event.localY);
}
private function on_MouseUp(event:MouseEvent):void {
//s.removeEventListener(MouseEvent.MOUSE_MOVE, on_MouseMove);
}
private function on_MouseMove(event:MouseEvent):void {
//s.graphics.lineTo(event.localX,event.localY);
}
//セーブ
private function save():void{
var bd:BitmapData = new BitmapData(stage.width, stage.height);
bd.draw(stage);
var fr:FileReference;
fr = new FileReference();
fr.save( PNGEncoder.encode(bd), 'draw.png' );
}
}
}
//-------------------------------------
// oil_draw
//-------------------------------------
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.CapsStyle;
import flash.display.LineScaleMode;
class oil_draw extends Sprite {
private var jackson:Sprite;
private var area:Sprite;
private var prevX:int;
private var prevY:int;
private var startPosX:int;
private var startPosY:int;
private var disX:Number;
private var disY:Number;
private var size:Number;
public var color:uint;
public var Alpha:Number;
public var Width:Number;
public function oil_draw() {
Alpha = 1;
size = 1;
jackson = new Sprite();
addChild(jackson);
area = new Sprite();
area.graphics.lineStyle(0,0x000000,0);
area.graphics.beginFill(0xffffff,0);
area.graphics.drawRect(0,0,400,400);
area.graphics.endFill();
addChild(area);
addEventListener(MouseEvent.MOUSE_DOWN,_down);
addEventListener(MouseEvent.MOUSE_UP,_up);
addEventListener(MouseEvent.ROLL_OUT,_up);
}
//クリア
public function clear():void {
jackson.graphics.clear();
}
//描画開始
private function _down(event:MouseEvent):void {
prevX = event.stageX;
prevY = event.stageY;
startPosX = event.stageX;
startPosY = event.stageY;
addEventListener(MouseEvent.MOUSE_MOVE, _move);
}
//描画終了
private function _up(event:MouseEvent):void{
removeEventListener(MouseEvent.MOUSE_MOVE, _move);
}
private function _move(event:MouseEvent):void {
var distance:Number = Math.sqrt(Math.pow(prevX - startPosX, 2) + Math.pow(prevY - startPosY, 2))
var a:Number = distance * 10 * (Math.pow(Math.random(), 2) - 0.5)
var r:Number = Math.random() - 0.5
size = Math.random() * 15 / distance;
//disX = (prevX - startPosX) * Math.sin(0.5) + startPosX;
//disY = (prevY - startPosY) * Math.cos(0.5) + startPosY;
disX = prevX; disY = prevY;
startPosX += (prevX-startPosX)/2;
startPosY += (prevY-startPosY)/2;
prevX = event.stageX;
prevY = event.stageY;
jackson.graphics.moveTo(startPosX, startPosY);
jackson.graphics.curveTo(disX,disY,prevX,prevY)
//jackson.graphics.lineTo(prevX,prevY);
jackson.graphics.lineStyle(((Math.random()+20/10-0.5)*size+(1-Math.random()+30/20-0.5)*size), color,Alpha, false, LineScaleMode.NORMAL, CapsStyle.ROUND);
//jackson.graphics.lineStyle(size, color,alpha1, false, LineScaleMode.NORMAL, CapsStyle.ROUND);
if(20 < Math.abs(startPosX-event.stageX)+Math.abs(startPosY-event.stageY) ){
jackson.graphics.moveTo(startPosX + a, startPosY + a);
jackson.graphics.lineTo(startPosX+r+a, startPosY+r+a);
}
jackson.graphics.endFill();
}
}
//---------------------------------------------------
// タブボタン
//---------------------------------------------------
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.filters.DropShadowFilter;
import flash.events.Event;
import flash.events.MouseEvent;
class TabMenu extends Sprite {
public var id:uint;
private var menu:Sprite;
private var btn:Shape;
private var txt:TextField;
private var base:Shape;
private var label:String = "";
private static var fontType:String = "_ゴシック";
private var _width:uint = 60;
private static var _height:uint = 20;
private static var bHeight:uint = 40;
private static var corner:uint = 5;
private var type:uint = 1;
private static var bColor:uint = 0xFFFFFF;
private static var sColor:uint = 0x000000;
private static var tColor:uint = 0x333333;
private static var offColor:uint = 0x999999;
public static const UP:String = "up";
public static const DOWN:String = "down";
private var direction:String = TabMenu.UP;
private var slideIn:Function;
private static var yTarget:uint = 10;
private static var deceleration:Number = 0.5;
private var _enabled:Boolean = true;
public function TabMenu() {
}
public function init(option:Object):void {
if (option.id != undefined) id = option.id;
if (option.label != undefined) label = option.label;
if (option.width != undefined) _width = option.width;
if (option.type != undefined) type = option.type;
if (option.direction != undefined) direction = option.direction;
draw();
}
private function draw():void {
switch (type) {
case 1 :
bColor = 0xFFFFFF;
sColor = 0x000000;
tColor = 0x333333;
offColor = 0x999999;
break;
case 2 :
bColor = 0x000000;
sColor = 0xFFFFFF;
tColor = 0x999999;
offColor = 0x333333;
break;
}
menu = new Sprite();
btn = new Shape();
txt = new TextField();
base = new Shape();
addChild(menu);
menu.addChild(btn);
menu.addChild(txt);
addChild(base);
var shade:DropShadowFilter = new DropShadowFilter(1, 90, sColor, 0.5, 4, 4, 2, 3, false, false);
menu.filters = [shade];
menu.mask = base;
createBox(btn, _width, bHeight, corner);
createMask(base, _width + 10, bHeight);
txt.x = -_width*0.5;
txt.width = _width;
txt.height = _height - 1;
txt.type = TextFieldType.DYNAMIC;
txt.selectable = false;
//txt.embedFonts = true;
//txt.antiAliasType = AntiAliasType.ADVANCED;
var tf:TextFormat = new TextFormat();
tf.font = fontType;
tf.size = 12;
tf.align = TextFormatAlign.CENTER;
txt.defaultTextFormat = tf;
txt.text = label;
switch (direction) {
case TabMenu.UP :
txt.y = - _height;
base.y = - _height;
slideIn = slideUp;
break;
case TabMenu.DOWN :
txt.y = 1;
base.y = _height;
slideIn = slideDown;
break;
}
enabled = true;
mouseChildren = false;
}
private function rollOver(evt:MouseEvent):void {
_over();
removeEventListener(Event.ENTER_FRAME, slideOut);
addEventListener(Event.ENTER_FRAME, slideIn, false, 0, true);
}
private function rollOut(evt:MouseEvent):void {
_up();
removeEventListener(Event.ENTER_FRAME, slideIn);
addEventListener(Event.ENTER_FRAME, slideOut, false, 0, true);
}
private function press(evt:MouseEvent):void {
_down();
}
private function release(evt:MouseEvent):void {
_up();
}
private function click(evt:MouseEvent):void {
}
private function _up():void {
txt.textColor = tColor;
}
private function _over():void {
txt.textColor = tColor;
}
private function _down():void {
txt.textColor = tColor;
}
private function _off():void {
txt.textColor = offColor;
}
private function slideUp(evt:Event):void {
menu.y += (- yTarget - menu.y)*deceleration;
if (Math.abs(- yTarget - menu.y) < 0.5) {
menu.y = - yTarget;
removeEventListener(Event.ENTER_FRAME, slideIn);
}
}
private function slideDown(evt:Event):void {
menu.y += (yTarget - menu.y)*deceleration;
if (Math.abs(yTarget - menu.y) < 0.5) {
menu.y = yTarget;
removeEventListener(Event.ENTER_FRAME, slideIn);
}
}
private function slideOut(evt:Event):void {
menu.y -= menu.y*deceleration;
if (Math.abs(menu.y) < 0.5) {
menu.y = 0;
removeEventListener(Event.ENTER_FRAME, slideOut);
}
}
public function get enabled():Boolean {
return _enabled;
}
public function set enabled(param:Boolean):void {
_enabled = param;
buttonMode = _enabled;
mouseEnabled = _enabled;
useHandCursor = _enabled;
if (_enabled) {
_up();
addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
addEventListener(MouseEvent.MOUSE_DOWN, press, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, release, false, 0, true);
addEventListener(MouseEvent.CLICK, click, false, 0, true);
} else {
_off();
removeEventListener(MouseEvent.MOUSE_OVER, rollOver);
removeEventListener(MouseEvent.MOUSE_OUT, rollOut);
removeEventListener(MouseEvent.MOUSE_DOWN, press);
removeEventListener(MouseEvent.MOUSE_UP, release);
removeEventListener(MouseEvent.CLICK, click);
}
}
private function createBox(target:Shape, w:uint, h:uint, c:uint):void {
target.graphics.beginFill(bColor);
target.graphics.drawRoundRect(-w*0.5, -h*0.5, w, h, c*2);
target.graphics.endFill();
}
private function createMask(target:Shape, w:uint, h:uint):void {
target.graphics.beginFill(bColor);
target.graphics.drawRect(-w*0.5, -h*0.5, w, h);
target.graphics.endFill();
}
}
import flash.display.BitmapData;
class Tile extends BitmapData {
private static var size:uint = 6;
private static var color:uint = 0xFF000000;
public function Tile() {
super(size, size, true, 0x00000000);
init();
}
private function init():void {
setPixel32(0, 2, color);
setPixel32(0, 5, color);
setPixel32(1, 1, color);
setPixel32(1, 4, color);
setPixel32(2, 0, color);
setPixel32(2, 3, color);
setPixel32(3, 2, color);
setPixel32(3, 5, color);
setPixel32(4, 1, color);
setPixel32(4, 4, color);
setPixel32(5, 0, color);
setPixel32(5, 3, color);
}
}