# Eyes that follow the cursor in QGIS

I did this all in some random EPSG:25832 location and scale, this uses several magic numbers that make it work for that. I did not make it work for any CRS or canvas size. If you do, please share. But this is just silly fun so …..

Have two polygons for the eyes.

Set their Symbol Layer Type to Geometry Generator and smooth them:

`smooth(\$geometry, 3)`

Add another Geometry Generator symbol layer to it and throw in the following magic expression to build the pupils. It calculates the distance from your cursor to the centroids of the polygons and it prepares a line from each centroid to the cursor. Then it places a point geometry onto that line at a fraction of the distance. Use the Geometry Type “Point / MultiPoint” for this Geometry Generator.

```with_variable(
'distance',
distance(@canvas_cursor_point, centroid(\$geometry)),
with_variable(
'line',
make_line(centroid(\$geometry), @canvas_cursor_point),
line_interpolate_point(@line, @distance/5)
)
)```

Set the layer itself to automatically refresh its rendering in the layer’s properties:

Now the eyes will follow your cursor as it moves across the map canvas!

Task for you: The pupils are not clipped and can exit the eyes. Oops! Head over to Topi’s for a hint how to solve this: https://twitter.com/tjukanov/status/1278689814288760837

And then you paint the rest of the fucking owl:

Those are lines with 3 vertices each:

And the middle vertex is moved vertically using the expression below. Basically the line is reconstructed.

```smooth(
make_line(
start_point(\$geometry),  -- first point is kept
translate(
point_n(\$geometry, 2),  -- second point is translated
0,
distance(
@canvas_cursor_point, centroid(\$geometry)
)/10  -- move according the cursor distance to centroid
),
end_point(\$geometry)  -- last point is kept
),
4
)```

Here is my project file including the temporary scratch layers (use the awesome Memory Layer Saver plugin to have them loaded automatically):

This site uses Akismet to reduce spam. Learn how your comment data is processed.