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

おっぱいスライダー - Breast Slider -

商標登録されてたらどうしよう
/**
 * Copyright 9balls ( http://wonderfl.net/user/9balls )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cuyJ
 */

package {
    import com.adobe.utils.AGALMiniAssembler;
    import com.bit101.components.ColorChooser;
    import com.bit101.components.HUISlider;
    import com.bit101.components.Label;
    import com.bit101.components.NumericStepper;
    import com.bit101.components.Panel;
    import com.bit101.components.RadioButton;
    import com.bit101.components.Window;
    import flash.display.Sprite;
    import flash.display.Stage3D;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display3D.Context3D;
    import flash.display3D.Context3DProgramType;
    import flash.display3D.Context3DRenderMode;
    import flash.display3D.Context3DTriangleFace;
    import flash.display3D.Context3DVertexBufferFormat;
    import flash.display3D.IndexBuffer3D;
    import flash.display3D.Program3D;
    import flash.display3D.VertexBuffer3D;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.ByteArray;
    import net.hires.debug.Stats;

    /**
     * ...
     * @author
     */
    public class Main extends Sprite {

        private const BUST_X:Number = 1;
        private const BUST_Y:Number = 0;
        private const BUST_RADIUS:Number = 1;
        private const BUST_HEIGHT:Number = 6;
        private const NIPPLE_X:Number = 1;
        private const NIPPLE_Y:Number = 0;
        private const NIPPLE_RADIUS:Number = Math.exp(11);
        private const NIPPLE_HEIGHT:Number = 2 / 3;
        private const NIPPLE_THRESHOLD:Number = 0.1; //color threshold
        //
        private var bustParam:Vector.<Number> = Vector.<Number>([BUST_X, BUST_Y, -BUST_RADIUS, BUST_HEIGHT]);
        private var bustColor:Vector.<Number> = Vector.<Number>([0xff / 255.0, 0xcc / 255.0, 0x99 / 255.0, 8]);
        private var nippleParam:Vector.<Number> = Vector.<Number>([NIPPLE_X, NIPPLE_Y, -NIPPLE_RADIUS, NIPPLE_HEIGHT]);
        private var nippleColor:Vector.<Number> = Vector.<Number>([0xee / 255.0, 0x8e / 255.0, 0xa0 / 255.0, NIPPLE_THRESHOLD]);
        //
        private const NUM_PARTICLES:uint = 16383;
        private const MAX_BUFFERS:uint = 50;
        private const P_SIZE:Number = 0.5 * 0.01;
        private const WIDTH:uint = 466;
        private const HEIGHT:uint = 466;
        private const RAD:Number = Math.PI / 180;
        //
        private var stage3D:Stage3D;
        private var context3D:Context3D;
        //
        private var camera:SimpleCamera3D;
        private var particleProgram:Program3D;
        private var vBufferXYs:Vector.<VertexBuffer3D>;
        private var vBufferOffset:VertexBuffer3D;
        private var iBuffer:IndexBuffer3D;
        private var numBuffers:uint = 20;
        //
        private var tfP:TextField;
        private var dummy:Sprite;
        //ui
        private var window:Window;
        private var panelB:Panel;
        private var bustC:ColorChooser;
        private var bustX:HUISlider;
        private var bustY:HUISlider;
        private var bustR:HUISlider;
        private var bustH:HUISlider;
        private var panelN:Panel;
        private var nippleC:ColorChooser;
        private var nippleX:HUISlider;
        private var nippleY:HUISlider;
        private var nippleR:HUISlider;
        private var nippleH:HUISlider;
        


        public function Main():void {
            Wonderfl.disable_capture();
            stage.frameRate = 60;
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            addChild(new Stats());
            //
            dummy = new Sprite();
            dummy.graphics.beginFill(0, 0);
            dummy.graphics.drawRect(0, 0, WIDTH, HEIGHT);
            dummy.graphics.endFill();
            addChild(dummy);
            //set ui
            var tfB:TextField = new TextField();
            tfB.autoSize = TextFieldAutoSize.LEFT;
            tfB.textColor = 0xffffff;
            tfB.text = "Buffer : ";
            tfB.x = 100;
            addChild(tfB);
            var stepper:NumericStepper = new NumericStepper(this, 150, 0, onStepper);
            stepper.minimum = 1;
            stepper.maximum = MAX_BUFFERS;
            stepper.value = numBuffers;
            stepper.width = 60;
            tfP = new TextField();
            tfP.autoSize = TextFieldAutoSize.LEFT;
            tfP.textColor = 0xffffff;
            tfP.text = "Particle : " + NUM_PARTICLES;
            tfP.x = 250;
            addChild(tfP);
            ////menu
            window = new Window(this, 0, 0, "menu");
            window.hasMinimizeButton = true;
            window.setSize(200, 150);
            new RadioButton(window.content, 10, 4, "BUST", true, onRadio);
            new RadioButton(window.content, 100, 4, "NIPPLE", false, onRadio);
            //
            panelB = new Panel(window.content, 0, 20);
            panelB.setSize(200, 110);
            panelB.shadow = false;
            new Label(panelB.content, 4, 2, "color :");
            bustC = new ColorChooser(panelB.content, 40, 4, 0xffcc99, onBust);
            bustC.usePopup = true;
            bustX = new HUISlider(panelB.content, 4, 24, "x :", onBust);
            bustX.setSliderParams(0.5, 2, 1);
            bustY = new HUISlider(panelB.content, 4, 44, "y :", onBust);
            bustY.setSliderParams(-0.5, 0.5, 0);
            bustR = new HUISlider(panelB.content, 4, 64, "radius :", onBust);
            bustR.setSliderParams(0, 2, 1);
            bustH = new HUISlider(panelB.content, 4, 84, "height :", onBust);
            bustH.setSliderParams(0.5, 4, 1);
            //
            panelN = new Panel(null, 0, 20);
            panelN.setSize(200, 110);
            panelN.shadow = false;
            new Label(panelN.content, 4, 2, "color :");
            nippleC = new ColorChooser(panelN.content, 40, 4, 0xee8ea0, onNipple);
            nippleC.usePopup = true;
            nippleX = new HUISlider(panelN.content, 4, 24, "x :", onNipple);
            nippleX.setSliderParams(0.5, 1.5, 1);
            nippleY = new HUISlider(panelN.content, 4, 44, "y :", onNipple);
            nippleY.setSliderParams(-0.5, 0.5, 0);
            nippleR = new HUISlider(panelN.content, 4, 64, "radius :", onNipple);
            nippleR.setSliderParams(0, 2, 1);
            nippleH = new HUISlider(panelN.content, 4, 84, "height :", onNipple);
            nippleH.setSliderParams(0, 4, 1);
            //
            stage3D = stage.stage3Ds[0];
            stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
            stage3D.requestContext3D(Context3DRenderMode.AUTO);
        }

        private function onRadio(e:Event):void {
            var str:String = (e.currentTarget as RadioButton).label;
            if (str == "BUST"){
                window.content.addChild(panelB);
            } else {
                window.content.addChild(panelN);
            }
        }

        private function onBust(e:Event):void {
            bustParam[0] = bustX.value;
            bustParam[1] = bustY.value;
            bustParam[2] = -BUST_RADIUS / Math.pow(bustR.value, 2);
            bustParam[3] = BUST_HEIGHT * bustH.value;
            var color:uint = bustC.value;
            bustColor[0] = (color >> 16 & 0xFF) / 255;
            bustColor[1] = (color >> 8 & 0xFF) / 255;
            bustColor[2] = (color & 0xFF) / 255;
        }

        private function onNipple(e:Event):void {
            nippleParam[0] = nippleX.value;
            nippleParam[1] = nippleY.value;
            nippleParam[2] = -NIPPLE_RADIUS / Math.pow(nippleR.value, 6);
            nippleParam[3] = NIPPLE_HEIGHT * nippleH.value;
            var color:uint = nippleC.value;
            nippleColor[0] = (color >> 16 & 0xFF) / 255;
            nippleColor[1] = (color >> 8 & 0xFF) / 255;
            nippleColor[2] = (color & 0xFF) / 255;
        }

        private function onStepper(e:Event):void {
            numBuffers = (e.currentTarget as NumericStepper).value;
            tfP.text = "Particle : " + NUM_PARTICLES * numBuffers;
        }

        private function onContextCreate(e:Event):void {
            context3D = stage3D.context3D;
            //context3D.enableErrorChecking = true;
            context3D.configureBackBuffer(WIDTH, HEIGHT, 0, true);
            context3D.setCulling(Context3DTriangleFace.BACK);
            //
            camera = new SimpleCamera3D(45 * RAD, 1, 0.1, 3000);
            new RoundCameraController(camera, dummy);
            createBuffer();
            createShader();
            context3D.setProgram(particleProgram);
            context3D.setVertexBufferAt(2, vBufferOffset, 0, Context3DVertexBufferFormat.FLOAT_2);
            context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 4, Vector.<Number>([2 / 3, 1 / 2, 3, 1 / 3])); //const1
            context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 5, Vector.<Number>([Math.E, 4, 1 / 8, 1.0])); //const2
            //
            addEventListener(Event.ENTER_FRAME, onEnter);
        }

        private function onEnter(e:Event):void {
            context3D.clear();
            context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, camera.cameraMtx, true);
            context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 6, bustParam); //bust
            context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 7, nippleParam); //nipple
            context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 8, bustColor); //bust color
            context3D.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 9, nippleColor); //nipple color
            for (var i:int = 0; i < numBuffers; i++){
                context3D.setVertexBufferAt(0, vBufferXYs[i], 0, Context3DVertexBufferFormat.FLOAT_2);
                context3D.drawTriangles(iBuffer);
            }
            context3D.present();
        }

        private function createShader():void {
            var agalAssembler:AGALMiniAssembler = new AGALMiniAssembler();
            ////Particle
            var code:String = "";
            //prepare
            code += "mov vt0, va0\n";
            code += "mul vt0.xy, vt0.xy, vc4.x\n"; //vt0.xy*=2/3
            code += "abs vt0.x, vt0.x\n"; //vt0.x=|vt0.x|
            //bust = (x23abs - BUST_X) * (x23abs - BUST_X) + (y23 - BUST_Y) * (y23 - BUST_Y);
            code += "mov vt1, vt0\n"; //vt1=vt0
            code += "sub vt1.xy, vt1.xy, vc6.xy\n"; //vt1.xy-=BUST.xy
            code += "dp3 vt1.x, vt1, vt1\n"; //vt1.x=bust
            code += "mul vt1.x, vt1.x, vc6.z\n"; //vt1.x*=-BUST_RADIUS
            code += "add vt1.y, vt0.y, vc4.y\n"; //vt1.y+=y23+1/2
            code += "pow vt1.y, vt0.y, vc4.z\n"; //vt1.y=Math.pow(y23 + C12, 3)
            code += "mul vt1.y, vt1.y, vc4.w\n"; //vt1.x*=1/3
            code += "sub vt1.x, vt1.x, vt1.y\n"; //vt1.x=-BUST_RADIUS * bust - C13 * Math.pow(y23 + C12, 3)
            code += "pow vt1.x, vc5.x, vt1.x\n"; //vt1.x=exp(vt1.x)
            code += "mul vt1.x, vt1.x, vc6.w\n"; //vt1.x*=BUST_HEIGHT
            //nipple = (x23abs - NIPPLE_X) * (x23abs - NIPPLE_X) + (y23 - NIPPLE_Y) * (y23 - NIPPLE_Y);
            code += "mov vt2, vt0\n"; //vt2=vt0
            code += "sub vt2.xy, vt2.xy, vc7.xy\n"; //vt2.xy-=NIPPLE.xy
            code += "dp3 vt2.x, vt2, vt2\n"; //vt2.x=nipple
            code += "mul vt2.x, vt2.x, vt2.x\n"; //vt2.x*=nipple*nipple
            code += "mul vt1.y, vt2.x, vc7.z\n"; //vt1.y=-NIPPLE_RADIUS * nipple * nipple
            code += "pow vt1.y, vc5.x, vt1.y\n"; //vt1.y=exp(vt1.y)
            code += "mov vt2.x, vt1.y\n"; ////////////////////////////vt1.z=exp(-NIPPLE_RADIUS * nipple * nipple)
            code += "mul vt1.y, vt1.y, vc7.w\n"; //vt1.x*=NIPPLE_HEIGHT
            //add
            code += "add vt0.z, vt1.x, vt1.y\n"; //vt0.z=bust'+nipple'
            code += "add vt0.z, vt0.z, vt0.y\n"; //vt0.z+=y23
            code += "pow vt1.w, vt0.x, vc5.y\n"; //vt1.w=Math.pow(x23abs, 4)
            code += "sub vt0.z, vt0.z, vt1.w\n"; //vt0.z-=Math.pow(x23abs, 4)
            code += "mul vt0.z, vt0.z, vc5.z\n"; //vt0.z*=1/8
            code += "mov vt0.xy, va0.xy\n";
            //screen
            code += "m44 vt0, vt0, vc0\n";
            code += "mul vt1, vt0.w, va2\n";
            code += "add vt0, vt0, vt1\n";
            code += "mov op, vt0\n";
            //color
            code += "sge vt2.x, vt2.x, vc9.w\n"; // vt2.x>=vc9.w?1:0
            code += "add vt2.x, vt2.x, vc8.w\n"; // vt2.x>=vc9.w?9:8
            code += "mov v0, vc[vt2.x]\n"; //v0=vc[vt2.x]...vc9 or vc8
            var vertexShader:ByteArray = agalAssembler.assemble(Context3DProgramType.VERTEX, code);
            var fragmentShader:ByteArray = agalAssembler.assemble(Context3DProgramType.FRAGMENT, "mov oc v0\n");
            particleProgram = context3D.createProgram();
            particleProgram.upload(vertexShader, fragmentShader);
            context3D.setProgram(particleProgram);
        }

        private function createBuffer():void {
            ////Particle
            var numVertices:uint = NUM_PARTICLES * 4;
            var numIndices:uint = NUM_PARTICLES * 6;
            //hs,rgb
            vBufferXYs = new Vector.<VertexBuffer3D>(MAX_BUFFERS);
            var index:uint;
            var pos:Vector.<Number> = new Vector.<Number>(NUM_PARTICLES * 4 * 2);
            var posX:Number;
            var posY:Number;
            for (var j:int = 0; j < MAX_BUFFERS; j++){
                vBufferXYs[j] = context3D.createVertexBuffer(numVertices, 2);
                index = 0;
                for (var i:int = 0; i < NUM_PARTICLES; i++){
                    posX = (Math.random() - 0.5) * 6;
                    posY = (Math.random() - 0.5) * 4;
                    pos[index++] = posX;
                    pos[index++] = posY;
                    pos[index++] = posX;
                    pos[index++] = posY;
                    pos[index++] = posX;
                    pos[index++] = posY;
                    pos[index++] = posX;
                    pos[index++] = posY;
                }
                vBufferXYs[j].uploadFromVector(pos, 0, numVertices);
            }
            //offset
            vBufferOffset = context3D.createVertexBuffer(numVertices, 2);
            var offsetVec:Vector.<Number> = new Vector.<Number>(numVertices * 2);
            index = 0;
            for (i = 0; i < NUM_PARTICLES; i++){
                offsetVec[index++] = -P_SIZE;
                offsetVec[index++] = -P_SIZE;
                offsetVec[index++] = -P_SIZE;
                offsetVec[index++] = P_SIZE;
                offsetVec[index++] = P_SIZE;
                offsetVec[index++] = -P_SIZE;
                offsetVec[index++] = P_SIZE;
                offsetVec[index++] = P_SIZE;
            }
            vBufferOffset.uploadFromVector(offsetVec, 0, numVertices);
            context3D.setVertexBufferAt(2, vBufferOffset, 0, Context3DVertexBufferFormat.FLOAT_2);
            //index buffer
            iBuffer = context3D.createIndexBuffer(numIndices);
            var iVec:Vector.<uint> = new Vector.<uint>(numIndices);
            index = 0;
            var p:uint;
            for (i = 0; i < NUM_PARTICLES; i++){
                p = i << 2;
                iVec[index++] = p;
                iVec[index++] = p + 1;
                iVec[index++] = p + 2;
                iVec[index++] = p + 2;
                iVec[index++] = p + 1;
                iVec[index++] = p + 3;
            }
            iBuffer.uploadFromVector(iVec, 0, numIndices);
        }

    }
}

