Javascript :: Fastest Way To Do A Collection Subtraction?
Mar 8, 2010
I have two Sets. Set b is the subset of Set a. they're both very huge Sets. I want to subtract b from a , what's the best practice to do this common operation? I've written to many codes like this , and I don't think it's efficient.
I am working on background subtraction with a webcam. I have an event listener for a mouse event which takes a snapshot from the webcam, then I draw the difference between what the webcam sees (video) and the still image that has been taken by the webcam on a mouse click. I want the webcam to take a picture of an empty room and then to show a silhouette of whoever walks into the room after that, but I am having trouble getting just a plain silhouette (the webcam remains in the same position as when the mouse is clicked). I have tried thresholding, but with that method I am getting detail inside the silhouette.
If anyone could just give me a plain english explanation of how the threshold object works, in particular the 'mask' parameter, that would be a huge help and also the 'draw' function, as I think that is where the key may lie!!
i'm trying to subtract a very small value from given height.
myMC._height -= .05;
it just doesn't subtract anything. so is flash ignoring to subtract it, possibly because i've too much in my flash file? then again, this works: myMC._height -= .20;
I have a divided box that has 3 panels in it... when a certain tab in tab navigator is clicked, then the sidebar with the three panels changed. One tab might show one Panel, another tab might show two of the panels and so on.
I can turn panels invisible and hide the dividers and ever almost positions the panels right, but the dividers still exists so it's not as dynamic as I would like.
Is their an easier way to add and remove panels from the Divided box that won't take as much manual configuration and hacking to make look right?
The problem is once I hide a panel the divider still exists.
create a random subtraction equation where the result will always be positive? For example, my current scripting will return something lilke 3-6=-3. I don't want equations like this- only postive answers
//random numbers//1.function randomNumbers(min:Number,max:Number) var Results:Number=Math.floor(Math.random()*max)+min; return Results;} //2.new_mc.addEventListener(MouseEvent.CLICK, showRandomnumber);
LinkeSetFx has its own CollectionEvent, but I don't know how to map the LinkedSetFx event to mx.events.collectionEvent(I want use it in ComboBox). LinkedSetFx is in AS3Commons-collection framework.Here is the url, choose the as3commons-collections-1.0.0.zip, you'll find LinkedSetFx in srcorgas3commonscollectionsfx
I have the following function in my FogOfWar class, it calculates if its team can see the position that is passed on the arguments:[code]My problem is that, with only 3 characters in the game, it can only run 4000 times per second, which is not too much.I can implement a cache, so it caches the most commons positions, but, what else can I do to optimize it?
The question is simple; I need the fastest way to calculate power 2. I need that for this formula which calculates distance between 2 points.var Dist:int = Math.sqrt( (mmx - ox) * (mmx - ox) + (mmy - oy) * (mmy - oy) );
I'm trying to figure out the fastest possible way to load a .png image into a BitmapData object. I am performing multiple processes that do this (load a .png from filesystem). The progress is shown using a loading bar, and I would like to speed up the loading time. Now this process can be called over n number times (via a timer). Right now the method I am using to this is:
I have searched google for an answer to my problem, but to no results have helped me to solve it. I am trying to find the fastest possible way to load an external .png (as the title suggests). The reason for this is because I want to speed up the loading time of my Adobe Air Application. It loads in a various number of .png files (with transparency) and displays them in a tilelist via Bitmap.
When I get a collection back from the service tier, I create an ArrayCollection and apply a sort. When I add an item to the collection later on, the sort is still in place? It seems to be the case. I thought I was only sorting it once, not applying a sort that will stick??Here is the method for adding an item:
private function onAddNewClick():void { var fileTemplate:FileTemplateDetailDTO = new FileTemplateDetailDTO();
I have an array, crewPositionsAC that contains a list of position abreviatations - EP, PR, DR, WR, and so on. These positions are read in through an XML file each time my flex application loads. Also being populated from an XML is a project. Within a project, there are positions (a student assigned to a type of position listed within crewPositionsAC). These positions are not necessarily in the correct hierarchy order dictated by crewPositionsAC. I have all the positions within an ArrayCollection (positionsAC) with the following structure:
Then, the user can click a button to add another position. When the "Add Crew Member" button is pressed, the user is presented with a list of possible positions to add. Currently, I simply add another array to positionsAC. This results in the recently added crew member to placed on the bottom of the list. I need to take positionsAC and reorder it based on it's [2] item (role) based on the hierarchy defined in the crewPositionsAC. crewPositionsAC has the following structure:
crewPositionsAC: [0] = EP [1] = PR [2] = DR [3] = WR
* continue until all possible position types are listed
This code calculates the distance between 2 points by using distance formula, Math.sqrt ( (x1 - x2)^2 + (y1 - y2) ^2). My first point has mmx and mmy coordination and second one has ox and oy coordination. My question is simple, is there any FASTER way for calculate this?
Im using a lot of movieclips in an app.Its hitting the performance limits.Im using .png files in animated movieclips.Looking in the clip it says bitmap as type.. source...pngI used .png because i want the alpha background possibility.I then went into some of the movieclips and changed properties convert to bitmap (althoug technicly they already were according to flash)After this i feel the performance has slightly improved.Is this true or just in my mind & wishfull thinking.
I need to know the best method to find an item inside a list (Vector, Array, Dictionary, whatever is faster) of complex type (extensions of Objects and Sprites). I've used "Needle in Haystack" method, but it seems that it isn't fast enough.
E.g. Suppose that I have a collection of Sprites (a pool, in fact). Each sprite will be added to the stage and perform some action. After that, it will die. I don't want to pay the cost to dispose it (garbage collect) and create another (new) one every time so I'll keep the dead sprites in a collection.
Sometimes times I'll call a method that will add a sprite to the stage. This sprite can be a old one, if it is already dead, or a new one, if the pool don't have any free sprite.
One of the scenarios that pushed me to this question was a Particle System. A "head" particle leaving a "trail" of particles every frame and exploding into a flashy multitude of particles... Every frame...
Some times this counts up to 50.000 PNGs with motion, rotation, alpha, event dispatching, scale, etc... But, this is JUST ONE scenario...
At the moment I'm trying to use a Object Pool with a Linked List... Hopes that it will be faster that running a whole Array/Vector or create new instances every frame an let them dye with Garbage Collection.
I've got my 3D sphere to triangle collision detection working now, but I need an efficient method of adding the triangles to the broadphase grid.
This is easy enough if the triangles are smaller than the grid nodes, however - especially given the polycounts I'm working with - it's going to be fairly frequent that a triangle is significantly larger than the grid nodes.
Here's an example.See the yellow polygon? Just adding it the grid nodes by it's vertices results in it NOT being added to 4 grid nodes that it does reside in.
My first thought is repeatedly casting rays along one of the edges from the normal of the edge until you find the intersection point with one of the other edges, of course checking for intersections with the grid edges until you reach the destination intersection with one of the other edges of the triangle. This would work, but is not particularly fast.
Although these triangles aren't being added/removed in real time, only when building the level, when constructing a level with say 100,000 polygons total, I obviously want it to be processed as quickly as possible.
I'm trying to write a function where I can specify any amount of array, and the return value will be an array containing the contents of all of the specified arrays.I've done this, but it seems like a really slow and ugly way of doing it:
var ar1:Array = [1,2,3,4,5,6,7,8,9]; var ar2:Array = ['a','b','c','d','e','f','g','h']; function merge(...multi):Array[code].....
Is there an inbuilt and more efficient / nice way of achieving this? The result does not need to be in the same order as the input - completely unsorted is fine.
In my flex application im using two datagridfirst datgrid is for items collectionssecond is for bank details.if i click one row in first datagrid (which has the items collections)...a unique code is taken from the grid(which is primary key).then, i have to select two or more banks using itemrenderer checkboxes in second datagrid(which has the bank details)ow, have to bind the bank details(one or more banks) with that one primary key in first datagrid. to an single array collection... and have to show it in another new datagrid(thirdone)
It is known that a display Object removed from the display list will be garbage collected only if any event listener associated with it is removed.What I would like to know, but could not anywhere find an answer to, is that for a class that we create which extends, say Sprite, and uses and manipulates various other display elements within it, while removing an instance of this class from the display list is it sufficient to remove the event listeners associated with the instance of the class, or do we necessarily have to remove all internal event listeners of the class definition associated with the display objects that the class uses and manages.
public function MovePath(ob:MovieClip) { ob.x = 458; ob.y = -5;[code]....
in the tweenmax there is a variable container "{x:458, y:-5},{x:458, y:153}, {x:212, y:254}, {x:208, y:606},{x:208, y:1000}".but i want it to work like this:
public function MovePath(ob:MovieClip,path) { ob.x = 458; ob.y = -5;[code]....
I understand that Objects not referenced by anything are garbage collected, and have been making sure to null out referenced to objects when I'm done with them. What I want to know are a few things:Do only Objects need to be null-referenced?How often does garbage collection usually run? Does it tend to run when processor demand is low? Is there a way I can tell garbage collection to run manually, such as when I'm done with a playing field full of sprites? This is not really needed if garbage collection tends to run when processor use is low, since it will run anyway at the times I'd like it to.Objects created just for the scope of an if or for statement etc, unless they are assigned a reference elseware, are eligible for garbage collection, right?
I have a question about garbage collection: I am using a MVC pattern for a photo gallery website.Every view displays a thumb viewer/controller and an image loader. Each view extends an abstract class that has a close() method that looks like this
PHP Code: //AbstractViewer class public function close():void {
How do I write a combination of XML declarations and Actionscript classes such that I can initialize each of my three lists from XML?
note that I am not trying to populate a Flex UI element (such as a DataGrid) with the various number-name pairs. I'm just trying to read the data into a plain old vanilla collection. (Once I've got my collections initialized, I can populate DataGrids or whatever at my leisure.) I can't find any documentation of how to address this super-simple case. The documentation all assumes that I'm trying to do something much more complicated, such as accessing a remote database, which confuses the issue tremendously.