Hi
I have stiched this small code together, just for playing with codea.
I wonder if there is a way to optimize the code, as it gets quite ‘heavy’ rather fast.
I think it is the quite complex form of the physics.body that makes things slow down.
I guess a solution would be separating the ‘body’ and ‘drawing’ and make a less complex physics model?
--# Main
function setup()
noSmooth()
supportedOrientations(PORTRAIT)
displayMode(FULLSCREEN)
lineCapMode(PROJECT)
l = {}
count = 0
strokeWidth(1)
edge1 = physics.body(EDGE, vec2(0,0), vec2(WIDTH, 0))
edge2 = physics.body(EDGE, vec2(0,0), vec2(0, HEIGHT))
edge3 = physics.body(EDGE, vec2(WIDTH,0), vec2(WIDTH, HEIGHT))
edge4 = physics.body(EDGE, vec2(0,HEIGHT), vec2(WIDTH, HEIGHT))
edge1.type = STATIC
edge2.type = STATIC
edge3.type = STATIC
edge4.type = STATIC
edge1.restitution = .1
edge2.restitution = .1
edge3.restitution = .1
edge4.restitution = .1
end
function draw()
physics.gravity(Gravity)
background(176, 208, 32, 255)
for i in pairs(l) do
l[i]:draw()
end
end
function touched(touch)
if touch.state == ENDED then
l[count] = logo(CurrentTouch.x, CurrentTouch.y)
count = count + 1
end
end
--# logo
logo = class()
function logo:init(x,y)
self.l = physics.body(POLYGON,
vec2(0,60),
vec2(0,160),
vec2(40,90),
vec2(120,130),
vec2(120,40),
vec2(110,30),
vec2(110,110),
vec2(50,80),
vec2(50,5),
vec2(40,0),
vec2(30,11),
vec2(30,80),
vec2(10,115),
vec2(10,40)
)
self.l.x = x
self.l.y = y
--self.l.restitution = .9 --restitution
end
function logo:draw()
--fill(255, 255, 255, 255)
pushMatrix()
translate(self.l.x, self.l.y)
rotate(self.l.angle)
for j in pairs(self.l.points) do
a =self.l.points[j]
b =self.l.points[(j % #self.l.points)+1]
line(a.x, a.y, b.x, b.y)
end
popMatrix()
end