Projects

A face that follows your cursor

The effect on the home page of this site. A face I filmed looking at 117 pieces of tape on my wall, turned into 925 photos that follow your cursor.

The idea started as a simple play video on scroll effect. I wanted to pre-record a video of myself looking in specific directions, play it back as you scroll and show page elements in those places. While I was building it, I thought it would be cool if the cursor could control my head instead.

The home page. The cursor is at the top right on the left and at the bottom left on the right, and the face looks at it.

I started with a very small proof of concept: separate photos of me looking in a few directions, top left, top centre, top right and so on. Moving the cursor would display the right image based on the position of the mouse on the screen.

The wall and the shoot

For this small POC, making the images was easy. I only took images for a 3x3 grid, so 9 images in total. After the POC I wanted to scale up. I started with 5x7, so 35 images. Later I added even more dots in between for a 9x13 grid (117 images). This was already way harder to look in a certain direction precisely. Every image should just be a little bit different from the frame next to or above it. To make that easier, I taped the points on my wall, so every direction had an actual spot to look at. Taking one photo per point was difficult too, because every time I touched my phone to take the picture, I moved my face a little bit. I also didn't have a trigger button to take the picture from a distance.

The wall. Each piece of tape is a place to look.

So instead I made a small audio guide that plays on my laptop, and filmed one continuous take. The phone, an iPhone 17 Pro, stood on the mantelpiece in the middle of the grid, facing away from the wall and towards me. I made sure the lens of the phone was placed at the centre point of the grid, so looking straight at the camera is exactly looking at the centre.

The guide cues me to look at a dot. I look at it and wait for the beep, that is the moment to extract the frame from. Then the guide moves on to the next point, I turn my head, and I wait for the beep again, and so on.

After recording, I upload the video to the tool, and it extracts the frames from the guide's timings. I can step to the next or previous frame when one looks better.

The tool and the in-betweens

Besides extracting the frames, the tool shows all of them in one grid.

All 117 frames in the tool, one per piece of tape. The middle one is where the lens was.

When I open one, I can see about a second of video around its beep, and the neighbouring frames next to it, so I can check if the gaze fits its row and column.

One frame opened. The neighbouring frames are on the right and the video around the beep is below.

With only the 117 real photos it wasn't smooth enough. When I moved the cursor, there was a very noticeable switch between the frames, so it looked very robotic. So instead of adding even more points, I tried generating the photos in between. For that I used RIFE, a model made for generating frames between two video frames. I can give it two neighbouring photos and the tool generates two photos between them, and then it sharpens them so they almost match the real ones. That turns the 9x13 grid into a 25x37 grid with 925 photos, 117 real ones and 808 generated ones.

The generate step. Two AI frames between stills makes 37x25 = 925 frames, 117 from the video and 808 generated.
All 925 faces, 37 columns by 25 rows.
The bright photos are real, 117 of 925. The dark ones are generated.
Four photos next to each other. The first and last are real, the two in between are generated.

The dithered look

The site has a black and white dot look, so the face blends into the page. A script converts every photo to that look: it makes the photo greyscale, adds a soft falloff of light around the face and then dithers it, which turns the grey into black and white dots.

For the dithering I used blue noise. It keeps the dots on a fixed pattern, so when the head moves one cell, only about 2% of the pixels change. A common alternative changes about 29%, and the image shimmers. That is why the movements feel a lot smoother.

The same photo before and after the dithering.

Loading the photos

The first version of the portfolio loaded every photo and kept all of them decoded in memory. I noticed the loading was slow, because there were a lot of images. After moving the cursor around, memory was at almost 3 GB on desktop and about 560 MB on a phone. It also made 925 requests, and the browser logged 38 long tasks in the first 20 seconds.

So I changed how it loads. The photos stay compressed, and only the ones around where the face is looking get decoded. The cache is 160 MiB on desktop and 48 MiB on a phone. The engine also tells the loader where the gaze is going, so the next photos are decoded before they are needed.

The order changed too. The 117 real photos load first, as one file per size. After that the in-betweens load, the ones closest to where the face is looking first. On desktop a small atlas fills the gaps until the rest has loaded. The atlas is one image (about 0.5 MiB) with all 925 faces in a very small size, so there is always something to show.

The atlas the site loads first: all 925 photos in one dithered image.

The photo URLs have a hash in them and are served as immutable, so a second visit only requests the manifest, a small file that lists every photo's URL. The photos themselves come from the browser cache.

After this, memory after moving the cursor went from almost 3 GB to 159 MB on desktop and from about 560 MB to 48 MB on a phone. The long tasks went from 38 to 3. On desktop the face now follows the cursor after 1.7 to 2.0 seconds (before 2.2 to 2.7), and on a throttled phone after 3.0 to 3.5 seconds (before 5.4 to 9.4).

There is a downside. When you move the cursor very fast, the exact photo is shown in about 76% of the frames (before 100%). In the other frames a neighbouring photo is shown for a moment. A bigger cache would improve that, but that also uses more memory.

Built with