Any suggestions eh...?

This is not perfect at all but I think works fine as a quick test and only
using a 45 degree rotation. 

To see it working, put any image in a MovieClip and call it 'mc' and then
this code on the same frame.


-----------------------------------------------------------------
        


Stage.scaleMode = 'noScale' 
import flash.display.*
import flash.geom.*


function drawSlices ( image:MovieClip, drawMC:MovieClip, rotation:Number,
sliceWidth:Number ) 
{
        var slice_info = getSliceInfo ( image, rotation );
        
        // DOT IS JUST A VISUAL MARKER
        dot._x = image._x + slice_info.pt.x;
        dot._y = image._y + slice_info.pt.y;
        dot.swapDepths ( dot._parent.getNextHighestDepth() )
        
        var angle = rotation * (Math.PI/180);

        var slices_top = Math.ceil(image._width/sliceWidth);
        var slices_bottom = Math.ceil((slice_info.pt.x)/sliceWidth)

        var slice_array = [];
        for ( var i = -slices_bottom; i < slices_top; i++ ) 
        {
                var slice = drawMC.createEmptyMovieClip ( 'slice_' + i,
drawMC.getNextHighestDepth() );
                slice._x = i * ( sliceWidth-(sliceWidth/1.7));
                
                var bmp_temp = new BitmapData ( sliceWidth+1,
slice_info.diagonal_height+sliceWidth, true, 0x00FFFFFF );
                var bmp_temp_matrix:Matrix = new Matrix();
                bmp_temp_matrix.rotate( angle );
                
                bmp_temp_matrix.translate( -(sliceWidth) * i, -sliceWidth *
i );
                bmp_temp.draw ( image, bmp_temp_matrix, null, null, null,
true );
                
                var slice_bmp = new BitmapData ( slice_info.diagonal_width ,
slice_info.diagonal_height, true, 0x00FFFFFF );
                var slice_bmp_matrix:Matrix = new Matrix();
                slice_bmp_matrix.rotate(-angle);
                slice_bmp_matrix.translate( (sliceWidth )*i, 0 );
                
                slice_bmp.draw ( bmp_temp, slice_bmp_matrix, null,
null,null, true  );
                slice.attachBitmap ( slice_bmp, 1, true, true );
                
                slice_array.push ( slice );
        }
        drawMC.slice_array = slice_array;
}


////////////////////////////////////////

function getSliceInfo ( image, angle)
{
        var pt = new Point ( image._width, image._height );
        var len = pt.length;
        
        var degrees = 90 - angle;
        var radians = degrees * (Math.PI/180);          
        
        var dpt = new Point ( len * Math.cos ( radians ), len * Math.sin (
radians ) );

        dpt.x = Math.max ( 0, Math.min ( pt.x, dpt.x ));
        dpt.y = Math.max ( 0, Math.min ( pt.y, dpt.y ));
        
        var info = {
                pt:dpt,
                diagonal_width: dpt.x,
                diagonal_height: dpt.length
        }
        return info;
}


////////////////////////////////////////

function drawSlicedImage ()
{       
        // ORIGINAL IMAGE
        mc._alpha = 40
        
        //      SLICE HOLDER
        var drawMC = this.createEmptyMovieClip ( 'drawMC',
this.getNextHighestDepth() );
        drawMC._x = mc._x;
        drawMC._y = mc._y;
        
        //      CREATE SLICES
        var sliceWidth = 30
        var angle = 45;
        drawSlices ( mc, drawMC, angle, sliceWidth );
}

function addSliceInteraction ( )
{
        drawMC.onMouseMove = function() 
        {
                var xper = Math.max ( 0, Math.min ( 1, this._xmouse /
mc._width ) )
                var yper = 1-Math.max ( 0, Math.min ( 1, this._ymouse /
mc._height ) )
                var per = (xper+yper)/2
                var inx = Math.round ( this.slice_array.length * per  )
                for ( var i in this.slice_array  ) 
                {
                        var slice = this.slice_array [ i ];
                        if ( i == inx ) 
                        {
                                slice._alpha = 10;
                        } 
                        else 
                        {
                                slice._alpha = 100;
                        }
                }
        }
}


//////////////////////////////////////


function INIT () 
{
        drawSlicedImage ();
        addSliceInteraction ();
}

INIT ();



_____________________________

Jesse Graupmann
www.jessegraupmann.com 
www.justgooddesign.com/blog/ 
_____________________________





-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Tuesday, May 22, 2007 11:38 AM
To: flashcoders
Subject: [Flashcoders] Q:Create and animate diagonal slices from Bitmap

I'm trying to create and animate diagonal slices from a bitmap object.

The easiest way to create slices from Bitmaps is via the Rectangle class,
but I need diagonal slices.

Can this be done via a matrix transform of my bitmap BEFORE I create my
slices, or si there an easier way that involves skewing the slices I create
using the Rectangle class?

Any suggestions welcome!


[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca
--------------------------------------------
"...all improvisation is life in search of a style."
             - Bruce Mau,'LifeStyle'

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to