<?xml version="1.0" encoding="utf-8" ?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" 
			xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" 
			xmlns:cc="http://web.resource.org/cc/" xml:lang="ja">
<channel rdf:about="http://yamasv.blog92.fc2.com/?xml">
<title>miscellaneous</title>
<link>http://yamasv.blog92.fc2.com/</link>
<description></description>
<dc:language>ja</dc:language>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://yamasv.blog92.fc2.com/blog-entry-163.html" />
<rdf:li rdf:resource="http://yamasv.blog92.fc2.com/blog-entry-161.html" />
<rdf:li rdf:resource="http://yamasv.blog92.fc2.com/blog-entry-160.html" />
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://yamasv.blog92.fc2.com/blog-entry-163.html">
<link>http://yamasv.blog92.fc2.com/blog-entry-163.html</link>
<title>Subdivision Curves3, 4</title>
<description> 昨日のSubdivisonによる線の円滑化のリアルタイム版の制御点を増やしてみた。
赤い円をドラッグで移動するとリアルタイムに線も再計算されます。




次に制御点をランダムな方向に自動的に動かすようにしてみた。
線が幻想的な動きをするかと思ったらそうでもない(笑)。












package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils
 </description>
<content:encoded>
<![CDATA[ <a href="http://yamasv.blog92.fc2.com/blog-entry-161.html" target="_blank" title="以前投稿した">昨日</a>のSubdivisonによる線の円滑化のリアルタイム版の制御点を増やしてみた。<br/>
赤い円をドラッグで移動するとリアルタイムに線も再計算されます。
<br/>
<iframe src="http://blog-imgs-35.fc2.com/y/a/m/yamasv/sc3.swf"
width="500" height="500" marginwidth="0" marginheight="0" frameborder="0"   
scrolling="no"></iframe>
<br/>

次に制御点をランダムな方向に自動的に動かすようにしてみた。<br/>
線が幻想的な動きをするかと思ったらそうでもない(笑)。
<br/>
<iframe src="http://blog-imgs-35.fc2.com/y/a/m/yamasv/sc4.swf"
width="500" height="500" marginwidth="0" marginheight="0" frameborder="0"   
scrolling="no"></iframe>
<br/>


<br/>

<br/>

<pre>


package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import flash.ui.Keyboard;
    import flash.geom.*;
    import flash.filters.*;


    [SWF(width="500", height="500", frameRate="10", backgroundColor="#ffffff")]
        public class SubdivisionCurves3 extends Sprite{
            private var _balls:Array = [];
            private var _vertices:Array = [];

            public function SubdivisionCurves3():void
            {
                var points:Array = [];

                for(var j:int = 0 ; j < 12 ; j++){
                    var p:Point = new Point(Math.cos(Math.PI/6*j) * 100 + 200, Math.sin(Math.PI/6*j) * 100 + 100);
                    points.push(p);
                }

                for(var i:int = 0 ; i < points.length ; i++){
                    var b:Ball = new Ball(0xff0000, 10);
                    _balls.push(b);
                    addChild(b);
                    b.x = points[i].x;
                    b.y = points[i].y;

                    b.addEventListener( MouseEvent.MOUSE_DOWN, pickup );
                    b.addEventListener( MouseEvent.MOUSE_UP, place );
                    b.addEventListener( MouseEvent.MOUSE_MOVE, function(e:*):void{
                            //            calcVolume();
							initVertices();
							while(_vertices.length <= 100)
							subdivision();
                            });
                }

                initVertices();
				while(_vertices.length <= 100)
					subdivision();

            }

            private function initVertices():void{
                _vertices = [];
                for each (var b:Ball in _balls){
                    _vertices.push(new Point(b.x, b.y));
                }
                drawVertices();
            }

            private function pickup( event:MouseEvent ):void {
                event.target.startDrag( );
                event.target.filters = [ new DropShadowFilter( ) ];
                
                setChildIndex( DisplayObject( event.target ), numChildren - 1 );
            }

            private function place( event:MouseEvent ):void {
               
                event.target.stopDrag( );
                event.target.filters = null;

            }

            private function subdivisionFromTo(from:Point, to:Point):Array{
                var v1:Point = new Point(from.x + (to.x - from.x) * (1/4),
                        from.y + (to.y - from.y) * (1/4));
                var v2:Point = new Point(from.x + (to.x - from.x) * (3/4),
                        from.y + (to.y - from.y) * (3/4));

                return [v1, v2];

            }
            private function subdivision():void{
                trace(_vertices.length);
                if(_vertices.length > 100)
                    return;

                var newVertices:Array = [];
                var temp:Array;
                for (var i:int = 0 ; i < _vertices.length - 1 ; i++){
                    temp = subdivisionFromTo(_vertices[i], _vertices[i+1]);
                    newVertices = newVertices.concat(temp);
                }
                temp = subdivisionFromTo(_vertices[_vertices.length - 1], _vertices[0]);
                newVertices = newVertices.concat(temp);

                _vertices = newVertices.concat();

                drawVertices();
            }

            private function drawVertices():void{
                graphics.clear();
                graphics.lineStyle(4,0xff,0.5);

                graphics.moveTo(this._vertices[0].x, this._vertices[0].y);
                for (var i:int = 1  ; i < this._vertices.length ; i++){
                    graphics.lineTo(this._vertices[i].x, this._vertices[i].y);
                }
                graphics.lineTo(this._vertices[0].x, this._vertices[0].y);
            }

        }
}
import flash.display.*;

internal class Ball extends Sprite{
        public function Ball(color:int, radius:int){
                graphics.beginFill(color);
                graphics.drawCircle(0,0,radius);
                graphics.endFill();
        }
}

</pre>

<pre>
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import flash.ui.Keyboard;
    import flash.geom.*;
    import flash.filters.*;


    [SWF(width="500", height="500", frameRate="10", backgroundColor="#ffffff")]
        public class SubdivisionCurves4 extends Sprite{
            private var _balls:Array = [];
            private var _vertices:Array = [];

            public function SubdivisionCurves4():void
            {
                var points:Array = [];

                for(var j:int = 0 ; j < 12 ; j++){
                    var p:Point = new Point(Math.cos(Math.PI/6*j) * 100 + 200, Math.sin(Math.PI/6*j) * 100 + 100);
                    points.push(p);
                }

                for(var i:int = 0 ; i < points.length ; i++){
                    var b:Ball = new Ball(0xff0000, 10);
                    _balls.push(b);
                    addChild(b);
                    b.x = points[i].x;
                    b.y = points[i].y;

                    b.addEventListener( MouseEvent.MOUSE_DOWN, pickup );
                    b.addEventListener( MouseEvent.MOUSE_UP, place );
                    b.addEventListener( MouseEvent.MOUSE_MOVE, function(e:*):void{
                            //            calcVolume();
							initVertices();
							while(_vertices.length <= 100)
							subdivision();
                            });
                }

                initVertices();
				while(_vertices.length <= 100)
					subdivision();

                addEventListener(Event.ENTER_FRAME, loop);

            }

            private function loop(event:*):void{
                for each (var b:Ball in _balls){
                    b.move();
                }
                initVertices();
				while(_vertices.length <= 100)
					subdivision();
            }

            private function initVertices():void{
                _vertices = [];
                for each (var b:Ball in _balls){
                    _vertices.push(new Point(b.x, b.y));
                }
                drawVertices();
            }

            private function pickup( event:MouseEvent ):void {
                event.target.startDrag( );
                event.target.filters = [ new DropShadowFilter( ) ];
                
                setChildIndex( DisplayObject( event.target ), numChildren - 1 );
            }

            private function place( event:MouseEvent ):void {
               
                event.target.stopDrag( );
                event.target.filters = null;

            }

            private function subdivisionFromTo(from:Point, to:Point):Array{
                var v1:Point = new Point(from.x + (to.x - from.x) * (1/4),
                        from.y + (to.y - from.y) * (1/4));
                var v2:Point = new Point(from.x + (to.x - from.x) * (3/4),
                        from.y + (to.y - from.y) * (3/4));

                return [v1, v2];

            }
            private function subdivision():void{
                trace(_vertices.length);
                if(_vertices.length > 100)
                    return;

                var newVertices:Array = [];
                var temp:Array;
                for (var i:int = 0 ; i < _vertices.length - 1 ; i++){
                    temp = subdivisionFromTo(_vertices[i], _vertices[i+1]);
                    newVertices = newVertices.concat(temp);
                }
                temp = subdivisionFromTo(_vertices[_vertices.length - 1], _vertices[0]);
                newVertices = newVertices.concat(temp);

                _vertices = newVertices.concat();

                drawVertices();
            }

            private function drawVertices():void{
                graphics.clear();
                graphics.lineStyle(10,0xff,0.5);

                graphics.moveTo(this._vertices[0].x, this._vertices[0].y);
                for (var i:int = 1  ; i < this._vertices.length ; i++){
                    graphics.lineTo(this._vertices[i].x, this._vertices[i].y);
                }
                graphics.lineTo(this._vertices[0].x, this._vertices[0].y);
            }

        }
}

