as3paintoco出来たかも

今年の3月くらいからまったりと開発して来ました、お絵描きライブラリ。

とりあえず、それなりに動くようなりました。
そこで、こっそりとGoogle Codeにて公開してみました。

その名も、as3paintoco(ぺいんとこ)と言います。

機能

主に、以下のような機能を持っています。

  • undo, redo機能
  • replay機能
  • お絵描きした画像の保存機能

使い方

as3paintoco(ぺいんとこ)はFlash Player10.0.32以降に対応しております。ただし、開発中ステータスのため予期しない動作をするかも知れません。その点ご了承下さい。

ライブラリの準備

  1. このライブラリは、as3corelibを使用しているので、as3corelib.swcをライブラリパスに通します。
  2. as3paintoco_alpha4.swcをダウンロードして、ライブラリパスに通します。

サンプルコード

コンテキストメニューからツールを選んで、キャンバスにお絵描きするサンプルです。

The Flash plugin is required to view this object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package 
{
    import flash.display.Sprite;
    import flash.events.ContextMenuEvent;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import jp.wxd.as3paintoco.AS3Paintoco;
    import jp.wxd.as3paintoco.tools.CircleTool;
    import jp.wxd.as3paintoco.tools.ITool;
    import jp.wxd.as3paintoco.tools.LineTool;
    import jp.wxd.as3paintoco.tools.PenTool;
    import jp.wxd.as3paintoco.tools.SelectTool;
    import jp.wxd.as3paintoco.tools.SquareTool;
    import jp.wxd.as3paintoco.tools.TextTool;
 
    /**
     * as3Paintoco sampleコード2
     * @author Copyright (C) naoto koshikawa, All Rights Reserved.
     */
    public class PaintocoWork2 extends Sprite
    {
        //----------------------------------------------------------------------
        //  properties
        //----------------------------------------------------------------------
        //------------------------------
        //  private properties
        //------------------------------
        /**
         * AS3Paintoco instance
         */
        private var _paint:AS3Paintoco;
 
        /**
         * tools
         */
        private var _tools:Object;
 
        //----------------------------------------------------------------------
        //  methods
        //----------------------------------------------------------------------
        //------------------------------
        //  public methods
        //------------------------------
        /**
         * constructor
         */
        public function PaintocoWork2() 
        {
            _tools = {
                penTool: new PenTool(),
                lineTool: new LineTool(),
                squareTool: new SquareTool(),
                circleTool: new CircleTool(),
                textTool: new TextTool(),
                selectTool: new SelectTool()
            };
 
            _tools.textTool.options = {
                size:24
            };
 
            // AS3Paintocoのインスタンスを生成します。
            _paint = new AS3Paintoco(this, 465, 465);
            _paint.replayable = true;
            initialize();
            createMenu();
        }
 
        /**
         * initialize 
         */
        private function initialize():void
        {
           _paint.initialize();
           // 初期ツールを設定します。
            _paint.applyTool(_tools.penTool);
 
            // キャンバスをアクティブにしお絵描き可能にします。
            _paint.activate();
        }
 
        /**
         * create context menu
         */
        private function createMenu():void
        {
            var contextMenu:ContextMenu = new ContextMenu();
            contextMenu.hideBuiltInItems();
 
            var penMenu:ContextMenuItem = new ContextMenuItem("penTool", true);
            var lineMenu:ContextMenuItem = new ContextMenuItem("lineTool");
            var squareMenu:ContextMenuItem = new ContextMenuItem("squareTool");
            var circleMenu:ContextMenuItem = new ContextMenuItem("circleTool");
            var textMenu:ContextMenuItem = new ContextMenuItem("textTool");
            var selectMenu:ContextMenuItem = new ContextMenuItem("selectTool");
 
            penMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexToolMenu_menuSelect);
            lineMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexToolMenu_menuSelect);
            squareMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexToolMenu_menuSelect);
            circleMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexToolMenu_menuSelect);
            textMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexToolMenu_menuSelect);
            selectMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexToolMenu_menuSelect);
 
            var clearMenu:ContextMenuItem = new ContextMenuItem("clearAction");
            var undoMenu:ContextMenuItem = new ContextMenuItem("undoAction");
            var redoMenu:ContextMenuItem = new ContextMenuItem("redoAction");
            var replayMenu:ContextMenuItem = new ContextMenuItem("replayAction", true);
            var saveMenu:ContextMenuItem = new ContextMenuItem("saveAction", true);
 
            clearMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexActionMenu_menuSelect);
            undoMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexActionMenu_menuSelect);
            redoMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexActionMenu_menuSelect);
            replayMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
                contexActionMenu_menuSelect);
            saveMenu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
				contexActionMenu_menuSelect);
 
            contextMenu.customItems.push(clearMenu);
            contextMenu.customItems.push(undoMenu);
            contextMenu.customItems.push(redoMenu);
            contextMenu.customItems.push(replayMenu);
            contextMenu.customItems.push(penMenu);
            contextMenu.customItems.push(lineMenu);
            contextMenu.customItems.push(squareMenu);
            contextMenu.customItems.push(circleMenu);
            contextMenu.customItems.push(textMenu);
            contextMenu.customItems.push(selectMenu);
            contextMenu.customItems.push(saveMenu);
 
            this.contextMenu = contextMenu;
        }
 
        //----------------------------------------------------------------------
        //  event listener
        //----------------------------------------------------------------------
        /**
         * ContextMenuEvent.MENU_SELECT
         * @param    event
         */
        private function contexToolMenu_menuSelect(event:ContextMenuEvent):void
        {
            var toolKey:String = ContextMenuItem(event.target).caption;
            // 選択されたツールを適用します。
            _paint.applyTool(_tools[toolKey]);
        }
 
        /**
         * ContextMenuEvent.MENU_SELECT
         * @param    event
         */
        private function contexActionMenu_menuSelect(event:ContextMenuEvent):void
        {
            var toolKey:String = ContextMenuItem(event.target).caption;
            switch (toolKey)
            {
                case "clearAction":
                    // 初期化します。
                    initialize();
                    break;
                case "undoAction":
                    // ワンストロークを取り消します。
                    _paint.undo();
                    break;
                case "redoAction":
                    // ワンストロークをやり直します。
                    _paint.redo();
                    break;
                case "replayAction":
                    // 最初からお絵描きを再生します。
                    _paint.replay(5.0);
                    break;
                case "saveAction":
                    // お絵描きしたキャンバスをローカルファイルに保存します。
                    _paint.save("paint.png");
                    break;
            }
        }
    }
}

