Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-14-2009, 09:12 AM   #1
nikhiljoshi122
मैं एक भारतीय हूँ
 
nikhiljoshi122's Avatar
 
Join Date: May 2007
Location: delhi
Posts: 111
Send a message via Yahoo to nikhiljoshi122 Send a message via Skype™ to nikhiljoshi122
Default How to check For Identical MovieClips

hey All,
I am working on a game in which i need to compare two movieclips for being identical.
What i am doing is creating a complex shape out of some primitive shapes and then I allow the user to drag and drop some primitive shapes to recreate a similar shape.
My problem is how can I calculate that the user created shape is similar to the original complex shape or not.

I have already posted this once before but dun get any replies.
Hope to get some help this time.
nik
nikhiljoshi122 is offline   Reply With Quote
Old 11-14-2009, 07:00 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,833
Send a message via Skype™ to henke37
Default

Check for position and angle similarities.
henke37 is offline   Reply With Quote
Old 11-15-2009, 03:57 AM   #3
nikhiljoshi122
मैं एक भारतीय हूँ
 
nikhiljoshi122's Avatar
 
Join Date: May 2007
Location: delhi
Posts: 111
Send a message via Yahoo to nikhiljoshi122 Send a message via Skype™ to nikhiljoshi122
Default

Thanks for replying
But my complex shape is made of primitive shapes like circle ,square etc by randomly rotating and scaling them.
Its kind of an organic shape
How could I check another movieclip with my complex shape if it is identical or not.
nikhiljoshi122 is offline   Reply With Quote
Old 11-15-2009, 09:36 AM   #4
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,833
Send a message via Skype™ to henke37
Default

You check each part seperatly.
henke37 is offline   Reply With Quote
Old 11-16-2009, 12:00 PM   #5
nikhiljoshi122
मैं एक भारतीय हूँ
 
nikhiljoshi122's Avatar
 
Join Date: May 2007
Location: delhi
Posts: 111
Send a message via Yahoo to nikhiljoshi122 Send a message via Skype™ to nikhiljoshi122
Default

I think I am not able to clarify my doubt
Actually My complex shape is similar to underlying image

now if i allow a user to draw a similar shape with pencil tool with high thickness.
How can I measure is the two shapes are similar and if not then ant way of calculating the percentage similarity between two of them.
nikhiljoshi122 is offline   Reply With Quote
Old 11-16-2009, 12:20 PM   #6
box86rowh
FLEX AND FLASH ARE COOL
 
Join Date: Oct 2005
Posts: 794
Default

you could flop one on top of the other and then go through pixel by picel to see how many share the same surface area, then return them back to position
box86rowh is offline   Reply With Quote
Old 11-16-2009, 12:41 PM   #7
magicTuscan
Registered User
 
Join Date: Nov 2009
Posts: 46
Default

Quote:
Originally Posted by nikhiljoshi122 View Post
I think I am not able to clarify my doubt
Actually My complex shape is similar to underlying image

now if i allow a user to draw a similar shape with pencil tool with high thickness.
How can I measure is the two shapes are similar and if not then ant way of calculating the percentage similarity between two of them.
Easy:
Just store for every individual obj (movieClip) properties into an object array.
For example that blob you have.

ActionScript Code:
private var _objectProps : Object = []; function addObjectProps(targetObject:MovieClip) : void { var userBlobProps:Object = {                            "_userName": userBlobs.userName,                            "_width":userBlobs.width,                            "_height":userBlobs.height,                            "_color":userBlobs.color,                            "_rotation":userBlobs.rotation,                            "_scaleX":userBlobs.scaleX,                            "_scaleY":userBlobs.scaleY                            } _objectProps.push(userBlobProps ); }

So imagine am a user and i provided my name as magicTuscan, and I have created a new blob...via below

ActionScript Code:
private function newBlob() : void {  var thisBlobCreatedByUser: MovieClip = new UserBlob() as MovieClip; //code to draw and add blob to stage here userBlobs["userName"] = "magicTuscan"; //after all is done- now attach blob props to array & then you can compare later on!!! addObjectProps(thisBlobCreatedByUser); // thats it } private function compareBlobs() : void {   // do your comparing here }
magicTuscan is offline   Reply With Quote
Old 11-16-2009, 02:36 PM   #8
-Ev-
Senior Member
 
Join Date: Aug 2008
Location: Boston, MA
Posts: 241
Default

When you're ready to compare the two drawings, you can use the BitmapData class to compare them.

1. Use BitmapData.draw() to draw both clips into BitmapData objects with the same dimensions.
2. Use the BitmapData.compare() method, which will return a NEW BitmapData object, in which the pixel RRGGBB values are the DIFFERENCE between the compared bitmaps. If two pixels in the compared bitmaps were identical, the resulting BitmapData will have a black pixel at that (x, y) coordinate.
3. Use the BitmapData.threshold() method to check if every pixel is greater than 0x00000000. It doesn't matter what color you change the pixels to, since this is a disposable BitmapData object. The key to this step is that the method returns the number of pixels that were changed.
4. Divide the number of changed pixels by the total pixels of your bitmap objects (width x height), and that will give you the exact percentage difference between the two drawings.
__________________
Tweet Tweet
-Ev- is offline   Reply With Quote
Old 11-17-2009, 01:44 AM   #9
nikhiljoshi122
मैं एक भारतीय हूँ
 
nikhiljoshi122's Avatar
 
Join Date: May 2007
Location: delhi
Posts: 111
Send a message via Yahoo to nikhiljoshi122 Send a message via Skype™ to nikhiljoshi122
Default

Hey Ev thanx a ton
I was was looking for a solution like this only.
great.
nik
nikhiljoshi122 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:58 AM.

///
Follow actionscriptorg on Twitter

 


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