Button extended with touch

My button extended to accept touch. This (and the previous code) use code from David Such. I modified the touch so it is limited to the size of the button. Buttons are rectangles for simplicity. In the course a student assignment will be to add David Such’s rounded rectangle to make the buttons more attractive.

When a button is touched it ‘responds’ by returning its label. This lets a program know which button was pressed.

The next step is to draw several buttons then extend that to a simple calculator.


I wonder if a calculator app isn’t better suited to a more conventional programming language. Codea, redrawing the screen 60 times a second, is more about animation and movement, and while it is certainly possible to create a UI on screen, as the Cider project shows, it doesn’t seem to be to be the natural direction for Codea programming.

I’ve written a number of tutorials which (I hope) do focus on Codea’s strengths. You are welcome to draw from them, at http://coolcodea.wordpress.com/.

You may be right. I have looked at your code and I will used some of it as I can.
The purpose of a calculator is to introduce people, who may be new to programming, to some basic ideas. First a box, then text, an array intro, an array of buttons, then the calculator. It is not a work of art, just a demonstration of how things might be done. After the calculator we move into circles, rectangles, animation, sprites, tweens, and more. Any suggestions are welcome.

i would make it fun, first of all, because programming is hard.

a calculator isn’t much fun, that is why i started with a bouncing ball

I will thing about re-ordering things.

Thanks @Brucewe for the code, helped me.

Nice code.