Ever wanted to know how you look like with a clown nose? You only need a few bricks and the face recognition function of your phone to make your own snapchat filters! Start right now…

What bricks and objects do you need?

Create a new program and add the following object from the media library:

Now add these scripts to the Hat object:

1. Step

At first you want to activate your camera as soon as the program starts.

2. Step

Now add a forever loop to continuously check if a face is in front of the camera.

3. Step

You actually need to check if the camera detects a face. Therefore you need an if-else-brick. In the condition of the brick insert the sensor value: “is_face_detected” which you find under the category: “devices” in the formula editor. So if your phone’s camera detects a face, your object should be shown, else insert a hide-brick in order to hide it.

4. Step

Every time the camera is detecting a face, your object is shown on the screen. Now you need to add movement to the object so it stays on a certain part of your face. Pick the place at X: Y: – brick and insert into the x-position field the sensor value “face_x_position” which you find under “devices” in the formula editor. Into the y-value field insert “face_y_position + 500” since the object is a hat.

5. Step

For the last step you need to make sure that our hat adjusts according to your face size. If you are close to the camera you want a bigger hat, if you are further away a smaller one.  Therefore add the set size to-brick and insert the sensor value “face_size”. Multiply this value with a certain number to fit your object to the correct size. In this case we choose to multiply it by 5 but you can try different values to get your perfect result.