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

Distance shown on alpha

A well-practiced method, showing the distances between points with the transparency of the lines connecting them.

点を結ぶ線の透明さで点と点の距離を表します。よく使われる手法ですが。

そういえば、サカナクションニューシングル「ミュージック」23日発売ですよ!
Get Adobe Flash player
by GreekFellows 21 Jan 2013
/**
 * Copyright GreekFellows ( http://wonderfl.net/user/GreekFellows )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/n6Q3
 */

package {
    import flash.geom.Point;
    import flash.events.Event;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    
    public class Partickles extends Sprite {
        public var partickles:Array;
        
        public function Partickles() {
            partickles = [];
            
            stage.quality = "low";
            
            for (var ci:int = 0; ci < 100; ci++) {
                partickles.push(
                                {
                                    x:465 / 2,
                                    y:465 / 2,
                                    ax:(Math.random() * 100 - 50) / 100,
                                    ay:(Math.random() * 100 - 50) / 100
                                }
                                );
            }
            
            this.addEventListener(Event.ENTER_FRAME, murmur);
        }
        
        public function murmur(e:Event):void {
            this.graphics.clear();
            
            for (var pi:int = 0; pi < partickles.length; pi++) {
                var cp:Object = partickles[pi];
                
                for (var ppi:int = 0; ppi < partickles.length; ppi++) {
                    if (ppi != pi) {
                        var cpp:Object = partickles[ppi];
                        var distance:Number = Point.distance(new Point(cp.x, cp.y), new Point(cpp.x, cpp.y));
                        
                        if (distance < mouseX / 5) {
                            this.graphics.lineStyle(1, 0, 1 - distance / (mouseX / 5));
                            this.graphics.moveTo(cp.x, cp.y);
                            this.graphics.lineTo(cpp.x, cpp.y);
                            
                            // this.graphics.lineStyle(1, 0, (1 - distance / (mouseX / 5)) / 2);
                            // this.graphics.drawCircle(cp.x + (cpp.x - cp.x) / 2, cp.y + (cpp.y - cp.y) / 2, distance / 2);
                        }
                    }
                }
                
                cp.x += cp.ax;
                cp.y += cp.ay;
                
                cp.ax += (Math.random() * 100 - 50) / 100;
                cp.ay += (Math.random() * 100 - 50) / 100;
                
                if (cp.x > 465) {
                    cp.x = 465;
                    cp.ax = -Math.abs(cp.ax);
                }
                if (cp.x < 0) {
                    cp.x < 0;
                    cp.ax = Math.abs(cp.ax);
                }
                if (cp.y > 465) {
                    cp.y = 465;
                    cp.ay = -Math.abs(cp.ay);
                }
                if (cp.y < 0) {
                    cp.y < 0;
                    cp.ay = Math.abs(cp.ay);
                }
                
                if (Math.abs(cp.ax) > 10) {
                    cp.ax *= .25;
                }
                if (Math.abs(cp.ay) > 10) {
                    cp.ay *= .25;
                }
            }
        }
        
        public function isInsideTriangle(ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number, px:Number, py:Number):Boolean {
            var planeAB:Number = (ax - px) * (by - py) - (bx - px) * (ay - py);
            var planeBC:Number = (bx - px) * (cy - py) - (cx - px) * (by - py);
            var planeCA:Number = (cx - px) * (ay - py) - (ax - px) * (cy - py);
            
            return sign(planeAB)==sign(planeBC) && sign(planeBC)==sign(planeCA);
        }
        
        public function sign(n:Number):int {
            return Math.abs(n)/n;
        }
    }
}