lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 2017-04-25 11:14, Enrico Colombini wrote:
Back to the subject: I think interactive graphics are a very
effective tool to teach programming, because they give a large
amount of feedback. Unfortunately, current-day languages (or, I
should say, programming environments) tend not to offer built-in
simple graphics. By "simple graphics" I mean no-hassle instructions
that draw directly into the output window, such as LINE. They can be
used to directly illustrate concepts, visualize data, keep attention
focused and so on.

LÖVE ( comes close to that.

  function love.draw( ) "fill", 100, 100, 50 )

is all it takes to get a (white, filled, usually(?) un-antialiased)
circle (on a black background) onto the screen (a window of 640x480?
800x600? something like that).

It includes pretty complex libraries (physics (box2d) & particle systems
are probably the worst) but luckily you don't need them and don't need
to mention that they exists.  There's some unfortunate design choices,
but it being Lua, most of these can easily be papered over.  (E.g.
drawables (polygons, splines, …) are drawn with and
have no (e.g.) :draw method, but has no protocol for
handling user-defined drawables (e.g. fall back to :draw if unknown).
So if you do not want to care what thing you get & just get it drawn,
you have to fiddle with the methods of all internal drawables (add draw
= or wrap to check for :draw.
There are a few more of those silly kinks, but overall it's quite usable.)

The current setup/loop graphics model is powerful but conceptually
harder to grasp for a programming beginner […]

While Love2D follows this model by default, (again) this being Lua, it
can be easily adjusted.  You can replace (the startup code
which eventually calls love.main), love.main (the main loop which
repeatedly calls love.update and love.draw) or provide a different
drawing library which wraps the low-level stuff & repaints after every
draw call and then just step through (coroutine!) a user-defined script
that you run (resume) inside the default update/draw loop.  (Beware of
double buffering if you do the latter – so maybe first paint to a canvas
/ frame buffer from the user script & then draw that one to the screen.)

(There are both love.keypressed/mousepressed/… event handlers and
love.keyboard.isDown/love.mouse.getPosition/… query functions, so you
can use whatever style you prefer.)

I'd say that if you have a good idea of what you want & have looked at
how love2d is structured, it's feasible to get a runnable prototype of a
beginner-friendly environment in about 1-2 hours.  (Yes, it really is
very hackable & close to usable.)  After a few more hours of polishing
it should be in acceptable shape to try it on real beginners.  (And then
you improve it over the next weeks/months – better error messages, …)

-- nobody