news
media
projects
links
styles
about
feeds

August 12, 2004

[AS 2.0] Distance Functions

First code posting, this is going to messy.... (attempt #2)
/* Returns the distance between two MovieClips */
function getDistanceMC(mc1:MovieClip, mc2:MovieClip):Number {
	var dx:Number = mc2._x - mc1._x;
	var dy:Number = mc2._y - mc1._y;
	var d:Number = Math.sqrt((dx * dx) + (dy * dy));
	return d;
}

/* Returns the distance between two points (x, y) */
function getDistanceXY(x1:Number, y1:Number, x2:Number, y2:Number):Number {
	var dx:Number = x2 - x1;
	var dy:Number = y2 - y1;
	var d:Number = Math.sqrt((dx * dx) + (dy * dy));
	return d;
}

/*
// Returns the position in given array of the closest MovieClip 
// to given MovieClip.  Returns Null if the closest is 0, the
// array is empty, the only MovieClip in the array is the given
// MovieClip.
//
// Array Format: [mc1, mc2, mc3, mcn, ...]
//
// Dependencies: getDistanceMC();
*/
function getClosestMC(mc_array:Array, mc:MovieClip):Number {
	var aNum:Number;
	var cDist:Number;
	var lDist:Number = Infinity;
	for(var i = 0; i < mc_array.length; i++){
		if(mc_array[i] != mc){
			var cDist = getDistanceMC(mc, mc_array[i]);
			if(cDist < lDist){
				lDist = cDist;
				aNum = i;
			}
		}
	}
	return aNum == undefined ? null : aNum;
}

/*
// Returns the position in given array of the closest point 
// to given x, y coordinates.  Returns Null if the closest is 0, 
// the array is empty, the only point in the array is the same
// as given coordinates.
//
// Array format: [{x:10, y:10}, {x:20, y:20}, {x:15, y:15}, ...];
//
// Dependencies: getDistanceXY();
*/
function getClosestXY(xy_array:Array, x:Number,y:Number):Number {
	var aNum:Number;
	var cDist:Number;
	var lDist:Number = Infinity;
	for(var i = 0; i < xy_array.length; i++){
		var cDist = getDistanceXY(xy_array[i].x, xy_array[i].y, x, y);
		if((cDist < lDist) && (cDist > 0)){
			lDist = cDist;
			aNum = i;
		}
	}
	return aNum == undefined ? null : aNum;
}

By: Dustin DuPree

Add Comment

August 12, 2004

New News Sections!

In an attempt to organize these news posts I've implemented a new news system. From now on when you go to Dujodu.com the default news page will be "Updates" which will be strictly page updates (well, maybe not so strick... but mainly). Anything that is more about me, my life, or something not pertaining to the webpage that I feel like writing about will now be in the "Blog" section (click on "news" on the left bar). Unfortunately this means that there will probably be more mindless ramblings in the blog section, so I apologize in advance. I'll try to organize the previous posts accordingly, but most of them contain some "blogging" as well as some site news.

You may also notice that there is a third section under "news" called "code." Here I will put code snippets that I make or find reading a forum that I think are worthy of remembering and/or displaying for others to read. I'll label in the title what it is for and what language it is using. There are currently none so you'll probably get an error if you click on it, but that will be changed soon probably.

Since I'm going to be shifting previous posts around, I'll say again that there are going to be two new media sections coming soon. They will be Traditional Art (physical stuff, sculptures etc...) and after that Movies. I'm not sure when this will happen, but probably soon.

Lets see if the new code holds up or if I have to rewrite this....

By: Dustin DuPree

Comments(27)

August 4, 2004

the days slip away.....

The summer is slipping away, and with it is my motivation to do anything other than play video games and watch TV series/movies on my computer. On the plate this week was Doom 3 and some Upright Citizens Brigade. Unfortunately it's been kinda hot out, so my motherboards South Bridge has been overheating while playing Doom 3. I'm ordering a new North Bridge heatsink though, so I'm going to slap the stock NB heatsink onto the South Bridge and that will be that. In other news of my boring life, I saw a kick ass Sonic Youth concert the other day. Great show. I also picked up Colin Moock's new book "Essential ActionScript 2.0" and it's pretty cool, I highly recommend it. Using that link to purchase will get him some commission, I'm sure he would appreciate it. It's a really good deal there too!

I really do plan on adding a new media section with some new stuff soon, I think I'll just do it and worry about the database structure later. If anyone cares, the new section is going to be Traditional Art (ooooooh non-digital! Dustin can operate without computer assistance?). I've also taken a liking to C# recently, so if I ever make anything worthwhile maybe I'll have to make a section for that too.

For anyone not wasting their time reading comments, my pal Eric recently updated his site. Check it out here. You can read all about the last 8 months of his life, kind of.

By: Dustin DuPree

Comments(47)

recent media

Perfect Paradigm by Dustin DuPree
Perfect Paradigm
Flash Levels by Dustin DuPree
Flash Levels
Motion In Flash by Dustin DuPree
Motion In Flash