Testing out APIs and different notations - It got me thinking on how others see the situation and what is easier/more accessible.
Currently, in order to draw a circle and animate it's X property, this is what we do in LÖVE:
Code: Select all
local x = 100
love.draw = function()
love.graphics.circle("fill", x, 200, 40)
end
love.update = function(dt)
x = x+100*dt
end
Code: Select all
--below is the function that creates circles in the "new" notation, just to show how it works
newCircle = function(t)
self = {}
self.x = t.x or 0
self.y = t.y or 0
self.radius = t.radius or 0
self[1] = t[1] or "fill"
self.draw = function()
love.graphics.circle(self[1], self.x, self.y, self.radius)
end
return self
end
--Creating our circle
ball = newCircle{x=100, y = 200, radius = 40, "fill"}
love.draw = function()
--draw it!
ball.draw()
end
love.update = function(dt)
ball.x = ball.x+100*dt
end
How do you feel about this?
What would your ideal system be?
PS: Just for fun, how it would look in Moonscript:
Code: Select all
newCircle = (t) ->
@ = {}
@x = t.x or 0
@y = t.y or 0
@radius = t.radius or 0
@draw = ->
love.graphics.rectangle("fill", @x, @y, @radius)
return @
ball = newCircle{x=:100, y:200,radius:40}
love.draw = ->
ball.draw!
love.update = (dt) ->
ball.x += 100*dt