It looks like you're new here. If you want to get involved, click one of these buttons!
require "clipper" local subject = Polygon.new() subject:addPoint(0, 0) subject:addPoint(16, 16) subject:addPoint(16, 32) subject:addPoint(0, 32) subject:addPoint(-16, 16) subject:addPoint(0, 0) local clipper = Polygon.new() clipper:addPoint(0, 0) clipper:addPoint(32, 32) clipper:addPoint(32, 64) clipper:addPoint(0, 64) clipper:addPoint(-32, 32) clipper:addPoint(0, 0) local myclipper = Clipper.new() myclipper:addSubjectPolygon(subject, Polygon.FILL_EVEN_ODD, true) myclipper:addClipPolygon(clipper, Polygon.FILL_EVEN_ODD, true) local myc = myclipper:getDifference(subject, clipper) local myi = myclipper:getIntersection(subject, clipper) local x, y, w, h = myclipper:getBounds(subject, clipper) print(x) -- ok --local solution = Polygon.new() -- ??? --stage:addChild(myclipper) -- not ok |
Comments
https://luapower.com/clipper
it seems it has a different api from the current gideros clipper.
perhaps this could replace the current one in gideros?
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
i did not test it, but according to the docs i think something like this would be better:
myclipper:addSubjectPolygon(subject)
myclipper:addClipPolygon(clipper)
local myc = myclipper:getDifference(Polygon.FILL_EVEN_ODD, Polygon.FILL_EVEN_ODD)
and then myc is still just an abstract polygon object, not a sprite, so first from reading its vertices (by using myc:getPoints() ) you need to build a sprite using path2d for example. and then that can be added to the stage.
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Thank you for your insights I am going to try what you suggested.
local myc = myclipper:getDifference(Polygon.FILL_EVEN_ODD, Polygon.FILL_EVEN_ODD)
But I cannot retrieve anything from this table!
in zerobrane studio you can watch tables with all the subvalues and then it's easier to see what and how is stored in the myc object.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
print(tprint(myi))
My last attempt:
Polygon clipping example
Likes: Apollo14
Likes: keszegh, MoKaLux
1
{{0, 0}, {32, 32}, {32, 64}, {0, 64}, {-32, 32}}
that is, indeed myc consists of tables storing polygons, which can be read using getPoints.
note that i used getUnion in my example to make sure that the result is not empty!
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
and if you want difference then better exchange clipper and subject as otherwise you get an empty difference (as the bigger contains the smaller one). that's why i used union in my example to avoid this.
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
1
{{0, 32}, {16, 32}, {16, 16}, {32, 32}, {32, 64}, {0, 64}, {-32, 32}, {-16, 16}}
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh
You can copy paste the code and it should work (you need to add the clipper plugin).
You can uncomment the local myc lines to see different effects.
But what a mess. I saw somewhere in this forum a clipping example that was quite good. I don't see the point of this clipper plugin and I won't add it to the wiki. I suggest to remove it completely from gideros! We could gain back a few kb
Next 3D in gideros
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: MoKaLux
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Likes: oleg
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!