In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

coding

コーディングをしているあにめーしょんです。
自分の使ったことある言語を載せました
Get Adobe Flash player
by about 15 Feb 2013
    Embed
/**
 * Copyright about ( http://wonderfl.net/user/about )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6owG
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    [SWF(width="465", height="465")]
    public class coding_animation extends Sprite
    {
        private var console_line:TextField = new TextField();
        private var line_command:Vector.<TextField> = new Vector.<TextField>; // source line
        private var command:Vector.<TextField> = new Vector.<TextField>; //console command 
        private var source_table:Sprite = new Sprite();
        private var coding_table:Sprite = new Sprite();
        private var Char:Array = new Array();
        private var line:TextField = new TextField();
        private var commandline:TextField = new TextField();
        private var command_type:Number = 21; //出力コマンドの数
        private var lang_type:Number = 11;  //ソースの数(種類)
        private var user_name:String = "no_name :";
        private var user_name_table:Sprite = new Sprite();
        private var user_line:TextField = new TextField();
        private var cursor_table:Sprite = new Sprite();
        private var cursor:TextField = new TextField();
        private var cnt:Number = 0;
        private var line_cnt:Number = 0; //現在のコマンドライン配列の参照index
        private var lang_cnt:Number = 0; //現在のソースの参照index
        private var cx:Number = 0;
        private var cy:Number = 315;
        private var percent:Number;
        private var percent_text:TextField = new TextField();
        private var personal_percent:Vector.<Number> = new Vector.<Number>;
        private var lang_out_cnt:Vector.<Number> = new Vector.<Number>;
        private var tmp:TextField = new TextField();
        private var Length:Number;
        private var commandline_overcnt:Number = 0; //コマンドラインでのページ送りのカウンター 10以上はページ送り
        private var command_line_cnt:Number = 0; //現在のコマンドの量
        private var now_cnt:Number = 0;
        private var cursor_bool:Boolean = false;
        
        //source_command
        private var source_command:Vector.<TextField> = new Vector.<TextField>;
        
        public function coding_animation()
        {
            User_name();
            //background
            graphics.beginFill(0x000000);
            graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
            graphics.endFill();
            
            //console line
            console_line.defaultTextFormat = new TextFormat("",20,0xffffff,true);
            console_line.autoSize = TextFieldAutoSize.LEFT;
            console_line.text = "---------------------------------------------------------------------";
            console_line.x = 0;
            console_line.y = 300;
            addChild(console_line);
            
            //cursor
            cursor.text = "_";
            
            //text_style
            line.defaultTextFormat = new TextFormat("",13,0xffffff,false);
            commandline.defaultTextFormat = new TextFormat("",14,0xffffff,false);
            percent_text.defaultTextFormat = new TextFormat("",14,0xffffff,false);
            line.autoSize = TextFieldAutoSize.LEFT; 
            commandline.autoSize = TextFieldAutoSize.LEFT;
            percent_text.autoSize = TextFieldAutoSize.LEFT;
            percent_text.x = 300;
            percent_text.y = 290;
            tmp.autoSize = TextFieldAutoSize.LEFT;
            tmp.defaultTextFormat = new TextFormat("",13,0xff4500,false);
            
            // %
            var p:TextField = new TextField();
            p.defaultTextFormat = new TextFormat("",14,0xffffff,true);
            p.text = "%";
            p.x = 430;
            p.y = 290;
            addChild(p);
            
            //コマンド生成
            for(var i:int=0;i<command_type;i++) command.push(new TextField);
            command[0].text  = "g++ Hello.cpp"; //C++
            command[1].text  = "./a.out"; 
            command[2].text  = "Hello World!";
            command[3].text  = "javac Hello.java"; //Java
            command[4].text  = "java Hello";
            command[5].text  = "Hello World!";
            command[6].text  = "csc Hello.cs"; //C#
            command[7].text  = "a.exe";
            command[8].text  = "Hello World!";
            command[9].text = "rdmd Hello.d"; //D
            command[10].text = "Hello World!";
            command[11].text  = "php Hello.php"; //PHP
            command[12].text = "Hello World!";
            command[13].text = "ruby Hello.rb"; //Ruby
            command[14].text = "Hello World!";
            command[15].text = "python Hello.py"; //Python v3
            command[16].text = "Hello World!";
            command[17].text = "brainfuck Hello.bf"; //BrainF*ck
            command[18].text = "Hello World!";
            command[19].text = "whitespace Hello.ws"; //WhiteSpace
            command[20].text = "Hello World!";
            
            //source生成  //tab = 4 spaces
            for(i=0;i<lang_type;i++) line_command.push(new TextField);
            line_command[0].text = "// Hello.cpp(C++)\n\n#include <iostream>\n\nint main(void){\n    std :: cout << \"Hello World!\" << std :: endl;\n    return 0;\n}";
            line_command[1].text = "// Hello.java(Java)\n\npublic class Hello{\n    public static void main (String [] args){\n        System.out.println (\"Hello World!\") ;\n    }\n}";
            line_command[2].text = "// Hello.cs(C#)\n\nclass Hello{\n    static void Main(){\n        System.Console.WriteLine(\"Hello World!\");\n    }\n}";
            line_command[3].text = "// Hello.d(D)\n\nprivate import std.stdio;\n\nvoid main(){\n    writeln(\"Hello World!\");\n}";
            line_command[4].text = "// Hello.php(PHP)\n\n<?php\necho \"Hello World!\\n\";\n?>\n";
            line_command[5].text = "# Hello.rb(Ruby)\n\nputs \"Hello World!\"\n";
            line_command[6].text = "# Hello.py(Python)\n\nprint(\"Hello World!\")\n";
            line_command[7].text = "// Hello.bf(BrainF*ck)\n\n+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.\n-----------.<++++++++.--------.+++.------.--------.>+.\n";
            line_command[8].text = "Hello.ws(WhiteSpace)\n                \n    \n                        \n    \n                        \n    \n                        \n    \n                              \n    \n              \n    \n                           \n    \n                              \n    \n                        \n    \n                        \n    \n                     \n    \n                 \n    \n               \n    \n  \n";
            line_command[9].text = "finish";
            line_command[10].text = "Sentinel";
            
            //lang個別の出力コマンド個数
            lang_out_cnt[0] = 2; //C++
            lang_out_cnt[1] = 3; //Java
            lang_out_cnt[2] = 3; //C#
            lang_out_cnt[3] = 2; //D
            lang_out_cnt[4] = 2; //PHP
            lang_out_cnt[5] = 2; //Ruby
            lang_out_cnt[6] = 2; //Python
            lang_out_cnt[7] = 2; //BrainF*ck
            lang_out_cnt[8] = 2; //Whitespace
            
            //コマンド開始ポイント
            commandline.x = 80;
            commandline.y = 315;
            
            addEventListener(Event.ENTER_FRAME,onEnterFrame);
            addChild(coding_table);
            coding_table.addChild(line);
            addChild(commandline);
            addChild(user_name_table);
            addChild(user_line);
            addChild(cursor_table);
            cursor_table.addChild(cursor);
            
            //それぞれのコードの1文字分の%を計算
            for(i=0;i<lang_type;i++){
                personal_percent.push(100/line_command[i].text.length);
            }
            addChild(percent_text);
        }
        
        private function onEnterFrame(e:Event):void{
            //percent表示
            percent = (line_cnt+1) * personal_percent[lang_cnt]; 
            if(percent == Infinity) percent_text.text = "0";
            else percent_text.text = (String)(percent);
            var now_char:String =  line_command[lang_cnt].text.charAt(line_cnt);
            if(lang_cnt == lang_type -1) removeEventListener(Event.ENTER_FRAME,onEnterFrame);
            //改行判断
            if(now_char == "\r"){
                if(line.height >= 300 - 10){ //10は適当数
                    var index_line:Number = commandline.text.indexOf("\r"); //改行での分割
                    var tmp_line:String = commandline.text;
                    line.text = line.text.substr(index_line+1);
                    cursor.y = 295;
                    cursor_bool = true;
                }
                tmp.text = "";
                cursor.x = 0;
//                cursor.y += 16; //font size 14
                if(!cursor_bool) cursor.y += 14; //font size 13
            }
            
            line.text += now_char;
            tmp.text  += now_char;
            Length = tmp.width;
            cursor_fun();
            if(line_cnt == line_command[lang_cnt].text.length -1 ){
                cnt = 0;
                line_cnt = -1;
                removeEventListener(Event.ENTER_FRAME,onEnterFrame);
                addEventListener(Event.ENTER_FRAME,onEnterFrame2);
                line_cnt = -1;
                line.text +="\n";
            }
            line_cnt++;
        }
        
        private function onEnterFrame2(e:Event):void{
            var index:Number = command_line_cnt;
            if(lang_cnt == lang_type - 1 || index >= command_type ){ //finish
                return; //exit
            }
            commandline.text += command[index].text.charAt(line_cnt); 
            if(line_cnt == command[index].text.length){
                commandline_overcnt++; // コマンドラインでのページ送りカウント
                //ページ送り
                if(commandline_overcnt >= 10){
                    var index_command:Number = commandline.text.indexOf("\r"); //改行での分割
                    var tmp_string:String = commandline.text;
                    commandline.text = commandline.text.substr(index_command+1);
                }
                if(command_line_cnt ==now_cnt +lang_out_cnt[lang_cnt]){
                    now_cnt += lang_out_cnt[lang_cnt];
                    removeEventListener(Event.ENTER_FRAME,onEnterFrame2);
                    lang_cnt++;
                    line.text = "";
                    percent = 0;
                    cursor.x = 0;
                    cursor.y = 0;
                    addEventListener(Event.ENTER_FRAME,cursor_fun);
                    addEventListener(Event.ENTER_FRAME,onEnterFrame);
                }
                cnt++;
                command_line_cnt++;
                line_cnt = -1;
                commandline.text +="\n";
                User_name();
            }
            line_cnt++;
        }
        
        //username     
        private function User_name():void{
            user_line.defaultTextFormat = new TextFormat("",14,0xffffff,false);
            user_line.autoSize = TextFieldAutoSize.LEFT;
            user_line.text += user_name;
            user_line.x = cx;
            user_line.y = cy;
            user_line.text += "\n";
        }
        
        //cursor
        private function cursor_fun(e:Event=null):void{
            cursor.x = Length;
            cursor.textColor = 0xf08080;
        }
    }
}