import com.adobe.utils.PerspectiveMatrix3D;
import flash.display.InteractiveObject;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
import flash.ui.Keyboard;

//////////////////////////////////////////////////
// SimpleCamera3D
//////////////////////////////////////////////////
class SimpleCamera3D extends Object {

    private const RAD:Number = Math.random() / 180;
    private const DIRECTION:Vector3D = new Vector3D(0, 0, 1);
    //
    private var _cameraUP:Vector3D = new Vector3D(0, 1, 0);
    private var _direction:Vector3D = DIRECTION.clone();
    //
    private var _projectionMtx:PerspectiveMatrix3D = new PerspectiveMatrix3D();
    private var _cameraMtx:Matrix3D = new Matrix3D();
    private var _rotationMtx:Matrix3D = new Matrix3D();
    //
    public var x:Number = 0;
    public var y:Number = 0;
    public var z:Number = 0;

    public function SimpleCamera3D(fov:Number, aspect:Number, zNear:Number, zFar:Number):void {
        _projectionMtx.perspectiveFieldOfViewLH(fov, aspect, zNear, zFar);
    }

    public function get cameraMtx():Matrix3D {
        var forwardX:Number = _direction.x;
        var forwardY:Number = _direction.y;
        var forwardZ:Number = _direction.z;
        var rightX:Number = _cameraUP.y * forwardZ - _cameraUP.z * forwardY;
        var rightY:Number = _cameraUP.z * forwardX - _cameraUP.x * forwardZ;
        var rightZ:Number = _cameraUP.x * forwardY - _cameraUP.y * forwardX;
        var distance:Number = Math.sqrt(rightX * rightX + rightY * rightY + rightZ * rightZ);
        rightX /= distance;
        rightY /= distance;
        rightZ /= distance;
        var upX:Number = forwardY * rightZ - forwardZ * rightY;
        var upY:Number = forwardZ * rightX - forwardX * rightZ;
        var upZ:Number = forwardX * rightY - forwardY * rightX;
        var right:Number = rightX * x + rightY * y + rightZ * z;
        var up:Number = upX * x + upY * y + upZ * z;
        var forward:Number = forwardX * x + forwardY * y + forwardZ * z;
        _cameraMtx.rawData = Vector.<Number>([rightX, upX, forwardX, 0, rightY, upY, forwardY, 0, rightZ, upZ, forwardZ, 0, -right, -up, -forward, 1]);
        _cameraMtx.append(_projectionMtx);
        return _cameraMtx;
    }

