Showing posts with label Flash. Show all posts
Showing posts with label Flash. Show all posts

Valentines Day

Tuesday, February 2, 2010

I'm a total nerd. I made this for my fiancée as fun way to find out where we are going to Valentines Day.
She has to unscramble four pictures one at a time. The four pictures are a Saint Helmet, Elmo, a plate with 2 steaks on it and House (the Dr. on the TV show). So you put them all together?
St. Elmo's Steak House!

I made all the graphics myself, given that I'm just a programmer I'd say I'm getting a little bit better.

I wrote a cool little class that animates the instructions dynamic text field. (in the top left hand corner)

Hexart

Here's what it looks like.
What is it? I've create a site where you upload any image you want and it goes through one block of pixels at a time, evaluating each blocks median color hex code and prints that value to screen. You can adjust the font size and the font density. Go ahead give it a try!

Here's some code for ya!

I wrote this bitmap slicer class. It works really well, just pass it a bitmap and how many slices you want to slice it into. Each slice is the same aspect ratio of the original image. The parameter "pieces" is the square root of the total squares that there will be. The more square, the more memory is use.

public static function Slice(origBitmap:Bitmap, pieces:int):Array{
var BitmapArray:Array = new Array();

var recX:Number = 0;
var recY:Number = 0;
var recW:Number;
var recH:Number;
var aspctRatio:Number;
var destBitmap:Bitmap;
var totalSquares:Number;

if(origBitmap.height > origBitmap.width){
aspctRatio = origBitmap.width/origBitmap.height;
recH = Math.floor(origBitmap.height/pieces);
recW = Math.floor((origBitmap.height/pieces)*aspctRatio);
totalSquares = Math.floor(pieces * (origBitmap.width/recW));
}
else if(origBitmap.height < origBitmap.width){
aspctRatio = origBitmap.height/origBitmap.width;
recW = Math.floor(origBitmap.width/pieces);
recH = Math.floor((origBitmap.width/pieces)*aspctRatio);
totalSquares = pieces * Math.floor(origBitmap.height/recH);
}
else{
aspctRatio = 1;
recW = (origBitmap.width/pieces);
recH = recW;
totalSquares = pieces * (origBitmap.height/recH);
}


var xPos:Number;
var yPos:Number;
var colCounter:Number = 0;
var rowCounter:Number = 0;
for(var i:int = 0; i < totalSquares; i++){
destBitmap = new Bitmap(new BitmapData(recW, recH),PixelSnapping.NEVER, true);
destBitmap.bitmapData.copyPixels(origBitmap.bitmapData, new Rectangle(recX+(recW*colCounter), recY+(recH*rowCounter), recW, recH), new Point(0, 0));
BitmapArray.push(destBitmap);
destBitmap = null;
colCounter++;
if(colCounter >= pieces){
colCounter = 0;
rowCounter++;
}
}

return BitmapArray;
}


This finds the median color of each bitmap slice

//this finds the mean color for a bitmap data
public static function get_median_hex(bd:BitmapData):uint{
var pixelValue:uint;
var red:Number = 0;
var green:Number = 0;
var blue:Number = 0;
var count:Number = 0;

for (var i:int = 0; i < bd.height; i++){
for (var j:int = 0; j < bd.width; j++) {
pixelValue = bd.getPixel(j, i);

red += pixelValue >> 16 & 0xFF;
green += pixelValue >> 8 & 0xFF;
blue += pixelValue & 0xFF;
count++;

}
}
red /= count;
green /= count;
blue /= count;
return red << 16 | green << 8 | blue;
}

Xml Namespace

I've loaded various xmlns through Url Loaders and sometimes you just can't parse them because you have to first import the namespace. Here's an example (cause I keep forgetting)

namespace media= "http://search.yahoo.com/mrss/"; //for flickr
use namespace media;
namespace media= "http://www.w3.org/2005/Atom"; //for Atom
use namespace media;

FlashWars

Tuesday, January 19, 2010

I finally wrote my own collision detection engine from scratch. This game may or may not mimic another game for a certain unnamed console. Earth is being attacked and it's up to you to save the world! There are two bosses you'll have to face before the earth can be set free of impending Armageddon via meteor attack! Get as many points as you can in order to reach them! High score is also implemented into the game(although I think my server is currently down, so you can play, but no high score).
I've implemented a few new ideas into the game. Time bombs, lasers, bosses and background graphics to name a few. A mouse is pretty much required to play this game, because you click and hold to shoot. Moving the mouse will move the direction of fire. You can toggle special weapons with "1", "2", and "3", while "W", "A", "S", and "D", move the player around the screen. Give it a try, just click on the picture!

