For functions, you can use GLSL, version is WebGL 2.0 (GLSL 300 es).
Quick help: Shaderific A bit deeper: Khronos Wiki


Wirting helper functions are permitted.



Norm function:
float norm (in vec2 p1, in vec2 p2)
The canvas corners are [-1,-1] and [1,1].



Compute function:
hcol comp_values (in fdata fd)
Where "fdata" and "hcol" types are structs:
// For a given pixel,
struct fdata
{
    bool  spot; // true if pixel is very close to a base
    float d1;   // distance from the closest base
    int   i1;   // index of the closest base (-1 if not exists)
    float d2;   // distance from the 2nd closest base
    int   i2;   // index of the 2nd closest base (-1 if not exists)
    float d3;   // distance from the 3rd closest base
    int   i3;   // index of the 3rd closest base (-1 if not exists)
};

struct hcol
{
    float h;   // the height for the pixel displayed in 3D view
    vec3  col; // the colour of the pixel.
    // You can get the colour of a base given its id: vec3 getcol(in int base_id)
};