Sine wave using only Math nodes? For the purpose of animating materials, is there a way to construct a sine wave function out of Math nodes?

A while back I asked about how to do something similar with scripted driver expressions. But drivers don't work for animating materials (yet). They also are not currently supported in Blend4Web, which is where this will ultimately be used (with the B4W_TIME node driving the incremented value by frame).

So let's start with a keyframed Value node that increments by 1 for each frame. And that is factoring a MixRGB node with two mixed colors. 



Since 0 will be 100% the top color, and 1 will be 100% the bottom color, going from frame 0 to frame 1 instantly changes the mix completely. Inserting a Math (Multiply) node slows this process, so for example if multiplied by 0.05 it will take 20 frames to shift from red to blue, and at frame 10 it will be half/half (purple).





So what about animating it so that it oscillates between two colors? Can this sort of sine wave animation be constructed using Math nodes?

(Note: This must be achievable using the Blender Internal Render Engine.)

Thanks
Sine Wave
Producing a sine wave is easy as Sine is one of the math functions in the Blender Internal Converter --&gt; Math node.
However, a normal sine is no good as a direct factor for a mix node, since a sine wave produces values between -1 and 1, and the node expects a value between 0-1. To produce sine-like oscillating values between 0 and 1 I used the equation ( sin(x) + 1 ) / 2.
The node tree looks like this:

The factor values produced by this node setup look like this (green line):

Square Wave
A square wave is also pretty easy, since we only need to discern between positive and negative values, which we can do using the &quot;Greater Than&quot; or &quot;Less Than&quot; nodes:

And the factor values:

Triangle Wave
Based on this algorithm as implemented in wolfram, I used the following equation to generate a triangle wave:
pi/2 * asin( sin(pi * x) )
Since there is no inverse sine (asin) in the math node, I used the identity function (that employs the inverse cosine which can be found in the math node's repertoire):
asin(x) = pi/2 - acos(x)
Also, the original triangle wave creates values between pi/2 and -pi/2 more or less, so I adapted it thus to produce values between 0-1 (more or less):
( asin( sin(pi * x) ) + pi/2 ) / pi
The node setup looks like this:

This is by far the ugliest and biggest node setup, but that's the best I could manage. Here's how the factor values look:

Sawthooth Wave
Based on this answer, again adjusted to fit values between 0 and 1, I used this equation as basis:
( ( x + 1 ) % 2 ) / 2
Node setup:

Factor values: