rectangle elongate

I need to elongate, extend, make longer or whatever when i “slice/drag”. Something like in flow game, when you need to rech one point to other, or WordSearch ( https://play.google.com/store/apps/details?id=com.melimots.WordSearch ) when you drag to get two letter. In the last case is not exactly my case, because isn’t a square that’s make longer.
Pff, it’s hard to explain.

http://imgur.com/pPSYf
http://i.imgur.com/pPSYf.jpg

It works if it’s horizontal, but if it get degrees, it doesn’t work.

This is the code:

[lua]–
– Project: puzzle
– Description:

– Version: 1.0
– Managed with http://CoronaProjectManager.com

– Copyright 2012 . All Rights Reserved.

local rectangulo
local ultimo

function dibujar_linea( event )
–local t = event.target
local phase = event.phase
–ultimo = event.xStart

if “began” == phase then

rectangulo = display.newRect( event.x, event.y, 1, 20 )
rectangulo:setReferencePoint( display.TopLeftReferencePoint )
display.getCurrentStage():setFocus( rectangulo )
print(“entrando”)
–ultimo = event.x
rectangulo.x1 = event.x
rectangulo.y1 = event.y
end
if “moved” == phase then
–esto si es el movimiento x
display.getCurrentStage():setFocus( rectangulo )
–rectangulo.x1 = rectangulo.x

rectangulo:setReferencePoint( display.TopLeftReferencePoint )
rectangulo.width = ( event.x - event.xStart )
rectangulo:setReferencePoint( display.TopLeftReferencePoint )
rectangulo.x = event.xStart

–print(“moviendo mas”)
–si es el movimiento y
–if event.yStart ~= event.y then
– print("muevo y: "…event.y)

–copiado
rectangulo.x2 = event.x
rectangulo.y2 = event.y

angle1 = 180/math.pi * math.atan2(rectangulo.y1 - rectangulo.y , rectangulo.x1 - rectangulo.x)
angle2 = 180/math.pi * math.atan2(rectangulo.y2 - rectangulo.y , rectangulo.x2 - rectangulo.x)

print("angle1 = "…angle1)

rotationAmt = angle1 - angle2

if rotationAmt < -4 then
rotationAmt = -4
elseif rotationAmt > 4 then
rotationAmt = 4
end

–rotate it
rectangulo.rotation = rectangulo.rotation - rotationAmt
print ("t.rotation = "…rectangulo.rotation)

rectangulo.x1 = rectangulo.x2
rectangulo.y1 = rectangulo.y2
–fincopiado

– end
else
if “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )

end
end
end
Runtime:addEventListener( “touch”, dibujar_linea )

–rectangulo2 = display.newRect( 100, 100, 100, 20 )
local function rotateObj(event)
local t = event.target
local phase = event.phase

if (phase == “began”) then
display.getCurrentStage():setFocus( t )
t.isFocus = true

– Store initial position of finger
t.x1 = event.x
t.y1 = event.y

elseif t.isFocus then
if (phase == “moved”) then
t.x2 = event.x
t.y2 = event.y

angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)

print("angle1 = "…angle1)

rotationAmt = angle1 - angle2

if rotationAmt < -4 then
rotationAmt = -4
elseif rotationAmt > 4 then
rotationAmt = 4
end

–rotate it
t.rotation = t.rotation - rotationAmt
print ("t.rotation = "…t.rotation)

t.x1 = t.x2
t.y1 = t.y2

elseif (phase == “ended”) then

display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

– Stop further propagation of touch event
return true
end
–Runtime:addEventListener( “enterFrame”, rotateObj )[/lua]

It doen’t need images, u can compile it. Thanks.
PS: resume

I need a rectangle that make longer wherever i slice/drag it.

I’m so bad explaining. [import]uid: 116842 topic_id: 33054 reply_id: 333054[/import]