How do I fill an object made with lines?

I hope that someone can help me with a problem that I ran into this weekend. I am trying to make objects by drawing lines such as a triangle and pentagon, which I have been successful doing. However, I cannot find a way to fill in the object and am left with a frame. I have been unable to locate any syntax for accomplishing this. I would be extremely grateful for any assistance with this. [import]uid: 186904 topic_id: 32194 reply_id: 332194[/import]

I’ve been using the code I found in this post, hope it helps ^^

[lua]local function paintPoly(poly, xoffset, yoffset, rgba)

local newLine = display.newLine
local math_floor = math.floor
local math_min = math.min
local math_max = math.max
local polyGroup = display.newGroup()

local n = #poly

local minY = poly[1].y
local maxY = poly[1].y

for i = 2, n do
minY = math_min(minY, poly[i].y)
maxY = math_max(maxY, poly[i].y)
end

for y = minY, maxY do

local ints = {}
local int = 0
local last = n

for i = 1, n do
local y1 = poly[last].y
local y2 = poly[i].y
if y1 < y2 then
local x1 = poly[last].x
local x2 = poly[i].x
if (y >= y1) and (y < y2) then
int = int + 1
ints[int] = math_floor((y - y1) * (x2 - x1) / (y2 - y1) + x1)
end
elseif y1 > y2 then
local x1 = poly[last].x
local x2 = poly[i].x
if (y >= y2) and (y < y1) then
int = int + 1
ints[int] = math_floor((y - y2) * (x1 - x2) / (y1 - y2) + x2)
end
end
last = i
end

local i = 1
while i < int do
local line = newLine(ints[i] + xoffset, y + yoffset, ints[i + 1] + xoffset, y + yoffset)
polyGroup:insert(line)
line:setColor(unpack(rgba))
i = i + 2
end
end

return polyGroup
end

hg={{x=0,y=0},{x=100,y=0},{x=0,y=100},{x=100,y=100}}
color = {0,255,0}
paintPoly(hg, display.contentWidth/2, display.contentHeight/2, color )[/lua] [import]uid: 53195 topic_id: 32194 reply_id: 128202[/import]

I’ve been using the code I found in this post, hope it helps ^^

[lua]local function paintPoly(poly, xoffset, yoffset, rgba)

local newLine = display.newLine
local math_floor = math.floor
local math_min = math.min
local math_max = math.max
local polyGroup = display.newGroup()

local n = #poly

local minY = poly[1].y
local maxY = poly[1].y

for i = 2, n do
minY = math_min(minY, poly[i].y)
maxY = math_max(maxY, poly[i].y)
end

for y = minY, maxY do

local ints = {}
local int = 0
local last = n

for i = 1, n do
local y1 = poly[last].y
local y2 = poly[i].y
if y1 < y2 then
local x1 = poly[last].x
local x2 = poly[i].x
if (y >= y1) and (y < y2) then
int = int + 1
ints[int] = math_floor((y - y1) * (x2 - x1) / (y2 - y1) + x1)
end
elseif y1 > y2 then
local x1 = poly[last].x
local x2 = poly[i].x
if (y >= y2) and (y < y1) then
int = int + 1
ints[int] = math_floor((y - y2) * (x1 - x2) / (y1 - y2) + x2)
end
end
last = i
end

local i = 1
while i < int do
local line = newLine(ints[i] + xoffset, y + yoffset, ints[i + 1] + xoffset, y + yoffset)
polyGroup:insert(line)
line:setColor(unpack(rgba))
i = i + 2
end
end

return polyGroup
end

hg={{x=0,y=0},{x=100,y=0},{x=0,y=100},{x=100,y=100}}
color = {0,255,0}
paintPoly(hg, display.contentWidth/2, display.contentHeight/2, color )[/lua] [import]uid: 53195 topic_id: 32194 reply_id: 128202[/import]

Here is exactly what I want to do: Fill in the tree.

local tree1 = display.newRect(410,135,10,180)
tree1:setFillColor(200,154,125)

local tr1a = display.newLine(415,100,440,165)
tr1a:append(390,165,415,100)
tr1a:setColor(15,95,0)

local tr1b = display.newLine(415,140,460,240)
tr1b:append(370,240,415,140)
tr1b:setColor(15,95,0)

local tr1c = display.newLine(415,180,475,290)
tr1c:append(355,290,415,180)
tr1c:setColor(15,95,0)

The three triangles “tr1a,b,c” are the branches of a pine. “SetFillColor” just gives an error. Is there a way to fill the branches? [import]uid: 186904 topic_id: 32194 reply_id: 128350[/import]

Here is exactly what I want to do: Fill in the tree.

local tree1 = display.newRect(410,135,10,180)
tree1:setFillColor(200,154,125)

local tr1a = display.newLine(415,100,440,165)
tr1a:append(390,165,415,100)
tr1a:setColor(15,95,0)

local tr1b = display.newLine(415,140,460,240)
tr1b:append(370,240,415,140)
tr1b:setColor(15,95,0)

local tr1c = display.newLine(415,180,475,290)
tr1c:append(355,290,415,180)
tr1c:setColor(15,95,0)

The three triangles “tr1a,b,c” are the branches of a pine. “SetFillColor” just gives an error. Is there a way to fill the branches? [import]uid: 186904 topic_id: 32194 reply_id: 128350[/import]