Author Topic: [FLASH] Rotozoom  (Read 1312 times)

0 Members and 1 Guest are viewing this topic.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
[FLASH] Rotozoom
« on: December 21, 2008 »


Hi,

here is the source code to a little roto-zoomer done in ActionScript3.0

Code: [Select]
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/
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 612
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: [FLASH] Rotozoom
« Reply #1 on: December 21, 2008 »
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:
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [FLASH] Rotozoom
« Reply #2 on: December 21, 2008 »
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.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 612
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: [FLASH] Rotozoom
« Reply #3 on: December 21, 2008 »
Well, easy or not, it's really really cool :) I guess it would be nice for some website decorations
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [FLASH] Rotozoom
« Reply #4 on: December 21, 2008 »
Yup. Thanks a lot, Hezad.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17296
  • Karma: 489
  • evil/good
    • View Profile
    • My Homepage
Re: [FLASH] Rotozoom
« Reply #5 on: December 22, 2008 »
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 :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [FLASH] Rotozoom
« Reply #6 on: December 22, 2008 »
Thanks Shocky. Good to hear that you like it (and the new site).
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline spitfire

  • Atari ST
  • ***
  • Posts: 200
  • Karma: 5
    • View Profile
Re: [FLASH] Rotozoom
« Reply #7 on: December 24, 2008 »
Thanx for that Benny.

Would be cool if this forum also highlighted code.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [FLASH] Rotozoom
« Reply #8 on: December 25, 2008 »
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.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: