Thursday, 08 January 2009
 
  Home arrow Forum  
Main Menu
Home
News
Forum
Documentation
Download
Links
Administrator
Login Form
Welcome, Guest. Please login or register.
January 08, 2009, 01:31:19 PM
Username: Password:
Login with username, password and session length

Forgot your password?
Simple shape identification example
DSLua Community
Welcome, Guest. Please login or register.
January 08, 2009, 01:31:19 PM
1724 Posts in 316 Topics by 10297 Members
Latest Member: bepNepedurnem
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Examples/Tutorials  |  Simple shape identification example « previous next »
Pages: [1]
Author Topic: Simple shape identification example  (Read 3016 times)
Zhen
Waxing Crescent
**
Posts: 57


WWW
« on: June 20, 2006, 03:43:39 PM »

Hello everyone,

I was working in a shape identification module, as Lost Magic Game, and i code something that work quite well. So I upload it.

The shapes that identifies are triangle, square and Z. I upload a jpg to show the shapes. Sorry for the poor quality :-P. It's easy to add more shapes, but I don't know the perfomance, maybe the sqrt function is too much.

Zhen.

update: I change the precision for detect shapes.


* shapes.JPG (3.55 KB, 249x95 - viewed 375 times.)
* detect.2.zip (1.99 KB - downloaded 200 times.)
« Last Edit: June 21, 2006, 01:06:42 PM by Zhen » Logged
daltonlaffs
Waxing Gibbous
****
Posts: 340


Freaking Insane


WWW
« Reply #1 on: June 21, 2006, 10:21:46 AM »

EH, it really won't work. Keeps saying <<<Nothing>>> Sad
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Zhen
Waxing Crescent
**
Posts: 57


WWW
« Reply #2 on: June 21, 2006, 01:11:07 PM »

Ups, I put a too much restric mean of 0.2. I check it and change to maximum mean of 0.3 to accept a shape.

I show a ...ejem.. perfect triangle draw by me.

Zhen


* triangle.jpg (7.32 KB, 256x384 - viewed 369 times.)
Logged
angor
Waxing Crescent
**
Posts: 55


WWW
« Reply #3 on: June 21, 2006, 06:08:14 PM »

Ups, I put a too much restric mean of 0.2. I check it and change to maximum mean of 0.3 to accept a shape.

I show a ...ejem.. perfect triangle draw by me.

Zhen

Indeed now it works! Very nice. Any sneak peek of the game you are developing and where you plan to use this shape recognition code? Smiley
Logged
daltonlaffs
Waxing Gibbous
****
Posts: 340


Freaking Insane


WWW
« Reply #4 on: June 22, 2006, 12:16:20 PM »

Wow! It really is good! I changed the max mean to 0.4 and it works perfectly! I shall add more shapes! HAHA! Fire! Ice! Earth! Light! Dark! Wind!

Voila! Copycat of Lostmagic's first 6 spells! YES!  Tongue

Wow, Zhen. You did it again Smiley
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Zhen
Waxing Crescent
**
Posts: 57


WWW
« Reply #5 on: June 23, 2006, 05:31:07 AM »

Indeed now it works! Very nice. Any sneak peek of the game you are developing and where you plan to use this shape recognition code? Smiley

I have no project in mind for this. I like combat system of Lost Magic, and try to reproduce it.
Logged
daltonlaffs
Waxing Gibbous
****
Posts: 340


Freaking Insane


WWW
« Reply #6 on: June 23, 2006, 07:18:11 AM »

Hmph! Well, Zhen, maybe YOU don't have anything in mind for this, but can I use it in MY code? Please  Kiss

If I used this, I could change the line that makes the text depending on what you drew to a trigger function!
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
daltonlaffs
Waxing Gibbous
****
Posts: 340


Freaking Insane


WWW
« Reply #7 on: June 23, 2006, 06:55:28 PM »

Double posting feels bad  Shocked, but Zhen, it took me a few tries to get your program to accept my shapes. I think I get it, but can I have a solid tutorial on how to set up shapes  Cry?

Thanks,
Daltonlaffs
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Zhen
Waxing Crescent
**
Posts: 57


WWW
« Reply #8 on: June 24, 2006, 03:00:52 PM »

Hmph! Well, Zhen, maybe YOU don't have anything in mind for this, but can I use it in MY code? Please  Kiss

If I used this, I could change the line that makes the text depending on what you drew to a trigger function!

Of course you can use it in your code. I made it for DSLua community. And made the changes that you need.

Zhen
Logged
Zhen
Waxing Crescent
**
Posts: 57


WWW
« Reply #9 on: June 24, 2006, 03:13:29 PM »

I made a few changes to shape identification.

The first one is add a canvas for draw. You can write
Code:
Shapes.canvas  = { {80,16}, {240,176} }
to get the figure from that rectangle. You can draw out of the canvas, but the original shape to compare is in that canvas.

And now a little tutorial about shape definition. By example:

Code:
Shapes.list = {
    {
        name = "Triangle",
        F = {
            { t=0, p={ 0, 0.8 } },
            { t=0.33, p={ 0.5, 0.2 } },
            { t=0.67, p={ 0.8, 0.8 } },
            { t=1, p={ 0, 0.8 } }
        }
    },
    {
        name = "Square",
        F = {
            { t=0.00, p={ 0, 0 } },
            { t=0.25, p={ 0.8, 0 } },
            { t=0.50, p={ 0.8, 0.8 } },
            { t=0.75, p={ 0, 0.8 } },
            { t=1.00, p={ 0, 0 } }
        }
    }
}

Shape.list is the list of shapes that algorithm identifies. In the example two shapes, Triangle and Square.

The shapes are defined by a list of points. The points are a tuple of t (time) and p (point). All the shapes have ordered points from t=0.0 to t=1.0. This is the normalized form of a shape. The points are in a bidimensional canvas from (0.0,0.0) to (1.0,1.0). The first point is the left-top corner of canvas and the second one is the right-bottom corner of the canvas.

The points of the shape define where should be the player pen when shape is draw. In the example Triangle. at 0.33 time it should be near point (0.5, 0.2).

An that's all. ... Well, the player draw shapes in a (0,0) (256,192) screen and time > that 1 second. But the function Shape.Normalize(...) convert the player shape to a Shape in the 0..1 canvas and the 0..1 time.

Zhen.
Logged
Pages: [1]
« previous next »
    Jump to:  



    (C) 2009 DSLua

    DSLua - Best scripting language for Nintendo DS home-brew!