Some GLSL imagery

Hello. It’s been a long time. Let’s ignore that.

In a recent urge to put more FOSS apps on my Android phone, I installed a marvelous application called Shader Editor.  The app is basically just a GLSL editor that compiles the code live. You can use then use these shader files to make them animated wallpapers for your phone.

There exists a web-app for this too, for those who don’t like writing code on a phone (it’s a nightmare, really!). It’s called GLSLSandbox. You can hence write the code online and send it to your phone for Shader Editor to make a wallpaper out of it.

So for example writing the following code in the app:

#extension GL_OES_standard_derivatives : enable
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

#define PI 3.14159268
uniform vec2 resolution;
uniform float time;

vec2 invert(vec2 x)
{
float d=x.x*x.x +x.y*x.y;
return vec2( x.x/d,-x.y/d);
}

vec2 cube(vec2 x)
{ return vec2(x.x*x.x*x.x- 3.0*x.x*x.y*x.y,
-x.y*x.y*x.y +3.0*x.x*x.x*x.y) ;
}

vec3 design(float scal)
{
if(abs(scal) <0.54)
return vec3(0.350+0.1*sin(scal),0.230,0.25);
else
return vec3(0.3,0.1+0.05*sin(2.0*scal) ,0.2*scal);
}
void main(void) {
float mx = max(resolution.x, resolution.y);
vec2 uv = gl_FragCoord.xy / mx;
vec2 center = resolution / mx * 0.5;
float t = time * 0.40;

float scalar=sin(40.0*uv.x) *
sin(t+20.0*uv.x-1.732*20.0*uv.y) *
sin(t+20.0*uv.x+1.732*20.0*uv.y);

scalar=sin(8.0*scalar) ;
gl_FragColor = vec4(design(scalar), 1.0);
}

Gives the following result (recorded from GLSLSandbox):

Soon I found myself doodling with this app, through which I created some trippy visuals that I would like to share. I’ll add them soon in a different blogpost.

Modular group in action

I’m sorry for the long gap, though there’s nothing really to be sorry about. I know I wasn’t missed.

This posts will present some of my newly created gifs. Before showing the outcome, first let’s delve into some theory (the hasty reader is free to scroll to the juicier part, of course). As you may have perhaps deduced from the title, the theme of discussion today is the Modular group.

By the modular group ${PSL(2,\mathbb{Z})}$, we almost mean the following group (fondly known as ${SL(2,\mathbb{Z})}$).

$\displaystyle SL(2,\mathbb{Z}) := \{ \left( \substack{a\ b \\ c\ d} \right)\ ,ad-bc=1 , (a,b,c,d) \in \mathbb{Z}^4 \}. \ \ \ \ \ (1)$

However, in reality, the modular group is just slightly away from being that group. It’s the group given by the quotient group

$\displaystyle PSL(2,\mathbb{Z}):=SL(2,\mathbb{Z})/\{\pm 1_{SL(2,\mathbb{Z})}\}. \ \ \ \ \ (2)$

There is a natural action of the modular group on the complex upper half plane, which is

$\displaystyle \mathbf{H}=\{z \in \mathbb{C}, \ \Im(z) > 0 \}. \ \ \ \ \ (3)$

The action of an element ${\pm (\substack{a\ b \\ c\ d})}$, is given by (check that the sign does not matter)

$\displaystyle z \mapsto \frac{az+b}{cz+d}. \ \ \ \ \ (4)$

What is almost so magical about the above action is that it actually is a group action. That is, there is associativity with the group product and group identity fixes everything. The former of these two facts is not immediately trivial, but to witness it, look at the following calculation:

$\displaystyle (\substack{a_1\ b_1 \\ c_1\ d_1})\Big{(}(\substack{a_2\ b_2 \\ c_2 \ d_2}) z\Big{)} = (\substack{a_1 \ b_1 \\ c_1 \ d_1})(\frac{a_2 z + b_2}{ c_2 z + d_2}) \ \ \ \ \ (5)$

$\displaystyle = \frac{(a_1 a_2 + b_1 c_2)z + (a_1 b_2 + b_1 d_2)}{ (c_1 a_2 + d_1 c_2) z + (c_1 b_2 + d_1 d_2)} \ \ \ \ \ (6)$

The group action of the modular group on the upper half plane has inspired a lot of mathematics. It has deep connections with number theory and hyperbolic geometry. There are a lot of reasons to talk about these groups. There are complete books written on these subjects.

We will also witness another concept called the fundamental domain. Suppose we have a group ${G}$ acting on a topological space ${X}$. Then a fundamental domain of the action of ${X/G}$ (which is the set of ${G}$-orbits endowed with the Quotient topology), is a certain set ${D}$ inside ${X}$ which is in a set-bijection with ${X/G}$. More precisely, it is a region ${D\subset X}$ satisfying

• For any ${\varphi \in G}$, ${\varphi D \cap D \neq \phi \Leftrightarrow \varphi = 1_G}$,
• ${X= \bigsqcup_{\varphi \in G} \varphi D}$ .

If you’ve ever googled these things, the most commonly given example is always of the modular action, and how there is a fundamental domain ${D \subset \mathbf{H}}$ such that the following holds true

$\displaystyle U \subset D \subset \bar{U}, \ \ \ \ \ (7)$

where ${U}$ is the set

$\displaystyle U : = \{ z \in \mathbb{C},\ |z| > 1, \ |\Re(z)|<\frac{1}{2} \}. \ \ \ \ \ (8)$

A picture of this region (accurate upto boundary, beyond which it will be impossible for a computer to be accurate), is given here:

When acted upon by different elements of the modular group, the following “tiling” can be generated:

It is widely known that the modular group ${PSL(2,\mathbb{Z})}$ can be generated by the generators ${S,T}$ as described by

$\displaystyle S:= \pm \Big{(} \substack{0\ -1 \\ 1 \ \ 0}\Big{)} ,\ T:= \pm \Big{(} \substack{1 \ 1 \\ 0 \ 1} \Big{)}. \ \ \ \ \ (9)$

In the language of the above matrices, it is known that the modular group ${PSL(2,\mathbb{Z})}$ is given as the presentation

$\displaystyle \langle S , T \ | \ S^2=1,\ (ST)^3=1 \rangle. \ \ \ \ \ (10)$

Here is the action of ${T}$ (a little uneventful, unfortunately):

Here is the action of the element the element ${S}$ upon our favorite tiling:

To keep track of the flipping around, here is the same with each tile randomly colored (it was difficult to color the inside of a non-convex tile on the computer without triangulating it, so I chose the following scheme instead):

Here is the action of ${T}$ on the Poincare Disk model

Here is the action of ${S}$ on the same (looking much less dramatic):

While proving a landmark result (the Monstrous moonshine conjecture) related to modular forms, which are related to our discussion, Richard Borcherds had recounted his experience by saying, “I sometimes wonder if this is the feeling you get when you take certain drugs. I don’t actually know, as I have not tested this theory of mine.”

Inspired by this, I have created the following imagery (the colours of the tiles are a smooth function of time):