Mocha

from Technosis

by Wes Cherry (wesc@technosis.com)

Mocha allows you to generate nifty shifting images.. Starting with simple mathematical expression (called a bene, a mix of gene and bean, pronounced "bean"), you can investigate the visual impact of variable time, the inflence of sounds, colors, and seed images to the images created by Mocha. Evolve your visualizations purposfully, exploring th effects of various changes to the bene.. Watch as images evolve organically, both by your explicit changes or on your behalf by Mocha in breed mode

Mocha is Freeware. It may not be resold for profit without my consent.

Mocha is written in my spare time (of which I have very little). I welcome email with suggestions and bugs, but I can't guarantee I'll answer.


Revision History

Ver 3.0 18 Jan 99

  • Massive optimization to rad() and theta() functions which makes most benes evaluate 3x faster!
  • Manu new features -- see help file
  • New help file
  • Integration of standalone Mocha with new sources
  • Bene Database

    Ver 2.1 - 2 Dec 98

  • Ctrl-Z for Undo
  • Degenerate image detection -- reverts to good parent when the image is all same pixels
  • Multiple processor support -- creates threads to speed up rendering on multi-processor machines
  • Better Ctrl-F handling
  • Fixed some memory leaks

    Ver 2.0a - 10 Nov 98

  • Ctrl-C now copies current image to clipboard

    Ver 2.0: - 1 Oct 98

  • Original release for WinAmp


Installation

Mocha is currently available for Windows 95/98/NT and for WinAmp running on Windows.


Windows Standalone Installation

Mocha is a self installing executable. Just copy it to a directory and run it.

Standalone Mocha uses your soundcard's line input (or CD playback) as the sound source when evaluating expressions involving sound.


WinAmp Installation

Mocha works with WinAmp 1.90 and later (it may work with earlier versions, but I haven't tested it)

Copy Mocha to your winamp plugin directory (typically c:\program files\winamp\plugins).

If you don't already have WinAmp get it from www.winamp.com


Features

Bene Input Window

Breed Mode

Viewing Options

Bene Database


Bene Input Window

The Bene Input window is invoked via File/Enter Bene Expresion... or Ctrl-F. See the Benes Topic for more information of Bene expression syntax.


Breed Mode

Breed Mode allows you to generate multiple mutations of the current bene. These mutations, also called children are displayed around the parent bene. Clicking on one of the children makes it the new parent.

If Animate All in Breed Mode is checked in the options menu then Mocha will update all children. This may slow down the frame rate, however.

You can change the mutation rate by selecting one of the 3 mutation rates available in the options menu.


Saving Images

Mocha can save the current image out as a bitmap or GIF. Choose File/Save Image... and set the file format in the save dialog.

Also, animations can be saved as either an animated GIF or as an AVI file. Choose File/Save Animated GIF/AVI...


Viewing Options

Mocha has a number of options to customize its display.

Increase Scale (Up) | Increases the image size (more detail, slower bene evalutation)
Decrease Scale (Down) | Decreases the image size (less detail, faster bene evalutation)
Tile (Ctrl-T) | Tiles the current image to the size of the current window. Especially useful with Full Screen mode.
Stretch to Window (Ctrl-W) | Stretches the current image to the size of the window.
Full Screen (Ctrl-U) | Sizes the Mocha window to full screen.


Bene Database

If you like a particular bene that you have bred, you can save it to the bene database. Choose File/Save Bene...

Benes may also be loaded by choosing File/Open Bene....

Benes are saved in a database file named "mocha.moc"


Auto Mutate

When Auto Mutate is checked in the Options menu, Mocha will automatically mutate the current bene. To prevent degeneration to boring Benes Mocha will periodically pick a random good parent from the Bene Database

Use the Auto Mutate Settings... menu item to select the delay between Auto Mutations.


Benes

Benes (Expressions)

Benes are mathematical expressions which are evaluated for each pixel in the image. These expressions may involve the x or y coordinate of the image, the current frame or even the current mouse position. Benes may also use built in functions and best of all, respond to sound.


Benes Introduction

An Introduction to Benes

Starting with the simple bene:

y

will generate a vertical wash of grays going from black at the top to white at the bottom. (by default 0=black and 255=white). To enter this bene, open up the Bene Input Window with Ctrl-F, type in y and press Ok.

Benes can also involve the variable t. In this case the image is evaluated successively creating an animated "movie". For example, the bene

y+t

will cause the wash of grays to scroll upwards.

Now throw in a function. The bene

sin(y+t)

will sinusoid of grays to scroll upwards.

Don't worry about generating benes by hand. Mocha comes with many good built in Benes and it's Breed Mode makes it easy to evolve good benes (in fact most of the built in benes were bred rather than designed).

Since Mocha has to evaluate the bene for each pixel in the image Mocha is very computationally intensive. To run well it should be run on at least a 486 or better computer. Benes involving t in particular look much better on a fast 486 or a Pentium computer.


BenesVariables

Variables

x | x position of current pixel
y | y position of current pixel
t | the current frame number
xm | the current mouse x position
ym | the current mouse y position

Constants

X | The X extent of the image
Y | The Y extent of the image


BenesOperators

Operators

The following operaters are supported by Mocha.

+ | Plus
- | Minus (binary & unary)
* | Multiplication
/ | Division
% | Modulo
^ | Power
< | Less Than
<= | Less Than or Equal
> | Greater Than
>= | Greater Than or Equal
<> | Not Equal
== | Equal
? | Ternary operator (x ? y :z) evaluates to y if x != 0 else evaluates to z)
[,] | Array operator -- indexes into the source bitmap at pixel [x,y]. Source bitmap


