1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| local physics = require "physics"
physics.start()
--physics.setDrawMode("hybrid")
local line1 = display.newRect(100,100,5,100)
local line2 = display.newRect(100,100,5,100)
line2.rotation = 90
local circle = display.newCircle(100,150,15)
physics.addBody(circle,"static")
local lines = {}
local isReverse = 1
local function rotate()
if isReverse == 1 then
line1.rotation = line1.rotation + 5
line2.rotation = line2.rotation + 5
if #lines == 0 then
lines[#lines + 1] = display.newRect(0,0,1,3)
lines[#lines].x = circle.x + circle.width * 0.5
lines[#lines].y = circle.y
physics.addBody(lines[#lines],{density = 0.01})
else
lines[#lines + 1] = display.newRect(0,0,1,3)
lines[#lines].x = circle.x + circle.width * 0.5
lines[#lines].y = lines[#lines - 1].y + lines[#lines - 1].height
physics.addBody(lines[#lines],{density = 0.01})
end
if #lines == 1 then
myJoint = physics.newJoint( "pivot", lines[#lines], circle, lines[#lines].x,lines[#lines].y )
else
myJoint = physics.newJoint( "pivot", lines[#lines], lines[#lines - 1], lines[#lines].x,lines[#lines].y )
end
myJoint:setRotationLimits( -45, 45 )
else
line1.rotation = line1.rotation - 5
line2.rotation = line2.rotation - 5
lines[#lines]:removeSelf()
lines[#lines] = nil
end
end
timer.performWithDelay(70,rotate,0)
local function changeDirection()
isReverse = 1 - isReverse
end
local button = display.newText("tap me to change direction",200,0,native.systemFont,36)
button:addEventListener("tap",changeDirection) |