how to make fit...

For general discussion related FlowStone
Post Reply
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

how to make fit...

Post by tester »

How to make that vector triangle fit the whole square/rectangle? (non-ruby)
Attachments
triangle.fsm
(1.02 KiB) Downloaded 999 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: how to make fit...

Post by trogluddite »

The triangle in the example is drawn by using a single very thick line that is angled at 45deg. This effectively gives you a rectangle (line length * line width) rotated to 45deg. The triangle is then one corner of this rectangle clipped off by the view area - which mean that the angle at the lower point has to be 90deg.
To change the height of the triangle would require that angle to be different, and so it cannot be done using this method.

Three possible solutions...

1) Masking
For this technique you would have to have a GUI with a definite background colour - and then use other rotated rectangles (i.e. wide lines) drawn in the background colour to 'paint out' areas of pixels that are not part of the shape. But this will lead to some fiendishly complex maths - the required geometry would change, for example, as the triangle's apex changed from an acute to obtuse angle.

2) Fill your own shape.
Using geometry and draw loops, you would 'scan' the shape, using the equations of it's geometry to define lines of pixels that needed filling, building up the shape a row at a time. For this shape, a simple 'fan' might be easiest - scan along the top edge one pixel at a time, drawing a line from there to the triangle's apex.
A search for 'polygons' on the SM site should find you a few good examples - I remember there being a few threads about creating filled shapes.

3) Use Ruby to just draw the outline and let GDI+ do all the hard work.
I know, you said a 'non-Ruby' solution, but for non-trivial shapes, the old 'green/yellow' vector primitives are, well, just a bit too 'primitive' - there is no way to define 'fillable' outlines with them other than the default rectangle and ellipse shapes (and the "thick lines" method for rotated rectangles). OTOH with Ruby you can easily fill very complex outlines, including those with combinations of straight and curved edges - this is one area where Ruby really does have a huge advantage over the old methods.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: how to make fit...

Post by tester »

Thanks for explaining.
Meanwhile I just resigned somewhat from triangular pointers - the simplest way :-)

Right now I'm avoiding ruby for a moment. My lack of knowledge/experience on that, this "roaming folder" thing and uncertainty to the performance of ruby-driven modules - makes me to wait with that.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Post Reply