import flash.display.*;
internal class Ball extends Sprite{
    public var vx:int = 5*Math.random();
    public var vy:int = 5*Math.random();
    public var radius:int;
    public var currentColor:int;
    public function Ball(c:Number=0, radius:Number = 0){
        graphics.lineStyle(1, 0, 0.5);
        graphics.beginFill(c);
        graphics.drawCircle(0,0,radius);
        graphics.endFill();
        this.radius = radius;
        this.alpha = 0.1;
    }

    public function set color(c:int):void{
        if(currentColor != c){
            currentColor = c;
            graphics.clear();
            graphics.lineStyle(1, 0, 0.5);
            graphics.beginFill(currentColor);
            graphics.drawCircle(0,0,radius);
            graphics.endFill();
        }
    }

    public function move():void{
        x += vx;
        y += vy;
        if(x < 0 || x > 500)
            vx *= -1;
        if(y < 0 || y > 500)
            vy *= -1;
    }
}

</pre> ]]>
</content:encoded>
<dc:subject>ActionScript 3.0</dc:subject>
<dc:date>2009-11-24T10:29:57+09:00</dc:date>
<dc:creator>yamasv@gmail.com</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://yamasv.blog92.fc2.com/blog-entry-161.html">
<link>http://yamasv.blog92.fc2.com/blog-entry-161.html</link>
<title>Subdivision Curves 2</title>
<description> 以前投稿したSubdivisonによる線の円滑化のリアルタイム版。
赤い円をドラッグで移動するとリアルタイムに線も再計算されます。