その他のサンプル

as3paintoco(ぺいんとこ)を使って作成したお絵描きツールです。
現状は、UIを作成する手間がかかるので、今後、簡単に各種ツールボタンやオプション設定用のUIやスキンを作成することもぼんやりと考えております。

The Flash plugin is required to view this object.

まとめ

というわけで、今回は簡単な紹介でした。今後も、お絵描きライブラリのas3paintoco(ぺいんとこ)は開発を進めながら追加機能などを紹介していきます。

 

Comments: 4

Leave a reply »

 
 
 

お絵描きライブラリ!!

「ちょっぱや」押したら出たエラーのご報告でーす。

ArgumentError: Error #2005: パラメータ 0 の型が正しくありません。正しい型は Filter です。
at flash.display::DisplayObject/set filters()
at jp.wxd.as3paintoco.tools::LineTool/mouseDown()
at jp.wxd.as3paintoco.command::MouseDownCommand/execute()
at jp.wxd.as3paintoco.core::CanvasCore/mouseDown()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at jp.wxd.core.command::MethodCommand/execute()
at jp.wxd.core.command::QueueableMethodCommand/execute()
at jp.wxd.as3paintoco.command::ReplayQueue/_nextTimer_handleTimerComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()

 
 

おぉ、さっそくありがとうございます!

さきほど同じエラーが出て直したつもりなんですが
直ってなかったみたいですねぇ。。。

swfをあげ忘れていたかもなのでパブリッシュしなおして
更新してみましたがどうでしょう。

 
 

リプレイ時に、ツールのロックをし忘れていた
ので修正しました。

それに伴い、ライブラリ側も若干手を加えたので
http://as3paintoco.googlecode.com/files/as3paintoco_alpha3.swc
にバージョンアップしました。

 
 

I just want to tell you that your blog is very interesting, bookmarked

 
 
Leave a Reply
 
  (will not be published)