It looks like you're new here. If you want to get involved, click one of these buttons!
function Path2D:drawCircle( r, lineThickness, LineColor, FillColor, fillAlpha ) self:setSvgPath(("M %s 0 a %s %s 0 0 0 %s 0 a %s %s 0 0 0 %s 0 Z"):format(-r, r, r, 2*r, r, r, -2*r)) self:setLineThickness(lineThickness) -- Outline width self:setFillColor(FillColor,fillAlpha) --Fill color self:setLineColor(LineColor) --Line color end |
local circle = Path2d.new() circle:drawCircle(radius, lineThickness, LineColor, FillColor, fillAlpha ) stage:addChild(circle) |
Likes: mertocan
Comments
Likes: pie
Likes: pie
you're always a lot ahead eh..
It looked like a circle to me, but the one from @n1cke is much better. Mine was definitely odd :P
Where does the :format part come from? Couldn't find it in the docs: it's svg stuff?
Thank you again
("%s"):format(v) is equal to string.format("%s", v)
Thank you
Note that lower case letters in SVG are used for relative positioning while upper case letters are for absolute one.
`string.format` is part of Lua language: http://docs.giderosmobile.com/reference/lua/string/format#string.format
It accepts formatting string and list of arguments for each `%`-prefixed element in formatting string and outputs formatted string where each `%`-prefixed element is replaced with some argument from that list.
More about it: https://www.lua.org/pil/20.html
I use "M %s 0 a %s %s 0 0 0 %s 0 a %s %s 0 0 0 %s 0 Z" to describe a circle:
M %s 0 -- move pen without drawing to (%s,0)
a %s %s 0 0 0 %s 0 -- draw relatively positioned elliptical arc (half of circle)
a %s %s 0 0 0 %s 0 -- draw another relatively positioned elliptical arc (half of circle)
Z -- close path i.e. draw a line from last described point to first one
And then I replace `%s`-elements in this string with calculated numbers:
(-r, r, r, 2*r, r, r, -2*r)
`string.format` is faster than " M "..(-r).." 0 ".." a "..(r) ... etc. and more readable for my taste.
Some other programming languages have much more readable interpolated strings support for this case:
greet = "Hello"
whom = "world"
print("$greet, $whom.")
And it outputs "Hello, world.".
I should say it is also possible to implement interpolated strings in Gideros Lua via macro.
Likes: pie
Likes: pie
In the github update text you also mention the normal setPath, have you changed that too?
https://deluxepixel.com
https://deluxepixel.com