The game actually ended up being a lot more work than I had originally planned. A lot of trig went into the enemy chase movements, as well as the firing direction.
It just needs music now....

The enemy graphics were created in flash, while the background images and some boss graphics were created in Blender
The Earth is from my Papervision Phong Shader demo. I found an Earth cloud map and warped it to the earth in Photoshop.

26 Actionscript classes, 1598 lines of code. I tried really hard to keep it as efficient as possible.

If anyone has any questions about the game or its collision detection engine, feel free to contact me.

Tetris

Monday, November 9, 2009

After years of programming, I had always wanted to make a game. I had heard that Tetris was a good place to start. I encountered many hurdles but successfully overcame most of them.

collision detection engine
an engine to remove tetris lines
look ahead rotation/collision detection

There are definitely still some bugs in it but it's close enough for now. Perhaps someday I'll fix the bugs but for now I really don't care:)

The graphic design was done by Ronnie Fenwick
The background images were from my flickr photostream and then filtered in photoshop.
Beta-Testing was done by many of my friends(greatly appreciated)
The music is from http://www.8bitdaily.com/ and used under the creative commons license
This website and it's content's composers are in no way affiliated with this Tetris demo application.

Google Maps API

Tuesday, October 6, 2009

Using Google Maps Api, I've created my own xml driven map program with completely customizable pop-ups and map locations. It's actually very easy and only took me about an afternoon to figure out.
Check out the xml file that drives it too.
There's still quite a bit of code that you have to write to interact with the api's libraries, but Google definately makes it easier.
Here's their online documentation.

Blades: Concept Image Gallery

Tuesday, September 15, 2009


I've been playing around with this for a long time and I finally decided to finish it. It's just a concept image gallery I've called Blades.
It's dynamically generated via an xml file and virtually everything (except the spinning pre-loaded and the images themselves) are created through code(All graphics and animations).

Hover your mouse over each image to expand the pane. Go ahead and try to break it. I DARE you!

AS3 Flash Vars

Tuesday, September 1, 2009

it's nothing new, I just keep forgetting how to do it. So here it is so I will never have to look it up again!


import flash.display.LoaderInfo;
try {
var allFlashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
img_path = String(allFlashVars["path"]);

if (img_path.toString() == String(undefined)){
throw new Error("FlashVars did not load");
}
}catch(e:Error){
//error_txt.text = "did not load flash vars";
img_path = "path_to_my_image.jpg";
}

The Green Room

Thursday, August 6, 2009


This is my most ambitious project yet. It integrates UV Mapping with a 3D model that I created in Blender. Also I've integrated a 3D interactive page flip using the as3mod library. It works with most flash 3D engines.

I created the 3D mesh in Blender, UV Mapped the mesh, exported to a .DAE file, and imported the .DAE into papervision at run-time. It works really well although I had a lot of performance issues at first with triangles z-fighting. It is a common problem with the papervision rendering engine.
After reading through many forums, I finally figured out how to solve this problem and keep my cpu cylces low. I used separate viewport layers for each object that was having z-fighting issues.

here's an example

var obj_layer:ViewportLayer = viewport.getChildLayer(my_3D_Display_Object);
obj_layer.layerIndex = 1;

//tell the viewport to sort by z-indexing
viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;

//I have an array of viewportLayers that I send to the rendering engine.
layers.push(obj_layer);


I was able to further tweak the performance by only removing things from the "layers" array that did not need updating once they've been rendered. For example...when you click on the book, the camera zooms in. Once it's stopped zooming in, it no longer needs to update the room mesh, just the book. So I remove the room's viewport layer from the layer array and viola...the rendering engine does not perform calculations on it until the user clicks the book's back button to return to the room view.

There are still a few z-index issues as well as camera rotation issues. The room does not spin, the camera spins around the room, I just constantly update the cameras degrees and run them through my formula, thus moving the camera in a circular motion around the 3D scene.


camera.x = 3800 * (Math.sin(degrees * (Math.PI/180)));
camera.y = 3800 * (Math.cos(degrees * (Math.PI/180)));
camera.rotationZ = (360-(degrees-180));
degrees += inertiaX;
if (!dragging) {
inertiaY *= .92;
inertiaX *= .92;
}

I also made the background design and the wallpaper myself in photoshop:)

Augmented Reality

Tuesday, July 28, 2009

This one takes a little bit of time and money to figure out. It's really really cool though. At a glance, Augmented Reality is just flash accessing your web cam, scanning for a specific pattern, and then orienting a 3D scene to that pattern.

