Playground feature

Back to General discussions forum

Rodion (admin)     2023-12-07 18:24:29
User avatar

Hi Friends! I'm sorry for not creating new problems myself for past few weeks.

But meanwhile there is coming small new feature which can be of some use. As some of you have noticed, I'm trying to create meek set of small lessons targeted to those who are at very beginning and struggle even with the simplest problems. Lessons use again the same Lua for examples and exercise, but for advanced users all this is unimportant.

Playground is a kind of small notebook which allows to create and run some code in the same way used in "school". Particularly it allows creating tiny applications with simple graphics. It is supposed that beginners after learning some basics may want to create "something" persistent and shareable to show friends etc. So such programs are saved and could be shared by direct link.

And in that sense it may be useful not only for beginners. When there are no new interesting problems, you can amuse colleagues trying to create small visual puzzles.

As an example, I just have completed a kind of well-known Memory Game.

Besides the games simply curious animations could be created, e.g. Lines Example or Random Circles.

To use the feature, navigate to "school" page and then to "saving and sharing your programs". The few functions available for drawing and user-interaction are mainly found on pages titled "Graphics - ..." Actually your abilities are not limited to existing functions, they are simple wrappers around JS calls - but feel free to request what other useful functions may be necessary to be added urgently. And other suggestions, of course.

qwerty     2023-12-09 18:36:39

Hey, Rodion.

Thank you for this interesting feature!

Here is my first attempt at playground: Necklace

Rodion (admin)     2023-12-10 06:22:55
User avatar

Wow, thanks for giving it a try! (actually I haven't expected anyone would spent much time trying but your code probably took at least hour or two to compose!)

These necklaces reminded me of something I read probably in Gardner's books, but googling at the morning I found it is seemingly well-known combinatorics problem! Necklaces and Bracelets I wonder are you studying this right now for some purpose or the idea just come up randomly :)

BTW: few minor additions happened which may be convenient, particularly comments of special type could be added to the program, e.g.

--play:title:Necklace Builder
--play:console:0
--play:canvas:800

The last two define the height of "output" box and "canvas" in lines and pixels correspondingly, with 0 meaning hide at all (if this or that is not used by program). I'll put this information somewhere at hand bit later...

qwerty     2023-12-10 14:28:26

Rodion, hi!

I remember studying that problem you linked (Necklaces and Bracelets), but this was a long time ago, so yesterday's idea came at random. I just saw your lesson on interactive graphics (where one can draw circles), and started to think: "How it is possible to improve this example?". And this is a result of these improvements.

You are right suspecting that this took a while. I am unfamiliar with Lua and it was quite a surprise for me that "not equal" operator is ~= and not != or <>. And that Lua's style of adding elements to lists looks more like PHP than Python's list.append(), though I must consider that they are not actually lists, but hash tables (and can serve both purposes, just like in PHP).

There was also difficulties with implementation, for example, I want lines to be drawn not between centers of circles, but between their perimeters, which required some trigonometry... I also did not want for players to accidentally draw an overlapping pearls, because this not make sense (they are solid objects and cannot share the same space). And implementing these toggle buttons was a bit of challenge, too! But I really liked all these challenges.

And thank you for that hint about comments of special type! I put these to program and it seems that they work nicely, except that console is not being hidden (can you take a look, please?).

qwerty     2023-12-14 17:37:33

A note to future readers: issue with setting console height seems to be solved now.

Rodion (admin)     2023-12-14 19:12:24
User avatar

Actually this was fixed immediately - it was not broken but I mistaken the correct magic word (console for output or something like this) - noticed it doesn't have effect in your case and quickly found my fault. Thanks to this case, though, now both words should work.

Also noticed you made some substantial improvements to visual interface :) As about syntax - I mostly agree, I mistake "not equals" virtually every time. BTW there seems to be two ways of appending elements

table.insert(list, element)
list[#list+1] = element

(well, in PHP there are also two)

I was wondering if it is safe and easy use 0-based arrays - seems working yet somewhat clumsy.

I want lines to be drawn not between centers of circles, but between their perimeters, which required some trigonometry.

Those without trigonometry knowledge could instead write filled circle over the line :) Though ideally this would require double-buffering technique (perhaps good point to think of it and add bit later) to avoid flickering - but perhaps there'll be no much flickering anyway. And perhaps we should also add sounds in future :)

TestUser     2023-12-16 08:45:24
User avatar

While adding Number Guessing Game it was found useful to be able to center text, so graph.align(...) function was added. Also there is now small link to short reference page to list useful functions etc.

Please login and solve 5 problems to be able to post at forum