A tunnel (66 FPS captured at 8 FPS)

Still images of four expressions

**What is it?**

Expression Lab is a small batch script layer on top of Cmdgfx_RGB (1.6, unreleased) which allows to write (RGB color) expressions and see them animate immediately in real time.

As well as making my own, I thought it would be fun to see if some DosTips users could come up with interesting animations. I know many of you would have no problem of doing so (if interested).

**How does it work?**

After running ExpressionLab.bat, you can either:

1. Browse the 48 examples with cursor left/right. The examples are divided into 2 sets of ~20 examples each, press 'm' to switch between sets.

2.

**Press 'Enter' to open the interactive expression lab**, which is just a prompt. (It's possible to have several such windows open at the same time). Write an expression in the window, press Enter, see results (or errors). Note that after pressing Enter, the script tries to restore both your previous input as well as the previous cursor position (the latter may take ~1s). Also note that since it is a prompt, you have command history available in the window.

**But how do the expressions work?**

So basically, like a fragment shader, the expression runs for every character in the window, and the only real input you get is the x and y position of the current character. From this, all kinds of colors and animations blooms through the use of math. Everything has to be composed in a single line, no spaces, and the result should be a 24-bit RGB (red/green/blue) value.

Apart from the x and y position, ExpressionLab also injects the following data that can be used in expressions:

Code: Select all

```
x: current x position (column)
y: current y position (row)
A1 : a counter increasing by 1 every frame
A2: a counter decreasing by 2 every frame
C1: sin(A1 degrees)*367 (stupid decision, *255 would have been better but too annoying to change now)
C2: sin(A2 degrees)*342 (as above)
L1: a counter that goes from 0 to 255 and then restarts
SCRW: the width in characters of the current window
SCRH: the height in characters of the current window
s0-s9: Not filled in by the script, these are the variables used for (temporary) storage inside expressions
```

**Which math or other functions are available?**

Currently, these (I skipped some that are useless in this context):

Code: Select all

```
Standard math: abs, acos, asin, atan, atan2, ceil, cos, cosh, e, exp, floor, ln, log, log10, pi, pow, sin, sinh, sqrt, tan, tanh
Add-on math: random, or, and, xor, neg, shl, shr, max, min, mod, clamp, sign, clamp255, length, frac, perlin
Conditional (these return 1 if true, otherwise 0): eq, neq, gtr, lss, geq, leq
Sampling functions (returns color at given position): col (fgcol, bgcol)
Storing temporary values: store (always returns 0. 2 parameters, first is the value, second is index of storage 0-9. So store(5+9,1) would store 14 in s1 )
Getting color components (red/green/blue) of color: fgr, fgg, fgb
Composing colors: makecol, makecol255, shade, blend (plus several more I left out)
```

**Limitations?**

As mentioned, everything must be on a single line, no spaces. No looping is possible (though you could unroll loops like I did for the Julia fractal). An expression must be minimum 2 characters. No self-defined functions. Also as mentioned, there are only 10 variables for temp storage.

**Examples?**

Yes, very much needed I think...

Let's start super simple:

Code: Select all

`y+0`

Next up:

Code: Select all

`y*5`

To help this, we could use e.g. the

*clamp255*function, which clamps the value between 0-255. But it's better to get acquainted with the

*makecol255*function:

Code: Select all

`makecol255(y*5,y,y*2)`

But what if the expression was complex and we just wanted to adjust it a bit for each color component? That's where

*store*comes in:

Code: Select all

`store(x/1.6+max(x/2,y)*2,0)+makecol255(s0,s0/1.5,s0*1.4)`

Use A1/A2,C1/C2/L1 in the math expression. C1 and C2 (the sinus values) are good for quickly getting something running, e.g.:

Code: Select all

`store(x/1.6+max(x/2,y+C2/6)*2,0)+makecol255(s0,s0/4.5+C1/5,s0*1.4)`

Finally you might end up with something like the colorized tunnel from the first still image above:

Code: Select all

`store(A1/20,4)+store(x/SCRW-0.5+sin(s4/2.7)*0.2,0)+store(y/1.6/SCRH-0.3+cos(s4/3)*0.11,1)+store(length(s0,s1),2)+store(atan2(s0,s1)+s4*0.3,0)+store(0.3/s2+s4*0.5,1)+store(perlin(sin(s0)*(2+sin(A1/150)*3)*1+s1*2,s1*2)*s2*s2*2.8,3)+makecol255(s3*10000+sin(s0)*s2*1000,10+abs(s3)*1500+sin(s0*3)*s2*250,abs(s3)*4600+sin(s0*2)*750*s2)`