Forums > Javascript

Mgraphics not drawing stroke properly

December 10, 2012 | 11:19 pm

If you run the following code…

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);

mgfx.redraw();

function bang()
{
draw();
}

function draw()
{
var theImage = null;

background(255);

mgfx.rectangle(0, 0, 100, 100);

mgfx.set_source_rgba(0, 0, 0, 1);
mgfx.stroke_preserve();

mgfx.set_source_rgba(0, 1, 1, 1);
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 clearBackground() {
background(0);
}

function clearBackground() {
background(0);
}

You will see that two sides of the border stroke are missing.
Did I get something wrong here?

-ap


December 12, 2012 | 4:53 pm

Is this a bug or am I doing something wrong?


December 14, 2012 | 4:59 pm

Anybody?


December 17, 2012 | 3:14 pm

Surely someone here knows something about mgraphics.


December 17, 2012 | 7:35 pm

Hi Anthony,

Not sure about what you’re trying to achieve here but it sounds like you’d want to revert the stroke and fill operations:
// first
fill_preserve()
// then
stroke()

Best,
Frédéric


December 17, 2012 | 9:40 pm

Let me rephrase my problem. My objective is to see a shape with a border around it.
The code I have now, draws the shape then the frame. What I should see is NOTHING.
The shape should cover the frame. What you actually see is a square with two sides
of the border.

If I reverse it, as you suggested, I see the frame but two of the sides are twice as thick.
I have included a test patch.

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);

mgfx.redraw();

function bang()
{
draw();
}

function draw()
{
var theImage = null;

background(255);

mgfx.rectangle(0, 0, 100, 100);

mgfx.set_source_rgba(0, 1, 1, 1);
mgfx.fill_preserve();

mgfx.set_source_rgba(0, 0, 0, 1);
mgfx.stroke_preserve();

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 clearBackground() {
background(0);
}

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

– Pasted Max Patch, click to expand. –

December 17, 2012 | 10:10 pm

I believe your issue will be clearer if you don’t do the drawings at the upleft bounds of the jit.pwindow. See for instance what is happening when replacing mgfx.rectangle(0, 0, 100, 100) with mgfx.rectangle(10, 10, 100, 100).

In both cases you have to consider that stroke() has an irreducible thickness. Maybe try to experiment with function set_line_width(f) with f less than 1.

Hope that helps,

Best,
Frédéric


December 17, 2012 | 11:14 pm

Ahhh you are right, starting at (0, 0) seems to clip the top and left side of the
border, which is why it is not seen. Thanks Frederic for helping me sort this out!


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