Here are two demo's I've been able to build from it so far!

Phong Shader

Friday, July 10, 2009

Yes I know, another 3D earth! But this one is different. It's got a dynamic light source that gives a true feel of the earth rotating around the sun. Click and drag your mouse in any direction to change the POV and see the light source move with it. Very cool if you ask me:)
Sorry if it kills your cpu. Phong shaders don't play nicely with the CPU...oh flash when will you utilize the GPU. (CS4 says that it does but let's not fool ourselves)
I've created a phong shader material and have mapped a light source with a texture of the earth. thanks nasa:)

http://jakkd.info

Tuesday, July 7, 2009

jakkd.info is a biking website I made for my sister. She's going on a cross country biking trip with her friends and wanted a site to be able to update pictures and statuses...etc.
My co-worker made the graphics. There's a link to her site at the bottom of jakkd.info

jakkd are the initials of all the people on the trip. I tried to convince them it was a bad domain name, but you know how the clients can be.....

So any way, I made them a login page too so that they can securely update their entire site's contents as the want. Very cool if you ask me.
The back end CMS is written in C# and uses a SQL database. As always they comminicate through a web service.

There are 3 admin sections.
  1. Blog
  2. Route
  3. Gallery
The Blog section allows you to add/edit/delete any blog post
The Route Section is a drop down box that allows you to select any city name along the route of the trip and it will automatically connect the dots of every city they have ridden through, highlighting the current city location.
The Gallery section allows you to upload an image of any size. It will save a thumbnail version of it as well as a custome sized image for the actual flash gallery.

Garbage Collector

Wednesday, June 3, 2009

Throughout the past few applications that I've made at work, I've found constantly run into one problem that I spend a lot of time tweaking. Managing memory. Actionscript 3 does not automate this process very well. I've found a few helpful techniques to run the Garbage Collector at will, although I still feel that it is a wild and uncontrollable wind, I'm at least hopeful to control it.

GSSkinner explains the concepts really well.
http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html

One of my most used methods of manual garbage collection is to remove all children in a main section MovieClip, just before I remove it from stage.
for example


//remove all of the children
while(parent.numChildren > 0){
parent.removeChildAt(0);
}

//remove the parent
removeChild(parent);

//run the garbage colletor
import flash.system.System;
System.gc();

Also you can monitor the swf's total memory usage via
System.totalMemory;
I usually set up something like this


private var peak:Number = 0;
private function mem_test():void{
if (System.totalMemory > peak)
peak = System.totalMemory;

mem_txt.text = "current memory: " + (System.totalMemory/1024).toString() + "\r" + "peak memory: " + (peak/1024).toString();
}

setInterval(mem_test,1000);

3D Sound Spectrum

Thursday, April 30, 2009

Move your mouse around to get a fresh point of view!

I decided to mess around with some sound frequency animations using 3D cubes in papervision. It's a pretty beautiful application for such a simple concept.
Each squished 3D cube represents a sound frequency. There are 20 cubes and the human range of hearing is 20Hz - 20,000Hz (no longer mine thanks to years of guitar!). Therefore each cube is exactly 999Hz from its neighbor.

I've done a bunch of cool animations too! All of them done through code using tweens and lots and lots of trig:) Enjoy!

Primary Color Detection

Tuesday, April 28, 2009


I call it Studio Vibe. It shows off quite a bit of functionality I've been able to create. The main technology here being an algorithm to determine the main color of any dynamically loaded image. It then creates a pretty studio like background that inherits the loaded images main color.
My good friend Josh Pate helped me out a lot by telling me what functionality was good to leave or take out after I had round 1 finished.

This is using Papervision 3D of course, to accomplish the 3d effects you see going on with the camera. The application also uses my bitmapSlicer class, you can see demonstrated whenever you click on the picture, each papervision plane rotates on the x-axis.
The tricky part was resizing the Papervision planes when I load an image of a different size. I had to actually tween each planes verticies to stretch or shrink them to the appropriate size and constantly update the bitmapMaterial while doing so.
It was a bit more math than I had hoped, but I was able to figure it out:)

The images are all images I've taken myself and done some post processing in photoshop. You can find my images at my flickr page.

This Studio Vibe application serves best as a concept image gallery. I'd be glad to sell one to anyone who's interested:)

Now for some code

//I was able to get really close without googling for help
but thanks to blog.soulwire.co.uk for some missing pieces!
//this part finds the median hex color value of any image

