Dark Bit Factory & Gravity
ARCHIVE => Archive => Java,JS & Flash => Topic started by: benny! on December 21, 2008
-
Hi,
here is the source code to a little roto-zoomer done in ActionScript3.0
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.events.MouseEvent;
import flash.net.*;
/**
* Simple rotozoomer in actionscript3.0
*
* @author benny!weltenkonstrukteur.de
*/
public class RotoZoom2 extends Sprite
{
// Declaring class constants
private const ZOOM_MAX:Number = 3;
private const ZOOM_MIN:Number = -2.0;
private const ZOOM_DELTA:Number = 0.015;
private const ROTATE_DELTA:Number = 0.05;
/// Initialisate private class members
private var angle:Number = 0, zoom:Number = ZOOM_MIN, isZoomIncreasing:Boolean = true;
private var logo:Bitmap = null, logoBitmapData:BitmapData;
private var sw:uint, sh:uint;
// Declare embedded assets
[Embed(source = "made-bunny.png")]
private var LogoBitmap:Class;
/**
* Constructor
*/
public function RotoZoom2()
{
init();
addEventListener("enterFrame", loop);
}
/**
* Initialize needed sprites and bitmaps
*/
private function init():void
{
// Create logo bitmap and retrieving the bitmapData
logo = new LogoBitmap();
logoBitmapData = logo.bitmapData;
// Setting canvas dimensions
sw = stage.stageWidth;
sh = stage.stageHeight;
}
/**
* Calcualte roto matrix and draws the scene
* @param ev, onEnter event
*/
private function loop(ev:Event):void
{
// If we want to zoom in
if ( isZoomIncreasing )
{
// Add increase value to zoom
zoom = zoom + ZOOM_DELTA;
}
else
{
// Otherwise decrement value from zoom
zoom = zoom - ZOOM_DELTA;
}
// Calculate new rotation angle
angle = angle + ROTATE_DELTA;
// If angle is greater than 360
if ( angle > 360 )
{
// Reset it to zero
angle = 0;
}
// If zoom is higher than maximum value
if ( zoom > ZOOM_MAX )
{
// Change to zoom out
isZoomIncreasing = false;
zoom = ZOOM_MAX;
}
// If zoom is less than minimum value
else if ( zoom < ZOOM_MIN )
{
// Change to zoom in
isZoomIncreasing = true;
zoom = ZOOM_MIN;
}
// Calculate matrix for rotation an zooming
var rotoMatrix:Matrix = new Matrix(Math.cos(angle) * zoom, Math.sin(angle), -Math.sin(angle), Math.cos(angle) * zoom, 0, 0);
// Fill scene with bitmap using the rotoMatrix
graphics.clear();
graphics.beginBitmapFill(logoBitmapData, rotoMatrix,true, true);
graphics.drawRect(0, 0, sw, sh);
graphics.endFill();
// Set it free for gargabe collection
rotoMatrix = null;
}
}
}
For a working version - visit my blog at.
http://www.weltenkonstrukteur.de/2008/12/rotozoomer-in-actionscript30/ (http://www.weltenkonstrukteur.de/2008/12/rotozoomer-in-actionscript30/)
-
Mate, it's really awesome :) I don't have any knowledge in Action Script so I don't know how hard it can be to code it but I assume it is :P
Oh and I guess I recognize the same algorithm you used for the DBF link button ;D
:goodpost:
-
It was surprisingly easy to be honest. Using the Matrix class and the
beginBitmapFill command - it was really piece of a cake ;-)
I was very impressed how easy such an effect can be done in Action-
script.
-
Well, easy or not, it's really really cool :) I guess it would be nice for some website decorations
-
Yup. Thanks a lot, Hezad.
-
I've got to post that nice link button... Shame on me Benny, I am sorry.
The rotozoom in your link looks great too :) It reminds me a lot (in quality terms) of the Mandrixx Java applets, you definately make awesome actionscript stuff Benny.
The site looks just fine too... I love the way that it displays to rotozoomer! Well done :)
-
Thanks Shocky. Good to hear that you like it (and the new site).
-
Thanx for that Benny.
Would be cool if this forum also highlighted code.
-
Thanx for that Benny.
Np, mate.
Would be cool if this forum also highlighted code.
Don't know if there is a plugin available like Geshi that
provides syntax highlighting for SMF. Would be a good idea
though.