Code: Select all
function fillTriangle(size,color,direction)
direction = direction or 1
local shape = Image.createEmpty(size, size)
distance = (size/2)
if direction == 1 then
for i = 0,distance do shape:drawLine(distance-i, i, distance+i, i, color) end -- up
elseif direction == 2 then
for i = 0,distance do shape:drawLine(i, i, size-i, i, color) end -- down
elseif direction == 3 then
for i = 0,distance do shape:drawLine(size-i, i, size-i, size-i, color) end -- left
elseif direction == 4 then
for i = 0,distance do shape:drawLine(i, size-i, i, i, color) end -- right
end
return shape
end
--EXAMPLE USAGE
while not Controls.read():start() do
screen:blit(110, 50, fillTriangle(128,Color.new(25, 100, 220),1))
screen.waitVblankStart()
screen.flip()
end
Another offering from me.[/img]