# Programming AI with Leaf/Creating Your Own Leaf
## Creating Your Own Leaf, a Tutorial

Adding a new person to Leaf
The following applies to version 01-01-07 only, although it may be a guide to other versions.
There are 2 parts to this process. One part is adding the person to the Leaf "brain" and the other loading up a reference image so Leaf can "See" you.
We'll start with adding you to Leafs brain. Not much point in Leaf being able to see you if Leaf doesn't know who s/he is looking at.
Note in some of the code snippets there is a 'characture in front of the word. This is important and it must be the correct punctuation mark otherwise the lisp compiler will give an error when you save the file.
In this example we will use the name “BOB” if you aren’t BOB then change BOB to your name.
First leaf needs to be able to understand you when you say your name. Go to “speech.xml “ and add
between
and
Then save the file.
Open “leaf.lisp” in the lisp editor (save a copy first in case you have problems)
First we need an object for the person.
Locate the line
This is the start of the area to add the new person.
Scroll down to just after
And before
Robin is the last person currently defined
Add a new person with the following code
Leaf now has an object to store you in.
Now you would like Leaf to play a game with you so locate the line
This is the start of where games are configured for each person.
Scroll down to the gap between
and
Gary is the last person to have a game defined. We will set bob to play “mine sweeper” We will also make Leaf more happy and less sad when we play.
Insert the code
We also want leaf to play music for you. We will use “mission impossible” & we will also make Leaf more happy and less sad
This is the following section so scroll down to between
and
And add the following
We want leaf to have feelings about us so we add a behaviour script.
Locate the line
and scroll down to between
and
Robin is the last person. Add the following
We can also update the lonely script so Leaf will ask for Bob.
Locate the line
and scroll down to
Add Bob to this line so it now reads
If we want Leaf to be able to like us best locate
scroll to the line
and change it to
Lastly we want Leaf to act when we say our name so locate the line
and scroll down to between
and
and add the following
Save and compile.
Leaf will now know who you are when you say your name.
Try saying
"leaf this is bob"
"leaf play some music"
Leaf should play "mission impossible"
Now we can add our picture so Leaf knows what we look like.
First make sure leaf is working and can see the camera.
Ask leaf “leaf who am I” leaf should respond with “you look like XXX ” where XXX could be Gary, Alex, Ana, or Bruce.
If Leaf responds with “I can’t see you” try moving so you are directly looking at the camera, as this appears to indicate that OpenCV could not locate a face in the image.
For me it works fine from about 18” through to 3 feet on a cheap web cam.
Once you have had leaf respond with “you look like XXX” you are ready to make Leaf recognise you.
Open the folder “C:\program files\leaf\leaffaces” in there you will find a file “image.jpg”. Note this image does not have a number at the end.
Open this file in an image viewer and check it looks something like you. It doesn’t need to be very good.
Rename this file to “image4.jpg” (assuming you already have images 0 to 3 which are Gary, Alex, Ana, & Bruce).
Open the file “names.txt” in the same directory and add your name to the end of the list. Use capital letters and a space between BRUCE and your name. Save the file.
Open the file “distances.txt” in the same directory and add the following
Note that there is a line between the last entry ant this new text and a blank line at the end. Save this file.
Now when you ask Leaf “Leaf who am I?” Leaf should respond with your name. and now the new and great moe!!