About
Andrew Stacey
Information about my research, teaching, and other interests.
By: Andrew Stacey
Contact details
Wed, 16th Nov 2011 (HowDidIDoThat :: iPad)
Codea
When I switched to using a computer for my lectures instead of a chalkboard, I also took the opportunity to add a few animations/simulations to my lectures (see applets). Then I started using my iPad for the lectures, which meant that those applets would no longer work, even over the internet (as they use processing which is built on java). Fortunately, I was told about Codea (formerly known as Codify). As luck would have it, this is heavily influenced by processing so my applets should transfer -- once I've learnt a bit of lua.
Codea has its own forum and wiki. Here, I'll mainly put links to my code.
Unless otherwise stated, all of my code is placed in the public domain to the extent governable by law. Explicitly, I place it under the CC0. The code that this does not apply to is that which I have derived from someone else's code or code that has been adapted from some other format.
Note Regarding Attribution
Code that is placed in the public domain does not require attribution. However, if you have found this code useful, the best way to say "Thank you" is to point others to it.
Library Files: These are "auxilliary" files rather than individual projects.
- BinDecHex.lua Functions for converting between binary, decimal, hexadecimal, and octal numbers; this was harvested from the net from http://www.dialectronics.com/Lua/ except for the octal commands. This is released under the original licence (see the code or the above link for details).
- Colour.lua Functions for manipulating colours (formerly a class, now a series of standalone functions).
- ColourNames.lua Defines two lists of common colours based on the SVG and X11 definitions.
- Font10x20.lua
Defines a fixed-width font 10x20 for use with
Font.lua. Based on a font from the X11 distribution and so covered by the same licence. - Font8x16.lua
Defines a fixed-width font 8x16 for use with
Font.lua. Based on a font from the X11 distribution and so covered by the same licence. - Font.lua
A class for defining and using a bitmap font.
For defining the fonts, there is a fontforge script (for OpenType fonts I recommend using
otf2bdfwhich is in Debian and so probably in every other Linux distribution) and bdf conversion script. - FontTimesRoman.lua
Defines a variable-width font based on Times Roman for use with
Font.lua. Based on a font from the X11 distribution and so covered by the same licence. - Keyboard.lua This class defines a rudimentary keyboard object which can be used to get text input from the user (needs considerable work!).
- Keypad.lua This class defines a keypad object which can be used to get text input from the user.
- Menu.lua This class defines a menu object which can be used to present the user with a menu-based way of interacting with a program.
- Quaternion.lua This class is for handling quaternions, originally as a way of encoding rotations of 3-space.
- Shape.lua The classes in this file are for rendering 3D shapes using a "ball and sticks" model.
- Slider.lua This class provides a slider whereby a user can set a parameter.
- texgyreadventor-12pt.lua
This class and the following similarly named ones define fonts based on those from the TeX Gyre collection at various sizes for use with
Font.lua. These are released under the same licence as the original fonts (see the above link). - texgyreadventor-24pt.lua
- texgyreadventor-128pt.lua
- texgyreadventor-32pt.lua
- texgyreadventor-48pt.lua
- texgyreadventor-64pt.lua
- texgyrebonum-12pt.lua
- texgyrebonum-24pt.lua
- texgyrebonum-32pt.lua
- texgyrebonum-48pt.lua
- texgyrebonum-64pt.lua
- texgyrecursor-12pt.lua
- texgyrecursor-24pt.lua
- texgyrecursor-32pt.lua
- texgyrecursor-48pt.lua
- texgyrecursor-64pt.lua
- texgyreheros-12pt.lua
- texgyreheros-24pt.lua
- texgyreheros-32pt.lua
- texgyreheros-48pt.lua
- texgyreheros-64pt.lua
- texgyreheroscn-12pt.lua
- texgyreheroscn-24pt.lua
- texgyreheroscn-32pt.lua
- texgyreheroscn-48pt.lua
- texgyreheroscn-64pt.lua
- texgyrepagella-12pt.lua
- texgyrepagella-24pt.lua
- texgyrepagella-32pt.lua
- texgyrepagella-48pt.lua
- texgyrepagella-64pt.lua
- texgyreschola-12pt.lua
- texgyreschola-24pt.lua
- texgyreschola-32pt.lua
- texgyreschola-48pt.lua
- texgyreschola-64pt.lua
- texgyretermes-12pt.lua
- texgyretermes-24pt.lua
- texgyretermes-32pt.lua
- texgyretermes-48pt.lua
- texgyretermes-64pt.lua
- Touch.lua This is a general purpose touch handler.
- UI.lua This is a container class for all the user-interface objects.
- utf8Case.lua This contains the arrays for converting utf8 characters between upper and lower case. The information in this file was derived from the unicode specification, specifically ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt. (A brief search turned up no information as to the correct licence for this information.)
- utf8.lua This contains a family of functions for dealing with utf8 strings.
- Vec3.lua This class represents a 3-vector, and defines a fair few functions for manipluating them.
Projects:
Since the most recent version of Codea does not allow direct import of code, the files themselves are available for cut-and-pasting in a directory or as a single (but large!) files for cutting and pasting into Codea.
Cube Single file or directory. This is a 3D shape viewer and editor. It makes use of several of the files in the Library, amongst others the user interface, the font, the touch handler, and (of course) the shape renderer.
Bit Invader with Tilt Controls Single file or directory. This is a minor modification of one of the demo programs that uses gravity to control the game. There are two modes (controlled by the boolean
hero.TrueGravity). One in which gravity acts as gravity (thus controlling the acceleration) and one in which it acts as a control (thus controlling the velocity). In the first case, the "ship" bounces off the sides. In the second case, it rests against a side when it reaches it.Update (2011-12-09) Tilting the iPad vertically now does something. If
TRUEGRAVITY(now a global boolean, by the way) is false then tilting the iPad slows down or speeds up the vertical speed of things: towards you for slowing down, away for speeding up. The initial tilt is used as a base against which to measure subsequent tilting. IfTRUEGRAVITYis true then the effect is more sublte. It is still the case that tilting it towards you slows things down and away speeds them up, but the effect has a decay so that it only lasts a certain time.Particles Single file or directory. This simulates particles in a box. You introduce particles to the box by touching the screen; if you "flick" it then they get given an appropriate initial velocity. They then proceed to bounce around the box and bounce off each other. All collisions are totally elastic. The colour changes depending on the speed of the particle, from blue to white (not very physically accurate). It is possible to specify a lifetime for the particles, and also to allow them to escape from the box if they get enough energy. The temperature (average kinetic energy) is displayed in the parameter box.
Complex Plane Single file or directory. This is for exploring the complex plane by drawing points on the plane and seeing how they transform under various operations such as addition, multiplication, and taking roots.
Anagrams Single file or directory. This is a simple anagram program (the current word list is very simple). Rearrange the words to match one from the list (celebration effect adapted from http://www.twolivesleft.com/Codea/Talk/discussion/396).
Hangman Single file or directory. This is a hangman program (still a bit rough around the edges). (Same celebration as the anagram program.)
Pendulum Single file or directory. This is a simulation of two pendulums. The pendula can be coupled, they can run with the "small angle approximation" or not, with friction, and various parameters can be adjusted.
Note Regarding Cutting-and-Pasting
Cutting-and-pasting from a text file on the web is a little tricky on the iPad itself.
In my experiments, I couldn't select more than a word when using Safari Mobile (I managed a line once).
Using Opera Mini, I managed to select a whole page but then the Copy dialogue was at the other end of the selection ... off the screen.
The method I found that worked was to use an app that let me download and edit text files from the web.
Two that do this are GoodReader and FastKeyboard.
Then I download the file, go as if to edit it, and select-and-copy the whole document.
This gets it into the clipboard from where I can paste it into a Codea file.
Beta Software
I'm now a beta tester for Codea. The following projects were developed using features available in a beta version. If the corresponding Codea version has been released, they might work anyway.
- Anagrams Version of the above using native iOS5 fonts, Codea file and Movie (developed on the beta for Codea 1.3).
[Full link]
Last modified on:
Sat, 14th Jan 2012