Mgraphics not drawing stroke properly

Dec 10, 2012 at 11:19pm

Mgraphics not drawing stroke properly

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

#65623
Dec 12, 2012 at 4:53pm

Is this a bug or am I doing something wrong?

#236402
Dec 14, 2012 at 4:59pm

Anybody?

#236403
Dec 17, 2012 at 3:14pm

Surely someone here knows something about mgraphics.

#236404
Dec 17, 2012 at 7:35pm

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

#236405
Dec 17, 2012 at 9:40pm

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. –
#236407
Dec 17, 2012 at 10:10pm

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

#236408
Dec 17, 2012 at 11:14pm

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!

#236409

You must be logged in to reply to this topic.