public function get_median_hex(bd:BitmapData):uint{
var pixelValue:uint;
var red:Number = 0;
var green:Number = 0;
var blue:Number = 0;
var count:Number = 0;

for (var i:int = 0; i < int =" 0;" pixelvalue =" bd.getPixel(j,">> 16 & 0xFF;
green += pixelValue >> 8 & 0xFF;
blue += pixelValue & 0xFF;
count++;

}
}

red /= count;
green /= count;
blue /= count;

return red << update =" true;" number =" (slices[0].width" number =" (slices[0].height" int =" 1;" number =" -(loaded_content.width" number =" (loaded_content.height" vertex3d =" p.geometry.vertices[0];" vertex3d =" p.geometry.vertices[1];" vertex3d =" p.geometry.vertices[2];" vertex3d =" p.geometry.vertices[3];" vertex3d =" (p.getChildByName(" vertex3d =" (p.getChildByName(" vertex3d =" (p.getChildByName(" vertex3d =" (p.getChildByName(" index ="=""> 1 && index % num_sections == 0) {
yPos -= slices[0].height;
xPos = -(loaded_content.width / 2) + ((loaded_content.width/num_sections)/2);
}

index++;
}
}


Geocoding Earth

Tuesday, April 21, 2009

One of my most complex works yet. This 3D planet maps several Mercator Projections of the Earth (courtesy Nasa). You'll notice a reflection on the surface. (not really necessary but I like the effect).
That is achieved through a papervision EnvMap or Environment Map. A subtle glow effect is added around the earth to add atmosphere.