package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import flash.ui.Keyboard;
    import flash.geom.*;
    import flash.filters.*;


    [SWF(width=&quot;500&quot;, height=&quot;500&quot;, frame
 </description>
<content:encoded>
<![CDATA[ <a href="http://yamasv.blog92.fc2.com/blog-entry-151.html" target="_blank" title="以前投稿した">以前投稿した</a>Subdivisonによる線の円滑化のリアルタイム版。<br/>
赤い円をドラッグで移動するとリアルタイムに線も再計算されます。
<br/>
<iframe src="http://blog-imgs-35.fc2.com/y/a/m/yamasv/SubdivisionCurves2.swf"
width="500" height="500" marginwidth="0" marginheight="0" frameborder="0"   
scrolling="no"></iframe>
<br/>



<br/>

<br/>

<pre>


package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import flash.ui.Keyboard;
    import flash.geom.*;
    import flash.filters.*;


    [SWF(width="500", height="500", frameRate="10", backgroundColor="#ffffff")]
        public class SubdivisionCurves2 extends Sprite{
            private var _balls:Array = [];
            private var _vertices:Array = [];

            public function SubdivisionCurves2():void
            {
                var points:Array = [new Point(100, 200), new Point(20, 400)
                    , new Point(300, 400), new Point(400, 300) , new Point(300, 100)
                ];


                for(var i:int = 0 ; i < points.length ; i++){
                    var b:Ball = new Ball(0xff0000, 10);
                    _balls.push(b);
                    addChild(b);
                    b.x = points[i].x;
                    b.y = points[i].y;

                    b.addEventListener( MouseEvent.MOUSE_DOWN, pickup );
                    b.addEventListener( MouseEvent.MOUSE_UP, place );
                    b.addEventListener( MouseEvent.MOUSE_MOVE, function(e:*):void{
                            //            calcVolume();
							initVertices();
							while(_vertices.length <= 100)
							subdivision();
                            });
                }

                initVertices();
				while(_vertices.length <= 100)
					subdivision();

            }

            private function initVertices():void{
                _vertices = [];
                for each (var b:Ball in _balls){
                    _vertices.push(new Point(b.x, b.y));
                }
                drawVertices();
            }

            private function pickup( event:MouseEvent ):void {
                event.target.startDrag( );
                event.target.filters = [ new DropShadowFilter( ) ];
                
                setChildIndex( DisplayObject( event.target ), numChildren - 1 );
            }

            private function place( event:MouseEvent ):void {
               
                event.target.stopDrag( );
                event.target.filters = null;

            }

            private function subdivisionFromTo(from:Point, to:Point):Array{
                var v1:Point = new Point(from.x + (to.x - from.x) * (1/4),
                        from.y + (to.y - from.y) * (1/4));
                var v2:Point = new Point(from.x + (to.x - from.x) * (3/4),
                        from.y + (to.y - from.y) * (3/4));

                return [v1, v2];

            }
            private function subdivision():void{
                trace(_vertices.length);
                if(_vertices.length > 100)
                    return;

                var newVertices:Array = [];
                var temp:Array;
                for (var i:int = 0 ; i < _vertices.length - 1 ; i++){
                    temp = subdivisionFromTo(_vertices[i], _vertices[i+1]);
                    newVertices = newVertices.concat(temp);
                }
                temp = subdivisionFromTo(_vertices[_vertices.length - 1], _vertices[0]);
                newVertices = newVertices.concat(temp);

                _vertices = newVertices.concat();

                drawVertices();
            }

            private function drawVertices():void{
                graphics.clear();
                graphics.lineStyle(4,0xff,0.5);

                graphics.moveTo(this._vertices[0].x, this._vertices[0].y);
                for (var i:int = 1  ; i < this._vertices.length ; i++){
                    graphics.lineTo(this._vertices[i].x, this._vertices[i].y);
                }
                graphics.lineTo(this._vertices[0].x, this._vertices[0].y);
            }

        }
}
import flash.display.*;

internal class Ball extends Sprite{
        public function Ball(color:int, radius:int){
                graphics.beginFill(color);
                graphics.drawCircle(0,0,radius);
                graphics.endFill();
        }
}

</pre> ]]>
</content:encoded>
<dc:subject>ActionScript 3.0</dc:subject>
<dc:date>2009-11-23T20:11:57+09:00</dc:date>
<dc:creator>yamasv@gmail.com</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://yamasv.blog92.fc2.com/blog-entry-160.html">
<link>http://yamasv.blog92.fc2.com/blog-entry-160.html</link>
<title>確率</title>
<description> [問題]
二人の子供がいて、少なくとも片方は女の子だということがわかっている。
この時、二人とも女の子である確率はいくつか？





[答え]
二人の子をそれぞれA、Bとすると少なくとも片方は女の子なので、考えられるパターンとしては、
A=女の子、B=女の子
A=女の子、B=男の子
A=男の子、B=女の子
の３通り。
よって、両方女の子である確率は３分の１。
 </description>
<content:encoded>
<![CDATA[ [問題]<br/>
二人の子供がいて、少なくとも片方は女の子だということがわかっている。
この時、二人とも女の子である確率はいくつか？
<br/>
<br/>
<iframe src="http://rcm-jp.amazon.co.jp/e/cm?t=syamasswebpag-22&o=9&p=8&l=as1&asins=4478004528&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<br/>
<br/>
[答え]<br/>
二人の子をそれぞれA、Bとすると少なくとも片方は女の子なので、考えられるパターンとしては、<br/>
A=女の子、B=女の子<br/>
A=女の子、B=男の子<br/>
A=男の子、B=女の子<br/>
の３通り。
よって、両方女の子である確率は３分の１。
 ]]>
</content:encoded>
<dc:subject>未分類</dc:subject>
<dc:date>2009-11-23T18:47:08+09:00</dc:date>
<dc:creator>yamasv@gmail.com</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
</rdf:RDF>