I've change it to have 4 colors...not bad at all!!
// A simple example of using basic drawing routines to
// create a complex crossfade.
//
// For more significant use, you will probably have to
// calculate the drawing field, store it, and use it
// as a background for later painting.
//
// -----------------------------------------------------
mgraphics.init();
mgraphics.relative_coords = 0;
mgraphics.autofill = 0;
var color_centers = [.1, .38, .7, .9];
var myHeight = 1.;
var myWidth = .5;
function bang()
{
mgraphics.redraw();
}
function width(h)
{
myWidth = h;
}
function paint()
{
gc();
var tmp;
var width = this.box.rect[2] - this.box.rect[0];
var height = this.box.rect[3] - this.box.rect[1];
var aspect = width/height;
var amount = width * myWidth;
var myCenters =
[color_centers[0] * width,
color_centers[1] * width,
color_centers[2] * width,
color_centers[3] * width];
with (mgraphics) {
// clear the background
set_source_rgb(0., 0., 0.);
rectangle(0, 0, width, height);
fill();
// test a red fade
tmp = pattern_create_linear(myCenters[0]-amount, 0., myCenters[0]+amount, 0);
tmp.add_color_stop_rgba(0.0, 1., 0., 0., 0.);
tmp.add_color_stop_rgba(0.5, 1., 0., 0., 1.);
tmp.add_color_stop_rgba(1.0, 1., 0., 0., 0.);
set_source(tmp);
rectangle(myCenters[0]-amount, 0., amount*2, height);
fill();
// test a yellow fade
tmp = pattern_create_linear(myCenters[1]-amount, 0., myCenters[1]+amount, 0);
tmp.add_color_stop_rgba(0.0, 1., 1., 0., 0.);
tmp.add_color_stop_rgba(0.5, 1., 1., 0., 1.);
tmp.add_color_stop_rgba(1.0, 1., 1., 0., 0.);
set_source(tmp);
rectangle(myCenters[1]-amount, 0., amount*2, height);
fill();
// test a green fade
tmp = pattern_create_linear(myCenters[2]-amount, 0., myCenters[2]+amount, 0);
tmp.add_color_stop_rgba(0.0, 0., 1., 0., 0.);
tmp.add_color_stop_rgba(0.5, 0., 1., 0., 1.);
tmp.add_color_stop_rgba(1.0, 0., 1., 0., 0.);
set_source(tmp);
rectangle(myCenters[2]-amount, 0., amount*2, height);
fill();
// test a blue fade
tmp = pattern_create_linear(myCenters[3]-amount, 0., myCenters[3]+amount, 0);
tmp.add_color_stop_rgba(0.0, 0., 0., 1., 0.);
tmp.add_color_stop_rgba(0.5, 0., 0., 1., 1.);
tmp.add_color_stop_rgba(1.0, 0., 0., 1., 0.);
set_source(tmp);
rectangle(myCenters[3]-amount, 0., amount*2, height);
fill();
}
}