    public function lookAt(point:Vector3D):void {
        _direction.x = point.x - x;
        _direction.y = point.y - y;
        _direction.z = point.z - z;
        _direction.normalize();
    }

}

//////////////////////////////////////////////////
// RoundCameraController
//////////////////////////////////////////////////
class RoundCameraController extends Object {

    private var _camera:SimpleCamera3D;
    private var _stage:InteractiveObject;
    private var _target:Vector3D;
    public var radiusOffset:Number = 0.1;
    //
    private const RAD:Number = Math.PI / 180;
    //
    public var isMouseDown:Boolean;
    private var _radius:Number = 4;
    private var _theta:Number = 0;
    private var _oldX:Number = 0;
    private var _phi:Number = 90;
    private var _oldY:Number = 0;

    public function RoundCameraController(camera:SimpleCamera3D, stage:InteractiveObject){
        _camera = camera;
        _stage = stage;
        _target = new Vector3D();
        enable();
        _upDateCamera();
    }

    public function enable():void {
        _stage.stage.addEventListener(KeyboardEvent.KEY_DOWN, _keyHandler);
        _stage.stage.addEventListener(MouseEvent.MOUSE_UP, _upHandler);
        _stage.addEventListener(MouseEvent.MOUSE_DOWN, _downHandler);
        _stage.addEventListener(MouseEvent.MOUSE_MOVE, _moveHandler);
        _stage.addEventListener(MouseEvent.MOUSE_WHEEL, _wheelHandler);
    }

