[lua]
local localGroup = display.newGroup()
local backback = display.newGroup()
local backback2 = display.newGroup()
local randomGroup = display.newGroup()
circleGroup = display.newGroup()
localGroup:insert(backback2)
localGroup:insert(backback)
localGroup:insert( circleGroup )
----Have user draw then send data----
local endPoint, startPoint
local lines, line, lx, ly, sx, sy = {}
local points = {}
–r,g,b = 255,0,0
lineWidth = 2
local drawPacket
local odd = true
local function draw(event)
if event.phase == “began” then
--Create the startpoint and endpoint of the line
startPoint = display.newCircle(0,0,lineWidth/2)
startPoint.x, startPoint.y = event.x, event.y
startPoint:setFillColor(r,g,b)
endPoint = display.newCircle(-100,0,lineWidth/2)
endPoint:setFillColor(r,g,b)
circleGroup:insert(startPoint)
circleGroup:insert(endPoint)
elseif event.phase == “moved” then
if not line then
if startPoint ~= nil then
print “I am now drawing the line”
--Append every point on the line depending one where the users finger is
line = display.newLine(startPoint.x, startPoint.y, event.x, event.y)
lines[#lines + 1] = line
line.width = lineWidth
line:setColor(r,g,b)
lx,ly = startPoint.x , startPoint.y
sx,sy = event.x, event.y
circleGroup:insert(line)
end
else
if math.sqrt((lx-event.x)^2+(ly-event.y)^2) > 5 then
--print “I am now appending the line”
line:append( event.x, event.y)
lx, ly = event.x, event.y
local dumb = display.newLine(-10,-10,-100,-100) --Create some shit that is a corona bug
display.remove( dumb )
end
endPoint.x = event.x
endPoint.y = event.y
if odd then
points[#points+1] = event.x
points[#points+1] = event.y
end
odd = not odd
end
elseif event.phase == “ended” then
if endPoint ~= nil then
line = nil
endPoint.x, endPoint.y = event.x, event.y
print “I have ended my touch, sending data”
points = {} --Reset Points table
print “Points table reset”
end
end
end
Runtime:addEventListener(“touch”, draw)[/lua]