If you don't want to code the animation, you can use Animation Nodes to do that.
Animation Nodes is an addon which can be found here: https://github.com/JacquesLucke/animation_nodes/releases
Here is a setting that allows to influence a Z curve depending on the position of an empty object (but that can be almost anything including the current frame).
The principle is in two parts: a main loop and its execution for each iteration of the loop.
The main loop:
It starts from 2 parameters, a subdivided plane (1) and an empty (2).
From the plane, the vertices are extracted so that they are given as input for the execution function (7), and the other element (edges, polygons) are reported to be combine to a new mesh (4) and to create a new 'target' object (5).
From the empty, we take its location (6) which goes as input for the execution function (7).
Note that the plane can be either an existing object in the scene or generated by AN using a grid.
The execution function
We can see the defined inputs in (1).
The first input 'object vertices' is given by the calling node and corresponds to each vertex of the plane (the loop iterates giving 1 vertex per iteration, in this case).
The second input 'center' corresponds to the vector which is the location of the empty.
These two vectors are decomposed in (2) and (3) to get the coordinates we want.
In (4) additional parameters (they should be set outside of the loop, if needed).
In (5) an 'expression node' which takes all input parameters and allows to write the curve formula.
In (6) we recompose the vector, keeping X and Y from the input and Z from the formula.
(6) is given as output in (7) so that we can have it at the "upper level" (the loop 'caller').