Hi.
I modified a little bit the line drawing code from gtatarkin.
The code didn’t draw lines with the same length. Perhaps it helps to find a good solution.
[lua]-- original source code: Gesture recognition library for Corona SDK
– http://developer.anscamobile.com/code/gesture-recognition-library-corona-sdk
– modified 110324 by sidasa
local moved = 0
local pointsTable = {}
local line
local function drawLine ()
if line then
line:removeSelf()
end
local numPoints = #pointsTable
local nl = {}
local j, p
local linewidth = 5
nl[1] = pointsTable[1]
j = 2
p = 1
for i = 2, numPoints, 1 do
nl[j] = pointsTable[i]
j = j+1
p = i
end
if ( p < numPoints -1 ) then
nl[j] = pointsTable[numPoints-1]
end
if #nl > 2 then
line = display.newLine(nl[1].x,nl[1].y,nl[2].x,nl[2].y)
line.width = linewidth
line:setColor(0,0,0)
for i = 3, #nl, 1 do
– draw next “step”
if #nl > i then
line = display.newLine(nl[i].x,nl[i].y,nl[i+1].x,nl[i+1].y)
else
line:append( nl[i].x,nl[i].y);
end
line.width = linewidth
– change color every “step”
if i%2 == 0 then
line:setColor(0,0,0)
else
line:setColor(255,255,255)
end
end
end
end
local function Update(event)
if “began” == event.phase then
pointsTable = nil
pointsTable = {}
local pt = {}
pt.x = event.x
pt.y = event.y
table.insert(pointsTable,pt)
elseif “moved” == event.phase then
local pt = {}
pt.x = event.x
pt.y = event.y
table.insert(pointsTable,pt)
moved = 1 –
elseif “ended” == event.phase or “cancelled” == event.phase then
if( moved == 1 ) then
drawLine ()
moved = 0
end
end
end
Runtime:addEventListener( “touch”, Update )[/lua] [import]uid: 42078 topic_id: 8237 reply_id: 29407[/import]