BenesFunctions

Functions

sin(x) | : period =256, range = 0..255
cos(x) | : period =256, range = 0..255
tan(x) | : period =256, range = 0..255^2
asin(x) | : inverse sin of x
acos(x) | : inverse cos of x
atan(x) | : inverse tan of x
dsin(x) | : decayed sinusoidal
theta(x,y) | : returns angle (0..255) of vector from center of image to x,y
rad(x,y) | : returns radius of vector from center of image to x,y
saw(x) | : sawtooth function, period = 128, range = 0..255
tri(x) | : triangle function, period = 256, range = 0..255
decay(x) | decay function = int(exp(-i/64)*255)
exp(x) | exp(x/10)
abs(x) | abs value of x
rand(x) | range = 0..x
sqrt(x) | square root of x
peg(x) | pegs x to 0..255 (best applied to the result of an bene)
frac(x) | fractal wave function
snd(x) | sound waveform at x (0..255)
sndl(x) | left channel of sound waveform at x (0..255)
sndr(x) | right channel of soudn waveform at x (0..255)
vol(x) | sound volume at x (0..255)
fft(x) | fast fourier transform of sound waveform (0..255)
pal(x,offs) | specifies which built in palette to use. See palette documentation.

Any of these functions may be plotted by using an bene of the form:

fn(x)==255-y ? 255 : 0

thus to plot a sine wave you would use the bene:

sin(x)==255-y ? 255 : 0


Palettes

You can also specify the palette that is used for displaying the image. The pixel value computed with the benes described above specifies an index of 0 to 255 into the palette. The Red, Green and Blue components of the palette are specified separately using assignments to the variables r,g and b. When palette benes are evaluated x is used to indicate the current palette index being computed. Thus the default palette of a gray wash is specified via

r=x
g=x
b=x

If you wanted a blue wash you would specify the palette with

r=0
g=0
b=x

You may also use the Hue, Saturation, Lightness (HSL) color model to specify color. It is often much easier to create a good palette using HSL. H specifies the hue (0..255 map to Red-Yellow-Green-Cyan-Blue-Magenta). S is color saturation (0..255) and L is lightness (0..255 map to black-white). A nice rainbow swash can be specified by:

h=x
s=255
l=128

Palettes may also be specified using assignments to p. Use the pal(x, offs) function when using p. The first argument to pal specifies the index into an array of predefined palettes (currently about 30). offs specifies the offset whithin the palette (0..255). Thus

p=pal(13,t)

will rotate palette 13.


BenesExamples

Example Benes

