Archive | ActionScript RSS for this section

Pixas Slope Primitives Added

The Four directions of Slope Primitives has been added into Pixas.

The parameters for the Slope constructor (take SlopeEast for example):

SlopeEast

public function SlopeEast(_dms:SlopeDms = null, _color:SlopeColor = null, _border:Boolean = true)

Parameters
_dms:SlopeDms - the SlopeDms dimension obj for rendering
_color:SlopeColor - the SlopeColor color obj for rendering
_border:Boolean - whether show border and highlight

The Slope Group has four sides: left slope, right slope, left side and right side. As it was introduced in the Color Tutorial, the SlopeColor.getByHorizontalColor(); static method helps you calculate values from light to dark automatically and returns an instance of SlopeColor which contains the values set.

Note: The horizontal side is taken as the reference side, in order to keep the same light source with other Primitives. However, you should keep in mind that the horizontal side does not really exist in each Slop Primitive. And the rendering effect for combination of Cube and Slopes will be like this:

Pixas Showcase Updating: Uncle Big’s Adventure

This time I decided to make Uncle Big Stand up~

Check the details at here:
Many thanks to the cartoon author UncleBig2D

Pixas has been added to wonderfl.net Libraries

Pixas has been added to wonderfl.net online building Libraries, which means from now on you can import the pixas classes when building applications on wonderfl.net
Cheers, thanks to mash and sugi!

Check how it behaves here:
http://wonderfl.net/search?q=com.risonhuang.pixas

This is an examle:

And here’s the code:

package 
{
	import com.bit101.components.*;
	import com.risonhuang.pixas.dimensions.CubeDms;
	import com.risonhuang.pixas.colors.CubeColor;
	import com.risonhuang.pixas.objects.PixelObject;
	import com.risonhuang.pixas.objects.primitives.Cube;
    import flash.display.Sprite;
    import flash.events.Event;
    
    /**
     * @author max.huang
     * @see http://code.google.com/p/pixas/
     */
    public class Main extends Sprite 
    {
        private var vBox:VBox;
        private var vBoxColor:VBox;
        private var vBoxBorder:VBox;
        private var sliX:HUISlider;
        private var sliY:HUISlider;
        private var sliZ:HUISlider;
        private var colorChooser:ColorChooser;
        private var cb:CheckBox;
		private var outPO:PixelObject;
        
        public function Main():void 
        {
            outPO = new PixelObject();
            outPO.x = Math.floor(stage.stageWidth / 2);
            outPO.y = Math.floor(stage.stageHeight / 2);
            addChild(outPO);
            
            //control menu
            vBox = new VBox(this , 5, 4);
            var lableA:Label = new Label(vBox, 0, 0, "Cube dimension:");
            sliX = new HUISlider(vBox, 0, 0, "X", updateCube);
            sliY = new HUISlider(vBox, 0, 0, "Y", updateCube);
            sliZ = new HUISlider(vBox, 0, 0, "Z", updateCube);
            var s:HUISlider;
            for each(s in [sliX, sliY, sliZ])
            {
                s.setSliderParams( 6, 220, 100);
                s.tick = 2;
                s.labelPrecision = 0;
            }
            sliZ.tick = 1;            
            vBoxColor = new VBox(this , 5, 110);
            var lableB:Label = new Label(vBoxColor, 0, 0, "Cube top side color:");
            colorChooser = new ColorChooser(vBoxColor, 0, 0, 0xE6E8E9, updateCube);
            colorChooser.usePopup = true;
                        
            vBoxBorder = new VBox(this , 5, 180);
            cb = new CheckBox(vBoxBorder, 0, 0, "Cube border", updateCube);
            cb.selected = true;
                        
            updateCube();
        }
        
        private function updateCube(e:Event = null):void
        {
            while (outPO.numChildren > 0)
            {
                outPO.removeChildAt(0);
            }
			var dms:CubeDms = new CubeDms(sliX.value, sliY.value, sliZ.value);
			var color:CubeColor = CubeColor.getByHorizontalColor(colorChooser.value);
            var cube:Cube = new Cube(dms , color, cb.selected);
			outPO.addChild(new PixelObject(cube));
        }
    }
}

Moving Shell

Try it out – wonderfl build flash online

package 
{
	/**
	 * @author max
	 */
    import Box2D.Common.Math.b2Vec2;
    import Box2D.Dynamics.b2Body;
    import com.actionsnippet.qbox.*;
    import flash.display.MovieClip;
	import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    [SWF(width=465, height=465, frameRate=60)]
    public class Main extends MovieClip 
    {
        private var sim:QuickBox2D;
        private var center:QuickObject;
		 
        public function Main():void 
        {
			var bg:Sprite = new Sprite();
			bg.graphics.beginFill(0x111111);
			bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			bg.graphics.endFill();
			addChild(bg);
			
			var top:MovieClip = new MovieClip();
			addChild(top);
			sim = new QuickBox2D(top, { gravityY:0 } );
            sim.createStageWalls( {lineColor:0x111111, fillColor:0x111111} );
            sim.start();

            addEventListener(Event.ENTER_FRAME, __onEnterFrame);
			var type:String = QuickBox2D.DISTANCE;
	
			var points:Array = [];
            var num : uint = 50;
            for (var i:uint = 0,angle:Number = 0,radius:uint = 150,step:Number = Math.PI*2 / num; i < num; i++)
			{
                var cX:Number = stage.stageWidth / 2 + radius * Math.cos(angle);
                var cY:Number = stage.stageHeight / 2 + radius * Math.sin(angle);
				//box2d circle and joint
                points.push(sim.addCircle( {lineThickness:2,lineAlpha:0, fillAlpha:0,x:cX / 30, y:cY / 30, density:1,radius:0.2} ));
				i > 0?sim.addJoint( {lineThickness:2,lineColor:0xFFFFFF,type:type, a:points[i - 1].body, b:points[i].body } ):0;
				i == num - 1?sim.addJoint( {lineThickness:2,lineColor:0xFFFFFF,type:type, a:points[0].body, b:points[i].body } ):0;
                angle += step;
            }
			
			center = sim.addCircle( {lineThickness:2,lineColor:0xFFFFFF,radius:2.4,fillAlpha:0, x:stage.stageWidth / 2 / 30, y:stage.stageHeight / 2 / 30 - 2.5, density:1 } );
			sim.addCircle( {lineThickness:2,lineColor:0xFFFFFF,radius:2,fillAlpha:0,  x:stage.stageWidth / 2 / 30-1, y:stage.stageHeight / 2 / 30, density:1 } );
			sim.addCircle( {lineThickness:2,lineColor:0xFFFFFF,radius:1.6,fillAlpha:0,  x:stage.stageWidth / 2 / 30+1, y:stage.stageHeight / 2 / 30, density:1 } );
			sim.mouseDrag();
			
        }
		
        private function __onEnterFrame(e:Event = null):void 
        {
            for (var body:b2Body = sim.w.m_bodyList; body ; body = body.GetNext())
            {
                if (body == center.body) continue;
                var cp:b2Vec2 =  center.body.GetPosition();
                var f:b2Vec2 = cp.Copy();
                f.Subtract(body.GetPosition());
                f.Normalize();
                f.Multiply(20);
				if(Math.random()>0.5){f = f.Negative();}
                body.ApplyForce(f, body.GetWorldCenter());
            }
        }
    }
}