The coolest part of this app is the Geocoding. You type in any address in the world (include the city name) and it sends it off to google, who kindly returns me a latitude and longitude coordinates. I then project those coordinates using a sphere and placing it at the correct location, thus highlighting the exact address you typed in. (I had help with the formula from http://blog.zupko.info/?p=221 on this part.) Go ahead try it! (click on the image above)

Here's some code for ya!


//i've already loaded bitmap data from external jpg files into local variables cloud_texture, earth_texture, and bump_texture

var earth_Shader:GouraudShader = new GouraudShader(light, 0xFFFFFF, 0x111111, 30);

//EnvMap gives us our reflection, the bump_texture gives us the small peaks and valleys on the earth
var earth_env:EnvMapShader = new EnvMapShader(light, cloud_texture, earth_texture, 0x0034c1, bump_texture);
var earth_mat:ShadedMaterial = new ShadedMaterial(new BitmapMaterial(earth_texture), earth_env, 0);

//let there be stars!!
var stars:ParticleField = new ParticleField(new ParticleMaterial(0xFFFFFF, .4, 1), 500);
scene.addChild(stars);

var earth:Sphere = new Sphere(earth_mat, 50, 25, 25);
scene.addChild(earth);

//this accomplishes the blurred glow effect around our 3D Earth
var bfx:BitmapEffectLayer = new BitmapEffectLayer(viewport, 1000, 1000, true, 0, "CLEAR_POST", false, true);//very important to set the last param to true! Otherwise the glow will continue to concatenate to itself! AHHH!

var gf:GlowFilter = new GlowFilter(0x00aaf6, .2, 5, 30, 2, 1, false);
var ble:BitmapLayerEffect = new BitmapLayerEffect(gf);
bfx.addEffect(ble);
viewport.containerSprite.addLayer(bfx);
bfx.addDisplayObject3D(earth);


//GeoCoding Functions
//I have this built into its own separate class

//Google makes you use their API. I tried over and over to make a simple URLRequest to get the coords...it worked just great locally, but as soon as I posted it to the server..nothin.



import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.services.*

//You only get access to the geocoder once a new Map Object has been instantiated
public function GPS(stage:*){
map = new Map();
map.key = "my_google_maps_api_key_here";
map.addEventListener(MapEvent.MAP_READY, onMapReady);
map.visible = false;
stage.addChild(map);

function onMapReady(event:Event):void {
trace(map);
}
}

//when user clicks on the find button, receive address as string, and call back function for when processing is complete.
public function Get_Coords_From_Address(address:String, callBack:Function) {

//format the address for google maps api
var temp:Array = address.split(" ");
address = temp.join("+").toString();

//call their geocoder, it just makes a URLRequest with special params
var geocoder:ClientGeocoder = new ClientGeocoder();
geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, handleGeocodingSuccess);
geocoder.geocode(address);

//geocode received successfully now parse out latitude and longitude and return for mapping!
function handleGeocodingSuccess(e:GeocodingEvent) {
var t1:int = e.response.placemarks.toString().indexOf("@(") + 2;
var t2:int = e.response.placemarks.toString().indexOf(")");
var data:String = e.response.placemarks.toString().substring(t1, t2);
callBack(data);
}


//here is the callback function
function callBack(data:String){
trace(coords);
var lat:Number = parseInt(coords[0]);
var lon:Number = parseInt(coords[1]);

//convert_coords_to_rotation(lat, lon);
var phi:Number = (90-lat)*(Math.PI/180);
var theta:Number = (lon+180)*(Math.PI/180);

//create the marker
var marker:Sphere = new Sphere(new ShadedMaterial(new BitmapMaterial(new BitmapData(20,20,false,0x00aaf6)), new PhongShader(light, 0x00aaf6)),1,5,5);

//figure the spatial coords in which the sphere should be placed (will be placed directly over the address that the user entered..code courtesy http://blog.zupko.info/?p=221)
var fx:Number = (earth_radius+3) * Math.sin(phi)*Math.cos(theta);
var fz:Number = (earth_radius+3) * Math.sin(phi)*Math.sin(theta);
var fy:Number = (earth_radius+3) * Math.cos(phi);

earth.addChild(marker);
bfx.addDisplayObject3D(marker);

marker.x = 0;
marker.y = 300;
marker.z = 0;
marker.alpha = 0;
//animate the sphere into place from 300 pixels north
TweenMax.to(marker, 2, { x:fx, y:fy, z:fz, ease:Regular.easeOut, alpha:1 } );
}

3D models in flash

Thursday, April 2, 2009

This is probably the coolest thing I've done to date.
The shark was modeled by my friend Sean McDonald in Maya. http://www.vimeo.com/3057750

He simply exported it to a dae file which I dynamically load into papervision, and then I throw an envMap to it with a PointLight3D object.
The envMap is just a jpg texture and the PointLight3D makes the texture reflect light! It's really cool and really really simple to do!
The water/wave effect is just the perlinNoise effect seen in my previous water demos.
Here's some papervision code to wet your appetite!

//gives us a nice particle field of bubbles
var pm:ParticleMaterial = new ParticleMaterial(0x00CCFF,.3,
var pf:ParticleField = new ParticleField(pm,500,10,2000,2000,2000);

//creates the new point light
var light:PointLight3D = new PointLight3D(true, false);

//creates a new EnvMapMaterial to add to our shark, the bmap.bitmapData is bitmapData from a the jpg texture that I loaded dynamically
var envMap:EnvMapMaterial = new EnvMapMaterial(light, bmap.bitmapData, bmap.bitmapData);

//load the dae file
dae = new DAE();
dae.load("3dmodel.dae", new MaterialsList( { all:envMap } ));

//add it to the scene!
scene.addChild(dae);


Playing with Fire II

Friday, March 27, 2009


What can I say, I like to play with fire!:) Same concept as the below entry, but now you can type in your own name and choose a color! Click and drag to rotate in 3D space! Web 3.0? Try it out!

Playing with Fire

Thursday, March 26, 2009


This uses the BitmapEffectsLayer in papervision 2.0
Click and drag to rotate the 3D cube.

//start with a bitmap file material
var bfm:BitmapFileMaterial = new BitmapFileMaterial("imagePath", true);
bfm.doubleSided = true;

//next we add a bitmap effect layer
var bfx:BitmapEffectLayer = new BitmapEffectLayer(viewport, stage.width, stage.height);

//add the effect layer to the viewport
viewport.containerSprite.addLayer(bfx);

//create a materials list with all sides the same
var mlist:MaterialsList = new MaterialsList({all:bfm});

//bind the material list to a new 3D Cube
var cube:Cube = new Cube(mlist, 500, 500, 500, 2, 2, 2);

//add the cube to the effects layer
bfx.addDisplayObject3D(cube);

//now for the fire effect
var fire:BitmapFireEffect = new BitmapFireEffect(0, 1, .2, 1);
fire.smoke = 0;
fire.flameHeight = .5;
fire.fadeRate = .4;
fire.flameSpread = .5;
fire.smoke = 0;
fire.distortion = .4;

//you can also add a new flash blur filter (or any kind of flash filter) to the object
//bfx.addEffect(new BitmapLayerEffect(new BlurFilter(2, 2, 8)));

bfx.addEffect(fire);

//add the cube to the scene
scene.addChild(cube);

//Now render your scene!

Zelda Game

Sunday, March 22, 2009

So I grew up on the console games and I loved them! I've always wanted to figure out how to make one so I've decided to try to figure out how to make a sprite based game...like Zelda. For now I'm just using Zelda sprites until I get a good engine down.

So far I've come up with an efficient, but not great, collision detection engine. I'm currently trying to come up with a state system using bit-wise booleans and masking. I'll be updating my progress if you're interested in checking back often!