Here are some sample benes. There are also some good sample expressions included in the default mocha.moc file. Choos File/Open Bene Expression. You may select these expressions in Help and copy them to the clipboard. Activate Mocha and paste them in with Edit/Paste.

x+y

sin(x)

sin(2*x)

sin(x+y)

theta(x,y)

Egg Carton variations

sin(x+sin(y+sin(sin((sin(x*2)+sin(y*2))/2))))
sin(x*t+sin(y+sin((sin(x*2)+sin(y*2))/2)))
sin(sin(x*t-sin(y+sin((sin(x*2)+sin(y*2)-y-6)%8-2)-x)))

Marching Melting Mountains

sin(cos(6*y+sin(x+cos(x+4*t)))+6*x)

sin(cos(6*y+sin(x+cos(x+sin(x+4*t))))+6*x)

Oscillating Too Dark Park

sin((((x-X/2)^2+sin((t-20)*x)*12+(y-Y/2)^2+sin(2*y)*((sin(t)-128)))/100)

Fractal Wipeout

sin(x*sin(y)*100/cos(t))

Jazz

sin(x*(t-100)/10+sin(x*t+sin(y+sin((x*2)+sin(y*2))/2))

Fraktal Supernova

r=x
g=x
b=0
cos(abs(rad(x,y)%tri((x*tri(t)+5-8+21)*y)))

No Name

r=0
g=(x*7)
b=(x*42)
tan(x)/-4/sin(saw(saw((cos(y+t)+(x--15))/-16+sin(t))))

Flying saucer

sin(x+y%rad(x,y*t/4))

Cursor position benes:

sin((((x-X/2)^2+(y-Y/2)^2+sin(2*y)*(xm-64)*5+cos(5*x)*(ym-64)*5))/100+t*40)

Image manglement benes

The following benes require you to first generate an image from this bene and then use File/Save Image to save it and then File/Open Source Image. Many of these images tile well and make good windows desktop bitmaps.

(sin(x+cos(y))+cos(y+sin(x)))/2

creates mocha.bmp

Using mocha.bmp for bitmap:

[[x,y],[y,x]]
[[[x,y],x],y][[sin(x),cos(y)],[sin(y),cos(x)]]
[sin([cos(x),sin(y)]),cos([cos(y),sin(x)])]
[[[sin(y+t*5),(x+cos(x+t*4))%255],y],x]
[[[sin(y+t*5),(x+cos(x+sin(t*4)))%255],x],y]
[sin(t+6+sin(x)+cos(y)),cos(t*4+y+sin(x+t))]
[sin(t+6+sin([x,y]*t)/cos(t+[y,x])+cos([y,sin(x)])),cos(t*4+y+sin(x+t))]
[[[x,y+cos(t*3)],x],sin(y+t*5)]
[[peg(sin(y+t)+cos(x+t)),peg(cos(y+t)+sin(x-t))],sin(x)]
[[peg(sin(y+t)+cos(x+t)),peg(cos(y+t)+sin(x-t))],peg(exp(x+t*4)/sin(y))] (lava gears)

General warp (tileable at 256x256)

[sin(x)*cos(x+y)/sin(y),cos(y+x)]

Blowup!
[x+(cos(x)-128)/(20-t),y+(sin(y)-128)/(20-t)]
frames=18
Cyclic Inflation
[x+(sin(x)-128)*16/(cos(t*4)+32),y+(cos(y)-128)*16/(cos(t*4)+32)]
The Stimpy Transform (best w/ people faces)
[x+(sin(x*t)-128)/(t*4),y+(sin(y*t)-128)/(t*4)]
frames=20

Mouse Controlled Woogilating

[x+(sin(x+t*xm)-128)/8,y+(sin(y+t*ym)-128)/8]

Wiped Monty

[abs(x+(exp(x+1-y*2+t*8)-128)/16)%X,abs(y+(cos(x+(y*2)+(t*8))-128)/6)%Y]

Perpetual Inflation

[abs(x+(exp((15+1-y*2)*t*8+y)-128)/16)%X,abs((cos(x+(y*2)+t*8)-128)/-5+y-3)%Y]

Funhouse Mirrors

[sin(x+exp((21-y*2)*t*8-y)*128/10)%X,abs((cos(x+(y*2)+t*8)-128)/11+y-3)%Y]

Moire Yer Face

[abs(x+(exp((15*15-y*2-t)*8+6+y)*1-141)/25)%X,abs((cos((x+x)*(y*2)+t*8)-129+t)/--10+y-3)%Y]

Gritty Zitties

[abs(x+(exp(14+y)*1-121)/13)%X,abs((cos((x+x)*y*2*t*8)-114+t+x)/-10+y-22)%Y]

Rotate Bitmap To View

[x+(y*4/t),y-(x*4/t)]

Monet

[x-t/2+rand(t),y-t/2+rand(t)]

Other Interesting Good Parents

t*exp(tan(x+y-t-t)/35*(7+x)-1-t+t-128-7)+17+x
exp(sin(5-t))*(peg(cos(y))-cos(x))
[16%X/0,abs(y+sin((x*(y-1)/-18+9)/(t-16))-128-t+27)*7%Y]
peg(cos((6+y)%sin((x/t*14+y)/3))%(6*x))
abs((((cos(8-x-y-4)%x+y)/7+t)/37-6)%x*y*-1-24+x)
abs(((cos(8-x-y-4)%x+y)/7*t/37-6)%x*y*-1-24+x)

Great Backgrounds

These guys tile well (Options/Background), Try them at 1/4 or 1/8 scale.

r=x
g=0
b=x
theta(cos(x),sin(y))+6*t+x+y

(theta(cos(x)-t,sin(y))-x+t)*(-16+t)-x+t+y
(((theta(5*5-6-1+x-t,(3+y-2)*t+18)--20-t)*-53-5)*4*-6*t+3+y+y--2+19-6-t+t)*-4-x+t-7+y

Pinwheels

sin(theta(cos(x),saw(y))--16*t)-x+y
sin(theta(cos(x),saw(y))+16*t)-5+y


Advanced Features

Master Slave Mode

Display Frame Rate

Disassembly


Master/Slave Mode

Master/Slave mode allows you to control Mocha on a remote machine. It could be useful in performance environments where you could compose an expression on one machine (Master) and then shoot it over to a display only machine (Slave).

To set it up, you must have both computers networked using TCP/IP with Winsock installed(other protocols may work, but I haven't tested them).

On the Master machine, select Options/Master Slave Config... from the menu and specify the machine name or IP address of the slave computer.

On the Slave machine, select Options/Master Slave Config... from the menu and check Slave. Make sure the port number is the same as that on the Master machine.

Press Ctrl-Enter on the Master machine to shoot the expression over to the Slave machine.


Display Frame Rate

Choose Options/Display Frame Rate to display the number of frames per second evaluated by Mocha.


Disassembly

Choose File/Disassemble write the assembly code of the current bene. Mocha will tell you the filename it generates. Since this is primarly a debugging feature for me it doesn't prompt for a filename.


Shortcuts

Keyboard Shortcuts

Mouse Shortcuts


Keyboard Shortcuts

Ctrl-C | Copy current bene and image to the clipboard
Ctrl-V | Paste bene
Ctrl-F | Toggle bene expression window
Ctrl-Z | Undo
Return | Save current bene in list of favorites (good parents)
BackSpace | Reset current bene to a random good parent
Space | Mutate bene
Ctrl-B | Toggle Breed Mode.
Ctrl-T | Tiles the current image to the size of the current window.
Ctrl-W | Stretches the current image to the size of the window.
Ctrl-U | Sizes the Mocha window to full screen.
Ctrl-M | Toggles the display of menu bar.
Up | Increase Scale
Down | Decrease Scale
Ctrl-O | Open Bene Database
Ctrl-S | Save Bene in Database
Ctrl-Enter | Send image to Slave machine (Master/Slave mode)


Mouse Shortcuts

Left-Click | Random mutation, or select new parent when in Breed Mode
Right-Click | Reset to a random parent picked from the Bene Database
Double-Click | Maximizes/Restores the Mocha window


Dummy

 dummy reference to background.jpg so it gets included