Forums > Javascript

MGraphics javascript api documentation inconsistency…

November 13, 2012 | 5:27 pm

I am experiencing some strangeness with javascript and mgraphics.
The code below shows a simple sketch. I have commented two lines,
one that works one that does not.

If you uncomment the line that does not work, you do not get a compiler
error but the sketch is broken. Which means that there is an undocumented call
to mgraphics matching the function signature fill(rgb), that is not documented.

Is this interpretation correct?

autowatch = 1;

var width = 500;
var height = 300;
var mgfx = new MGraphics(width,height);

mgfx.init();
mgfx.relative_coords = 0;
mgfx.autofill = 0;

var outmatrix = new JitterMatrix(4, "char", width, height);
var rotation = new Array(0.0, 0.0, 0.0);
var curMatrix = new Array(0.0, 0.0, 0.0);
var frameCount = 0;

mgfx.redraw();

function bang()
{
draw();
frameCount++;
}

function draw()
{
var theImage = null;

clearBackground();
fill(100); // < ---- this works
//mgfx.fill(100); // < ---- no compiler error, and does not work!
mgfx.rectangle(0, 0, 100, 100);
mgfx.fill();

mgfx.identity_matrix();
theImage = new Image(mgfx.pop_group());
mgfx.image_surface_draw(theImage);

theImage.tonamedmatrix(outmatrix.name);
outlet(0, "jit_matrix", outmatrix.name);

gc();

}

function fill(rgb)
{
mgfx.set_source_rgba(rgb/255, rgb/255, rgb/255, 1);
}

function clearBackground() {
background(0);
}

function background(rgb)
{
with (mgfx)
{
set_source_rgb(rgb/255, rgb/255, rgb/255);
rectangle(0, 0, width, height);
fill();
}
}


November 24, 2012 | 5:35 pm

Are there any Cycling74 folk out there? Is this a bug?


January 10, 2013 | 6:14 pm

This issue was a javascript parameter issue. See…

http://cycling74.com/forums/topic.php?id=43851


Viewing 3 posts - 1 through 3 (of 3 total)