Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Animation and Effects

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-28-2006, 03:19 PM   #1
unicorn
elder one
 
Join Date: Jul 2006
Posts: 27
Cool water effect revisited...

some time ago i've found info that using bitmap filters on video in flash 8 is slow... now it's time for flex 2, actionscript 3...

so here's some water effect (originally coded by andre michelle in AS2) ported by me to AS3, applied to some nice video. video is refreshed at 25fps, water effect at 50fps... it can easly go as far as 100fps, but it just doesn't look so good then

source code is lame... but i can provide it if you wish

just... PUSH THE BUTTON

almost forgotten...
click here

Last edited by unicorn; 07-28-2006 at 03:21 PM..
unicorn is offline   Reply With Quote
Old 07-30-2006, 02:35 PM   #2
thou
Registered User
 
Join Date: Jul 2006
Posts: 66
Default

that really cools
love the fire too, wonder if i can ever lend my hand on that code

Last edited by thou; 07-30-2006 at 02:46 PM..
thou is offline   Reply With Quote
Old 07-31-2006, 11:01 AM   #3
unicorn
elder one
 
Join Date: Jul 2006
Posts: 27
Default

Code:
kadaj.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:fx="fx.*" layout="horizontal" horizontalAlign="center" verticalAlign="middle" creationComplete="waterinit()" frameRate="50">
	<mx:Script>
		<![CDATA[
			internal function waterinit():void
			{
				panel.addChild(waterfx.getbmp());
			}
		]]>
	</mx:Script>
	<mx:Panel id="panel" width="324" height="208" layout="absolute" horizontalAlign="center" verticalAlign="middle">
		<fx:Water id="waterfx" source="kadaj2.flv" width="304" height="168" live="true" visible="false" x="0" y="0"/>
	</mx:Panel>
</mx:Application>

Water.as

package fx
{
	import mx.controls.VideoDisplay;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import flash.geom.Point;
	import flash.geom.Matrix;
	import flash.filters.ConvolutionFilter;
	import flash.geom.ColorTransform;
	import flash.filters.DisplacementMapFilter;
	import mx.core.FlexBitmap;
	import mx.core.UIComponent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import fx.performance.Fps;

	public class Water extends VideoDisplay
	{
		internal var wateron:Boolean;
		internal var damper:BitmapData;
		internal var result:BitmapData;
		internal var result2:BitmapData;
		internal var source2:BitmapData;
		internal var buffer:BitmapData;
		internal var output:BitmapData;
		internal var surface:BitmapData;
		internal var bounds:Rectangle;
		internal var origin:Point;
		internal var matrix:Matrix;
		internal var matrix2:Matrix;
		internal var wave:ConvolutionFilter;
		internal var damp:ColorTransform;
		internal var water:DisplacementMapFilter;
		internal var width1:int;
		internal var height1:int;
		internal var width2:int;
		internal var height2:int;
		internal var fxbmp:FlexBitmap;
		internal var fxbmpcomp:UIComponent;
		internal var mytimer:Timer;
		internal var wobbly:Boolean;
		internal var fps:Fps;

		public function Water()
		{
			width1 = 304;
			height1 = 168;
			width2 = 152;
			height2 = 84;
 			damper = new BitmapData(width2, height2, false, 0x80);
			result = new BitmapData(width2, height2, false, 0x80);
			result2 = new BitmapData(width1, height1, false, 0x80);
			source2 = new BitmapData(width2, height2, false, 0x80);
			buffer = new BitmapData(width2, height2, false, 0x80);
			output = new BitmapData(width1, height1, true, 0x80);
			surface = new BitmapData(width1, height1);
			bounds = new Rectangle(0, 0, width2, height2);
			origin = new Point();
			matrix = new Matrix();
			matrix2 = new Matrix();
			matrix2.a = matrix2.d=2;
			wave = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);
			damp = new ColorTransform(0, 0, 0.99609374, 1, 0, 0, 2, 0);
			water = new DisplacementMapFilter(result2, origin, 4, 4, 48, 48, 'ignore');
			fxbmp = new FlexBitmap(output);
			fxbmpcomp = new UIComponent();
			fxbmpcomp.addChild(fxbmp);
			wobbly = false;
			fxbmpcomp.addEventListener('mouseDown', mouse);
			fxbmpcomp.addEventListener('mouseUp', mouse);
			addEventListener('enterFrame', framelistener);
			mytimer = new Timer(40);
			mytimer.addEventListener('timer', timerlistener);
			mytimer.start();
			fps = new Fps();
			fxbmpcomp.addChild(fps);
		}
		public function getbmp():UIComponent
		{
			return fxbmpcomp;
		}
		internal function framelistener(e:Event):void
		{
			if (wobbly) {
				var mx:int = Math.round(mouseX/2);
				var my:int = Math.round(mouseY/2);
				source2.setPixel(mx+1, my, 0xffffff);
				source2.setPixel(mx-1, my, 0xffffff);
				source2.setPixel(mx, my+1, 0xffffff);
				source2.setPixel(mx, my-1, 0xffffff);
				source2.setPixel(mx, my, 0xffffff);
			}
			result.applyFilter(source2, bounds, origin, wave);
			result.draw(result, matrix, null, 'add');
			result.draw(buffer, matrix, null, 'difference');
			result.draw(result, matrix, damp);
			result2.draw(result, matrix2, null, null, null, true);
			output.applyFilter(surface, new Rectangle(0, 0, width1, height1), origin, water);
			buffer = source2;
			source2 = result.clone();
			fps.update();
		}
		internal function timerlistener(e:TimerEvent):void
		{
			surface.draw(this);
		}
		internal function mouse(e:MouseEvent):void
		{
			wobbly = e.buttonDown;
		}
	}
}

