Category — Flash
HYPE Framework – Bring experimentation to the masses.
Recently Joshua Davis and Brendan Hall released a new framework call HYPE. The aim of the framework is to allow everyone from newbie level to professionals experiment with ease using Flash.
I’m hoping to find some time in between GCSEs to have a go at making some stuff with this, so keep any eye out. You can download it here, and find the setup instructions here.
Have fun!!
November 3, 2009 No Comments
Getting Started with Augmented Reality (FLARToolkit).
If you have been following me on Twitter, then you may have noticed that I have been getting into Augmented Reality. This is the coolest thing I have seen in a long time! Now if you don’t know what this is, then it is a means of mapping 3D objects to a marker in the real world through a web cam.
Here is a simple guide to getting setup using the Augmented Reality in Flash. This includes downloading the library’s and then getting a simple demo up and running.
The name of the library used for Augmented Reality in Flash is called FLARToolkit which is developed by Saqoosha. It is a port of the ARToolkit which is written in C. You can download it from here through SVN. If you haven’t got a SVN client setup then I highly recommend SmartSVN which is a free client and I must thank Richard Leggett for recommending this to me!
Now once you have got the code, add it to your global Actionscript folder, then print out this marker and run the example. You can either compile the source in the ’src’ folder or just run the SWF in the ‘bin-debug’ folder. Hopefully this gives you a idea of what AR/FLARToolkit is all about.
If you can run the example yourself, here is a video of it in action.
FLARToolkit / Augmented Reality Basic Demo. from Harry Northover on Vimeo.
I have also written a base class for a FLARToolkit application. It is designed so that all you have to do is override the function ‘add3d()‘ to add your 3D objects to ‘FLAR_Container” object, and then override another function, ‘addAnimation_3d()‘ to add the animation. My description here is very brief so read the readme file in the package. You can download the class here. If you want to see how much code this can reduce then here is an example class using the base class:
package { import com.harrynorthover.ar.flar.base.FLARSingleMBase; import flash.filters.BlurFilter; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.primitives.Cube; [SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")] public class Demo_BaseClass_Test extends FLARSingleMBase { private var cube:Cube; public function Demo_BaseClass_Test() { /*This is the function 'Init' you need to call to setup the FLARToolkit scene. WIDTH, HEIGHT, FRAMERATE*/ Init(640, 480, 30); } /* ... This function is the one you need to override to add things to your 3D scene. */ override protected function add3D():void { // Add you 3D stuff here. The more the better :-) var pl:PointLight3D = new PointLight3D(); pl.z = -1000; pl.y = 1000; pl.x = 1000; pl.flipped = true; //var blurFilter:BlurFilter = new BlurFilter(24, 12, 1); var matList:MaterialsList = new MaterialsList(); var fsm:FlatShadeMaterial = new FlatShadeMaterial(pl); matList.addMaterial(fsm, "all"); cube = new Cube(matList, 60, 60, 60, 5, 5, 5); //cube.useOwnContainer = true; //cube.filters = [blurFilter]; // FLAR_Container is the FLARBaseNode that you // add your 3D objects to. FLAR_Container.addChild(cube); } /* ... This is the function to which you override to add your 3D animation. */ override protected function addAnimation_3d():void { //Add you animation here. cube.yaw(10); } } }
See? Lots of code that has been got rid of!
Other demos I have been working on are here:
FLAR + Lines3D:
FLARToolkit and Lines3D / Augmented Reality from Harry Northover on Vimeo.
Incorporating AS3DMod:
FLAR + As3DMod from Harry Northover on Vimeo.
So there you go, my first few demos. Yes, I know, they are not very special but now I’m working on getting mutliple markers working and just more advanced demos in general. If you are looking for more advice on how to get set up with FLAR go over to this blog here. This has everything you need to get going. Also, check out squidder.com for some cool demos.
Happy ARing!
April 15, 2009 19 Comments
PaperMash
Here’s the first little tech demo of ‘09 and I think it is a pretty cool one. The first difference is that it is made with Papervision3D instead of my usual engine choice of Away3D. It also uses a relativly new library, AS3DMod, and works with the 4 most popular engines. Now this library is a modifier library which can do some really cool stuff, so go on over and check it out.
Now for the demo. It creates a standard plane, then applys a noise and perlin modifier to it. The last thing is to apply a FlatShadeMaterial to the plane and just animate these properties in the enter frame function.
You can download it here. To view the demo, click on the picture.
Harry.
January 10, 2009 No Comments
BitmapRenderSession Demo.
(Updated: Download Link Added)
Phew, a tech demo hasn’t found it’s way on here for quite a while! Here is one to let you know I’m back, but busy.
I finally managed to get an idea down on to paper, (well.. into the Flash IDE) that had been buzzing around in my head for ages!
There is a feature in Away3D call the BitmapRenderSession, and you assign this to the session variable of your View3D. What this tells the rendered to do is, instead of drawing directly to the screen, it draws everything inside a BitmapData object, but at a much smaller resolution. This Bitmap is then scaled up and show and the selected size. As you can imagine this saves a lot of work done, as you only have to draw at, say, a quarter of the resolution that you normally would. There is a catch. You will have figured this out already, but the lost of quality is tremendous the more you scale it up, but I have found out how to make this work for me. Just look at the demo.
What I have done here is create a plane, added then some animation to it. Then I am assigning a new BitmapRenderSession object to the View3D, and then changing the value of it when the mouse moves. If you look closely at the code, you will see that I am creating a new BitmapRenderSession for every frame. Not efficient at all, but I haven’t had the time to look into this properly, so if anyone knows a solution, let me know!
This at one end of the scale (with your mouse at the top), looks high quality, but when you move your mouse to the bottom, you can see the effect immediately. It becomes highly pixilated and, I think, fairly cool! I have seen this sort of effect on many sites, and always wondered how I could achieve it. Here is my solution, but one of many out there I’m sure.
Your going to have to resize your browser, as pop-ups seem to be fairly hard in Wordpress :(
You can download the whole thing over at my Google Code site (look on the right). It should be up there in a few days. Here’s the link: BMRS.zip
Harry.
December 8, 2008 No Comments
How to create a Skybox in Away3D.
This technique is used when you need to create an all-round back drop for a 3D scene. A skybox is basically a big cube and textures are on the inside, and the camera is placed in the middle of the box. Ready?
You can download the whole thing here: http://harry-northover-code-store.googlecode.com/files/A3DSkyBox.zip.
Step 1 – Setting up Flash.
This is the easy bit. Create a new flash file, and leave the size of it at the default, and then in the bottom of the Flash IDE, there should be a text box saying ‘Document Class’. Create an Actionscript 3.0 file called SkyStuff and save it. Then you need to type SkyStuff into the text box and press enter. There should be no errors.
Step 2 – Importing…
Obviously, you are going to need the Away3D classes and you can download them here. If you already have a folder for your classes then unzip the download and copy it to there, but if not then just copy all the content of the download to the same directory of your Flash file.
Here are the necessary imports:
package { import away3d.cameras.HoverCamera3D; import away3d.containers.Scene3D; import away3d.containers.View3D; import away3d.materials.BitmapMaterial; import away3d.primitives.Skybox; import away3d.core.utils.Cast; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent;
So, there you go, the necessary imports. I think these are fairly obvious, but if you need to look them up, go here.
So, on we go!
Step 3 – Variables.
Here we need to create the necessary variables to hold stuff like materials. So here it is:
public class SkyStuff extends Sprite { public var cam:HoverCamera3D = new HoverCamera3D( { zoom:2 } ); public var scene:Scene3D = new Scene3D; public var view:View3D = new View3D( { camera:cam, scene:scene, x:0, y:0 } ); // Skybox stuff. public var sky:Skybox; // Materials.... public var sky_front_material:BitmapMaterial; public var sky_back_material:BitmapMaterial; public var sky_left_material:BitmapMaterial; public var sky_right_material:BitmapMaterial; public var sky_up_material:BitmapMaterial; public var sky_down_material:BitmapMaterial; // Movement vars. public var move:Boolean = false; public var lastPanAngle:Number; public var lastTiltAngle:Number; public var lastMouseX:Number; public var lastMouseY:Number;
So first of we create the basics that are needed for any Away3D project. This is a scene, a viewpoint and a camera. I am assuming that you know what these are for, so I am going to skip to the parameters. For the camera, we set the zoom to 2, in the viewpoint we set the scene toscene, the camera to cam and align it to the top left corner of the stage.
Next we create the actual skybox that will have all the materials assigned to it.
After that we create the 6 different variables that will hold each material for the skybox faces. This includes the front, back, left, right, top, bottom. Fairly obvious? Hope so.
The next variables hold data that we need for movement of the camera. These include a variable to see if the camera needs to be moved, the last pan angle, the last tilt angle, the last mouse X position and the last mouse Y position.
You will see how we use these later on.
Step 4 – Calling the functions.
Next we create the constructor which adds an event listener to call the function Init that will initialize all the 3D and 2D assets.
public function SkyStuff():void { addEventListener(Event.ADDED_TO_STAGE, Init); } private function Init(evt:Event):void { InitStage(); InitEngine(); InitMaterials(); InitObjects(); InitListeners(); }
Here you can see that all the different parts of the movie are initiated here. This includes setting up the stage, Away3D, the materials for the skybox, the 3D objects (skybox), and the event listeners.
Step 5 – Setting up the stage & engine.
Now we set the align mode and necessary stuff for Away3D.
private function InitStage():void { stage.align = StageAlign.TOP_LEFT stage.scaleMode = StageScaleMode.NO_SCALE; } private function InitEngine():void { cam.mintiltangle = -80; cam.maxtiltangle = 20; cam.targetpanangle = cam.panangle = 0; cam.targettiltangle = cam.tiltangle = 0; addChild(view); }
Here we are setting the stage align to the top left, and the scale mode to no scale.
Next, in theInitEngine() function we set up the camera, and then add the viewpoint to the display list. The variables we set for the camera are the mintiltangle which means it cannot tilt past -80 degrees, the maxtilitangle which means it can’t tilt further that 20 degrees. We also set the targetpanangle, and the targettiltangle. If you need more clarification to these values, click here.
Once we have done this, we add the whole viewpoint to the stage.
Step 6 – The meaty part, creating the Skybox
Next, we create the actual skybox and all the materials that are needed for its faces.
private function InitObjects():void { sky = new Skybox( sky_front_material, sky_left_material, sky_back_material, sky_right_material, sky_up_material, sky_down_material ); sky.quarterFaces(); view.scene.addChild(sky); } private function InitMaterials():void { sky_front_material = new BitmapMaterial(Cast.bitmap(SkyFront)); sky_back_material = new BitmapMaterial(Cast.bitmap(SkyBack)); sky_left_material = new BitmapMaterial(Cast.bitmap(SkyLeft)); sky_up_material = new BitmapMaterial(Cast.bitmap(SkyTop)); sky_right_material = new BitmapMaterial(Cast.bitmap(SkyRight)); }
Now, in the functionInitObjects() we assign a new skybox to the variable sky that we created in step 3.
So, to create a skybox you need to assign a front, back, left, right, top, bottom material. As you can see from the variables assigned to Skybox(), you can see which order these materials need to be assigned to. The full documentation is here.
Next, we call a function called quaterFaces(). This divides all face objects into 4 equal sized face objects. So this creates a more precise image.
Lastly, we add it to the viewpoint.
In the InitMaterials() function we assign a new bitmap material to each of the 6 materials. To do this, find a skybox (here’s a good site) and import the 6 images into you flash file. When you import them, give them a linkage ID of Sky + (Front, Back, whatever part of the skybox it is). Make sure these linkage ID’s correspond to the ones we passed into Cast.bitmap(name).
So now we have assigned all the skybox parts to their respective variables, and then we have created the skybox, passed all the faces into it, quatered the faces and added it to the viewport. That is the key part, now on to adding event listeners and camera movement.
Final Note – Camera Movement
Now as this tutorial is about the skybox, and not the camera movement, I am going to just give you the code and let you work it out.
private function EnterFrame(evt:Event):void { if (move) { cam.targetpanangle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle; cam.targettiltangle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle; } cam.hover(); view.render(); } private function MouseDown(evt:MouseEvent):void { lastPanAngle = cam.panangle; lastTiltAngle = cam.tiltangle; lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; move = true; stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } private function MouseUp(evt:MouseEvent):void { move = false; stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } private function onStageMouseLeave(evt:Event):void { move = false; stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } private function Resize(evt:Event):void { view.x = stage.stageWidth / 3; view.y = stage.stageHeight / 3; } } }
So there you go. I hope you enjoy this and find it useful.
Harry.
November 22, 2008 No Comments
Creating special effects in Flash CS3
Right well, I have seen many different demos and examples of how to create unique, random art by code. Now this looks very cool, but how on earth do you recreate this? Well the is what I am going to show you. There final piece can be downloaded here. As you can see, this is quite a cool piece of generative art. Now I am going to show you how to achieve this.
Step 1:
First of fire up Flash CS3. If you don’t have a copy you can download a trial from Adobes site. Right, now create a new Flash Actionscript 3 document. The next thing to do is set up the stage. I kept my dimensions of my Flash file as the default, 550px x 400px. Also set the frame rate to about 30fps. This stops the animation from appearing to be slow, and chuggy.
Now for this tutorial you need a simple graphic that will be used as our starting point for the animation. So, draw a simple circle on the stage, make sure its not very bit (maximum 100×100) and then select it all and press F8. This will present you with a box that will let you create a movie clip. Set the name to ‘Circle’, and then set the type to Movie Clip. Now, there should be a Linkage section, but if its not present, click the Advanced button in the bottom right hand corner.
In the linkage section there should be a check-box saying “Export for Actionscript”. Once this is clicked, some of the boxes that were greyed out should be come editable. There should be a box saying Linkage ID (or Symbol name), or something similar. If it is not already containing the word ‘Circle’, adjust it accordingly.
So now click OK. There might be a warning come up, but just click OK. The next thing to do is the delete the graphic that you created from the stage. All you need to do is select it (single click) and then press DELETE. This will delete it from the stage, but it will still be in the library.
Step 2:
Now we have the flash file set up, click on the first frame of the timeline and press F9 to access the actionscript editor.
So, now to set up everything that we need for the tweening etc. So click in the first line and add this code:
import gs.TweenLite; import gs.easing.Expo;
For this to work you need to have TweenLite in your class path. You can download it from here. If you don’t have a special class path just unzip the file that you have just downloaded and copy the folders to the same directory that your Flash file is.
So with the appropriate imports done, now we need to set up some basic variables that will make our development much easier:
var amountOfCircles:Number = 30; var stageW:Number = stage.stageWidth; var stageH:Number = stage.stageHeight; var ranX:Number = Math.random() * stageW - 300; var ranY:Number = Math.random() * stageH - 300; var ranAlpha:Number = Math.random() * .5;
Now here’s an explanation of what these lines are for.
The first one is fairly obvious. This is how many difference instances of the graphic you created earlier we will create. As you can see from the completed version there are multiple circles flying around.
The next two contain the width and height of the stage. This is purley to make it easier to reference to the value of the width of the stage. Basically it saves more typing.
The two after that are variables that hold a random X and Y value that are within the width of the stage.
The last one is a random alpha value between 0 – 50. This means that the graphic will never be completely opaque.
Step 3:
Now we need to create the 3 filters that we are going to create. There are two blur filters and a glow filter. You will see soon how we animate and apply them to out graphic.
var blur:BlurFilter = new BlurFilter(10, 10, 1); var blurBM:BlurFilter = new BlurFilter(20, 0, 1); var glowBM:GlowFilter = new GlowFilter(Math.round( Math.random()*0xFFFFFF ));
It is fairly obvious which filters are what, but the parameters are not! So here we go.
For a blur filter it is as follows new BlurFilter(BlurX, BlurY, Quality). Now the BlurX and BlurY are fairly straight forward, it sets how much you want the filter to blur the graphic on the respective axis. The next is the quality, and I usually set this to one for high quality. You can set it 1 – 15, and the X and Y can go from 0 – 255.
Later we will apply these filters to out bitmap data.
Step 4:
Now we are getting to the more exciting bits. We are going to create and add the bitmap and bitmap data objects.
So to do this we use:
var bmd:BitmapData = new BitmapData(550, 500, true, 0x000000); var bm:Bitmap = new Bitmap(bmd); bm.x = 0; bm.y = 0; addChild(bm);
Right now, this is most probably a new bit for you. So first a bit on bitmap and bitmap data objects.
- Bitmap Data - This is basically something that holds all you data that you are going to insert into your bitmap object. So this includes the width, height, whether it is transparent or not, if so what color should be displayed in the transparent area. This will also hold all the data we want to draw, as you will see late.
- Bitmap – This is the actual bitmap that all the data from the bitmap data will be inserted into and be drawn out. Think of this as the container and the bitmap data being the cargo.
So in the first line we create the bitmap data object and assign all the necessary data for now. This is what I explained earlier.
Next we create the bitmap will is where all the data from the bitmap data will be drawn out into.
After this will align the bitmap to the top left corner of the stage as the top left of the stage is always at X = 0 and Y = 0.
Finally we actually add it to the stage so we can visually see it.
Step 5:
Now we come to an exciting part, creating and adding all the instances of the graphic we created earlier to the stage.
Add this code straight after the last one.
for (var i:uint = 0; i <= amountOfCircles; i++) { var circle:Circle = new Circle(); circle.x = ranX + Math.random() * 100; circle.y = ranY + Math.random() * 100; circle.alpha = ranAlpha; circle.filters = [blur, glowBM]; addChild(circle); }
So what we are doing here is creating a simple loop that will keep running until it has looped over the same about of times as we set in the amoutOfCircles.
Here we also set the current circle to have random X and Y positions, and also random alpha value.
Now, this is where we are starting to use the filters we created earlier. An movie clip or graphic has an array that the filters can be assigned to, so what we are doing is assigning an array of filters to the filters property of circle. Lastly we add it to the stage.
Step 6:
Next we need to add an event listener that will call a function every time a frame is executed. This is an ENTER_FRAME event. Also, we call the function that will randomly move the circles we created earlier to a new random position with a random alpha and colour.
mover(); addEventListener(Event.ENTER_FRAME, enterFrame);
Step 7:
Now this is a main part of our special effect, the mover() function. This is where part of the magic happens.
function mover():void { for (var i:uint = 0; i <= amountOfCircles; i++) { var object:DisplayObject = getChildAt(i); if (object == bm) { i++; } else { object.alpha = ranAlpha; TweenLite.to(object, 1, {x: ranX + Math.random() * 1000, y: ranX + Math.random() * 1000, alpha: 0, ease:Expo.easeInOut, onComplete:mover, blurFilter:{blurX:Math.random()*100, blurY:Math.random() * 100}, tint:Math.round( Math.random()*0xFFFFFF )}); glowBM.color = Math.round( Math.random()*0xFFFFFF ); glowBM.alpha = ranAlpha / 2; } } }
So, here goes.
First of we create a loop that will iterate through all the circles. Then within this we create a variable called object and then we find a circle by using the getChildAt() which finds an object in the display list at the depth of i . We then assign the result of this to object . This gives us a handle on the current circle we are working with.
As the getChildAt() is designed to return anything that is on the stage so we need to check if it has returned the bitmap. We don’t want that, so what we do is skip to the next object in the display list. Once this has happened or if we didn’t have a handle to the bitmap in the first place we move on the code animates the circle.
First of we assign a new alpha value, then we tween it. Now this is beyond the scope of this tutorial, showing you how to use TweenLite, but here is a good tutorial. Just scroll down to the usage section. It is fairly self explanatory anyway.
Next we assign a new colour to the glow filter and also a new alpha value.
Step 8:
Now we are on the last bit of the tutorial. This defines the ENTER_FRAME function.
function enterFrame(evt:Event):void { bmd.draw(stage); bmd.applyFilter(bmd, bmd.rect, new Point(0,0), blurBM); bmd.applyFilter(bmd, bmd.rect, new Point(0,0), glowBM); bmd.scroll(10, 0); }
So, the first line captures what you can see and assigns the data that was captured to the bitmap data, and in turn then to the bitmap.
Next we apply to filters to the bitmap data. These look a little weird to here is an explanation.
The first parameter is which source bitmap data that you want to apply the filter to. The next is what area you want to apply the filter to, and we want to apply it to the whole bitmap data, then the destination point (99.9% of the time you won’t need to change this), and then finally which filter you want to apply to it.
Finally the last one moves everything in the bitmap 10px to the right.
Final Code:
import gs.TweenLite; import gs.easing.Expo; var amountOfCircles:Number = 30; var stageW:Number = stage.stageWidth; var stageH:Number = stage.stageHeight; var ranX:Number = Math.random() * stageW - 300; var ranY:Number = Math.random() * stageH - 300; var ranAlpha:Number = Math.random() * .5; var blur:BlurFilter = new BlurFilter(10, 10, 1); var blurBM:BlurFilter = new BlurFilter(20, 0, 1); var glowBM:GlowFilter = new GlowFilter(Math.round( Math.random()*0xFFFFFF )); var bmd:BitmapData = new BitmapData(550, 500, true, 0x000000); var bm:Bitmap = new Bitmap(bmd); bm.x = 0; bm.y = 0; addChild(bm); for (var i:uint = 0; i <= amountOfCircles; i++) { var circle:Circle = new Circle(); circle.x = ranX + Math.random() * 100; circle.y = ranY + Math.random() * 100; circle.alpha = ranAlpha; circle.filters = [blur, glowBM]; addChild(circle); } mover(); addEventListener(Event.ENTER_FRAME, enterFrame); function mover():void { for (var i:uint = 0; i <= amountOfCircles; i++) { var object:DisplayObject = getChildAt(i); if (object == bm) { i++; } else { object.alpha = ranAlpha; TweenLite.to(object, 1, {x: ranX + Math.random() * 1000, y: ranX + Math.random() * 1000, alpha: 0, ease:Expo.easeInOut, onComplete:mover, blurFilter:{blurX:Math.random()*100, blurY:Math.random() * 100}, tint:Math.round( Math.random()*0xFFFFFF )}); glowBM.color = Math.round( Math.random()*0xFFFFFF ); glowBM.alpha = ranAlpha / 2; } } } function enterFrame(evt:Event):void { bmd.draw(stage); bmd.applyFilter(bmd, bmd.rect, new Point(0,0), blurBM); bmd.applyFilter(bmd, bmd.rect, new Point(0,0), glowBM); bmd.scroll(10, 0); }
So there you go, phew! I hope I explained it enough and you now understand how to create these sort of effects in Flash CS3.
Any problems, suggestion, complaints etc, please feel free to contact me!
- Harry
November 8, 2008 1 Comment
Away3D Base Class
In my effort to cut down the amount of code I write when using Away3D, I created this. It is a base class for projects using Away3D. What this does is create a series of protected functions that you can override and add in what you need, while the base class created the viewport, scene and everything else! This minimizes the amount of code you write in the actual project to a minimal amount!
Here is an example:
package { import away3d.primitives.Sphere; import com.harrynorthover.base.AwayBase; public class BaseClass extends AwayBase { public var sphere:Sphere = new Sphere( { radius:100 } ); public function BaseClass() { // Init(camZoom, viewX, viewY); Init(12, 0, 0); } override protected function Init3D():void { sphere.x = 0; sphere.y = 0; view.scene.addChild(sphere); } } }
See how much is has been reduced by? No faffing around with View3D and addChild(view) etc.
You can download the whole thing here: http://harry-northover-code-store.googlecode.com/files/Away3dBase.zip
Hope it helps!
Harry.
October 12, 2008 No Comments
Technophobia
This is just another this animation I put together last night. It uses TweenLite, and BitmapData combined with a number of filters, to create this rather groovy effect. I think this is one of my better peices, so I hope you enjoy it.
NOTE: It is better viewed when you download it as I am having troubles with pop-ups in Wordpress? When viewed on line it is incrediably slow, and not very good in general.
And here is the code:
import gs.TweenLite; import gs.easing.Expo; var amountOfCircles:Number = 30; var stageW:Number = stage.stageWidth; var stageH:Number = stage.stageHeight; var ranX:Number = Math.random() * stageW - 300; var ranY:Number = Math.random() * stageH - 300; var ranAlpha:Number = Math.random() * .5; var blur:BlurFilter = new BlurFilter(10, 10, 1); var blurBM:BlurFilter = new BlurFilter(20, 0, 1); var glowBM:GlowFilter = new GlowFilter(Math.round( Math.random()*0xFFFFFF )); var bmd:BitmapData = new BitmapData(550, 500, true, 0x000000); var bm:Bitmap = new Bitmap(bmd); bm.x = 0; bm.y = 0; addChild(bm); for (var i:uint = 0; i <= amountOfCircles; i++) { var circle:Circle = new Circle(); circle.x = ranX + Math.random() * 100; circle.y = ranY + Math.random() * 100; circle.alpha = ranAlpha; circle.filters = [blur, glowBM]; addChild(circle); } mover(); addEventListener(Event.ENTER_FRAME, enterFrame); stage.addEventListener(Event.RESIZE, onResize); function mover():void { for (var i:uint = 0; i <= amountOfCircles; i++) { var object:DisplayObject = getChildAt(i); if (object == bm) { i++; } else { object.alpha = ranAlpha; TweenLite.to(object, 1, {x: ranX + Math.random() * 1000, y: ranX + Math.random() * 1000, alpha: 0, ease:Expo.easeInOut, onComplete:mover, blurFilter:{blurX:Math.random()*100, blurY:Math.random() * 100}, tint:Math.round( Math.random()*0xFFFFFF )}); glowBM.color = Math.round( Math.random()*0xFFFFFF ); glowBM.alpha = ranAlpha / 2; } } } function enterFrame(evt:Event):void { bmd.draw(stage); bmd.applyFilter(bmd, bmd.rect, new Point(0,0), blurBM); bmd.applyFilter(bmd, bmd.rect, new Point(0,0), glowBM); bmd.scroll(10, 0); } function onResize(evt:Event):void { bm.x = bm.y = 0; bm.width = stage.stageWidth; bm.height = stage.stageHeight; }
You can download the whole thing here: http://harry-northover-code-store.googlecode.com/files/Technophobia.zip
Harry.
October 5, 2008 1 Comment
Away3D Skyboxes
This is my best demo yet, and it is crucial to my new site. This demo is using the sky box features in Away3D. For those of you that don’t know what a sky box is, it is a collection of images (usually 6, but in this case 5, I didn’t have a bottom one), that are displayed on the inside of a cube, and then the camera is inside the cube looking out at these images. This gives the impression of a sky, and ground and surroundings that are usually behind everything else. Using sky boxes prevents the sky being plain black.
Here is the demo (just click). To explore, click and drag to find your way around.
And here is the code:
package { import away3d.cameras.HoverCamera3D; import away3d.containers.Scene3D; import away3d.containers.View3D; import away3d.materials.BitmapMaterial; import away3d.primitives.Skybox; import away3d.core.utils.Cast; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; public class SkyStuff extends Sprite { public var cam:HoverCamera3D = new HoverCamera3D( { zoom:2 } ); public var scene:Scene3D = new Scene3D; public var view:View3D = new View3D( { camera:cam, scene:scene, x:0, y:0 } ); // Skybox stuff. public var sky:Skybox; // Materials.... public var sky_front_material:BitmapMaterial; public var sky_back_material:BitmapMaterial; public var sky_left_material:BitmapMaterial; public var sky_right_material:BitmapMaterial; public var sky_up_material:BitmapMaterial; public var sky_down_material:BitmapMaterial; // Movement vars. public var move:Boolean = false; public var lastPanAngle:Number; public var lastTiltAngle:Number; public var lastMouseX:Number; public var lastMouseY:Number; public function SkyStuff():void { addEventListener(Event.ADDED_TO_STAGE, Init); } private function Init(evt:Event):void { InitStage(); InitEngine(); InitMaterials(); InitObjects(); InitListeners(); } private function InitStage():void { stage.align = StageAlign.TOP_LEFT stage.scaleMode = StageScaleMode.NO_SCALE; } private function InitEngine():void { cam.mintiltangle = -80; cam.maxtiltangle = 20; cam.targetpanangle = cam.panangle = 0; cam.targettiltangle = cam.tiltangle = 0; addChild(view); } private function InitObjects():void { sky = new Skybox( sky_front_material, sky_left_material, sky_back_material, sky_right_material, sky_up_material, sky_down_material ); sky.quarterFaces(); view.scene.addChild(sky); } private function InitMaterials():void { sky_front_material = new BitmapMaterial(Cast.bitmap(SkyFront)); sky_back_material = new BitmapMaterial(Cast.bitmap(SkyBack)); sky_left_material = new BitmapMaterial(Cast.bitmap(SkyLeft)); sky_up_material = new BitmapMaterial(Cast.bitmap(SkyTop)); sky_right_material = new BitmapMaterial(Cast.bitmap(SkyRight)); } private function InitListeners():void { addEventListener(Event.ENTER_FRAME, EnterFrame); stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown); stage.addEventListener(MouseEvent.MOUSE_UP, MouseUp); stage.addEventListener(Event.RESIZE, Resize); } private function EnterFrame(evt:Event):void { if (move) { cam.targetpanangle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle; cam.targettiltangle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle; } cam.hover(); view.render(); } private function MouseDown(evt:MouseEvent):void { lastPanAngle = cam.panangle; lastTiltAngle = cam.tiltangle; lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; move = true; stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } private function MouseUp(evt:MouseEvent):void { move = false; stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } private function onStageMouseLeave(evt:Event):void { move = false; stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } private function Resize(evt:Event):void { view.x = stage.stageWidth / 3; view.y = stage.stageHeight / 3; } } }
Now,I personally think skyboxes are a good piece of knowledge to have, as they provide, in my opinion, an effective and fairly easy way to get a fairly natural looking environment quickly. Once you have a skybox in place, you can concentrate on the more important objects, and not making the surrounding environment look good.
There is also another way of creating sky-boxes and this is using the Skybox6 class. This differs from the original method as instead of having six separate images, you have all your graphic in one jpg (png, or whatever).
I will also be trying to post versions of the examples in Papervision3d. This gives me a good understanding of how the engines differ, which ones I prefer and how they work.
You can download the whole thing (images as well!) here: http://harry-northover-code-store.googlecode.com/files/A3DSkyBox.zip
Harry.
September 28, 2008 3 Comments
Cool Away3D Example.
I just found this example over at Away3d.org and I have to say it is the best one yet!
Here’s the link: http://www.closier.nl/playground/railaway_express.html. This is a new demo/game to show of Away3D 2.2 new features!!
Enjoy, and good night.
Harry
September 27, 2008 No Comments