    //
    private function _keyHandler(e:KeyboardEvent):void {
        switch (e.keyCode){
            case Keyboard.UP:
                _radius -= radiusOffset;
                if (_radius < 0.1){
                    _radius = 0.1;
                }
                _upDateCamera();
                break;
            case Keyboard.DOWN:
                _radius += radiusOffset;
                _upDateCamera();
                break;
            default:
                break;
        }
    }

    private function _upHandler(e:MouseEvent):void {
        isMouseDown = false;
    }

    private function _downHandler(e:MouseEvent):void {
        isMouseDown = true;
        _oldX = _stage.mouseX;
        _oldY = _stage.mouseY;
    }

    private function _wheelHandler(e:MouseEvent):void {
        if (e.delta > 0){
            _radius -= radiusOffset;
            if (_radius < 0.1){
                _radius = 0.1;
            }
        } else {
            _radius += radiusOffset;
        }
        _upDateCamera();
    }

    private function _moveHandler(e:MouseEvent):void {
        if (isMouseDown){
            _theta += (e.stageX - _oldX) >> 2;
            _oldX = e.stageX;
            _phi -= (e.stageY - _oldY) >> 2;
            _oldY = e.stageY;
            //
            if (_theta < 0){
                _theta += 360;
            } else if (_theta > 360){
                _theta -= 360;
            }
            if (_phi < 10){
                _phi = 10;
            } else if (_phi > 170){
                _phi = 170;
            }
            _upDateCamera();
        }
    }

    private function _upDateCamera():void {
        var t:Number = _theta * RAD;
        var p:Number = _phi * RAD;
        var rsin:Number = _radius * Math.sin(p);
        _camera.x = rsin * Math.sin(t) + _target.x;
        _camera.z = rsin * Math.cos(t) + _target.z;
        _camera.y = _radius * Math.cos(p) + _target.y;
        _camera.lookAt(_target)
    }

}