Fps.as

package fx.performance
{
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.getTimer;

	public class Fps extends TextField
	{
		internal var fr:int;
		internal var ms:int;
		internal var ft:TextFormat;
		
		public function Fps()
		{
			ft = new TextFormat();
			ft.size = 10;
			ft.bold = true;
			ft.font = 'Verdana';
			autoSize = 'left';
			textColor = 0xffffff;
			defaultTextFormat = ft;
		}
		public function update():void
		{
			fr++;
			if (ms + 1000 < getTimer())
			{
				text = 'fps: '+fr.toString();
				fr = 0;
				ms = getTimer();
			}
		}
	}
}
that's it
unicorn is offline   Reply With Quote
Old 08-01-2006, 06:51 AM   #4
thou
Registered User
 
Join Date: Jul 2006
Posts: 66
Default

thanks
thou is offline   Reply With Quote
Old 05-14-2007, 10:00 AM   #5
carnophage
Registered User
 
Join Date: Apr 2007
Posts: 8
Default

Where can I see the example?
carnophage is offline   Reply With Quote
Old 03-12-2008, 12:50 PM   #6
overbyte
more bytes than sense
 
overbyte's Avatar
 
Join Date: Nov 2005
Posts: 66
Default

Quote:
Originally Posted by unicorn View Post
Code:
Fps.as

package fx.performance
{
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.getTimer;

	public class Fps extends TextField
	{
		internal var fr:int;
		internal var ms:int;
		internal var ft:TextFormat;
		
		public function Fps()
		{
			ft = new TextFormat();
			ft.size = 10;
			ft.bold = true;
			ft.font = 'Verdana';
			autoSize = 'left';
			textColor = 0xffffff;
			defaultTextFormat = ft;
		}
		public function update():void
		{
			fr++;
			if (ms + 1000 < getTimer())
			{
				text = 'fps: '+fr.toString();
				fr = 0;
				ms = getTimer();
			}
		}
	}
}
that's it
THAT IS FREAKIN' AWESOME! That has explained sooo much about what was wrong with my textfield class it's not even funny. Thankyou very much
overbyte is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
water waves effect raphaelc4 Animation and Effects 0 06-10-2005 03:11 PM
Water effect Tex Animation and Effects 1 11-23-2003 10:06 PM
how to make a drop of water effect Thore-Gundi Animation and Effects 4 10-06-2003 04:59 PM
Running water effect garion1 Animation and Effects 2 04-07-2003 11:48 AM
Water effect aggony! hotkarl! Animation and Effects 5 09-10-2002 11:12 AM


All times are GMT. The time now is 06:01 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.