My Codea Library

Now that we have project importing, it makes it easier to have a “library”. I’ve adapted my code so that just about anything that I think I might use again goes in a central library project. I’ve written some crude “import” code so that not everything gets imported every time.

Some of it is quite generic: UI, Touch handling (including gesture recognition), Colour manipulation, Font and textareas, Matrices, and more. So I thought I’d make it generally available. Some of it has been available from my website, but now that I can have it all in one project it is easier for me to keep in a version control system. You can get the code from:

http://www.math.ntnu.no/~stacey/code/CodeaLibrary

It is a bzr repository (bzr branch <url> <local dir>), but you can also just grab the code itself. Order isn’t important except that the Import.lua file must come before everything other than Main.lua (the relative placement of Main.lua isn’t important). To use a file in your code, save this lot in a project, add it to the imported list, and then in your own projection write import.library("<library name>"). It can also take a table of names, and there’s a import.all() function as well. The code protects from double importing.

Here’s a quick summary of what’s in the files. All of my work is CC0 when I’m allowed to do that. Some code is derived from other sources and so keeps the original licence. A couple of files aren’t really mine but are due to others on this forum.

  • BinDecHex.lua Based on some code I got off the internet - see header for details (and licence). Functions for manipulating and converting binary, octal, decimal, hexadecimal numbers.
  • Colour.lua Functions for manipulating colours such as blending, shading. Also includes a colour picker. CC0.
  • ColourNames.lua Define colours by name: either svg or x11. Derived from a LaTeX package and so licensed under the LPPL.
  • Complex.lua Complex numbers class, including functions acting on such. Includes overloading some of the math. functions so that they work on complex numbers. CC0
  • ComplexPlane.lua Code for visualising complex numbers on the complex plane. CC0
  • Coordinates.lua Defines some “anchors” around the screen. Idea being that these are more intuitive than writing the coordinates literally. CC0
  • DataSeries.lua This one isn’t mine. I want to say that it’s by @Mark, but I can’t find where I got it from right now. It, together with Frame.lua and TrendGraph.lua draws nice graphs of stuff in real time.
  • Debug.lua Not really well developed. Idea was to have a textarea where classes could send their debugging information. CC0
  • EuclideanPlane.lua For visualising the Euclidean plane and matrix actions thereon. CC0
  • Fireworks.lua Originally from this discussion. Licence unknown.
  • Font.lua This started out before we had native text handling, but it still does useful stuff. Of main interest will probably be the textarea class. CC0
  • Frame.lua See DataSeries.lua
  • Import.lua This sets up the code for importing other stuff so that it’s optional.
  • Keyboard.lua Once upon a time, Codea didn’t have access to the iPad keyboard. I still think it’s useful to have a keyboard that’s more manipulable than the Real One. CC0
  • Keypad.lua Simulates a phone keypad (or a computer numeric one). Again, originates from the pre-keyboard era but is still useful as it’s not so intrusive as the whole keyboard. CC0
  • Main.lua Idea is that this will provide tests for all of the classes. At the moment, it demonstrates the UI/Menu system and does some tests for the Complex and Vector classes. CC0
  • Matrix.lua Matrix class for … matrices. Also includes code to display and change a matrix (for the EuclideanPlane project). CC0
  • Menu.lua This provides a menu system, whereby it is easy (!) for things to define and use menus. A one-item menu looks awfully like a button. CCO
  • NumberSpinner.lua A Number Spinner! For choosing numbers. CC0
  • Playlist.lua This was written to make it easy (!) to write a demonstration of a program. Most of my programs are interactive, but for making videos then I often want more control than I can get by myself, and also want text on the screen to show what’s going on. This makes that easy (!) to do. CC0
  • Quaternion.lua If you know what they are, you’ll know what this is for. If you don’t, be thankful. Written originally as quaternions are good for encoding rotations. CC0
  • Shape.lua One of my earliest projects was a 3D shape explorer. This is the code for the overall shape class. CC0
  • ShapeElements.lua A Shape needs lots of pieces: vertices, edges, and the like. CC0
  • Shapes.lua Specific shapes. CC0
  • Slider.lua On-screen version of the sliders in the Output pane, but with callbacks instead of merely setting parameters. CC0
  • Space.lua This started out as part of the Shape system. It’s for interacting with a project as if it were 3D and manipulating the view via touch and moving the iPad. CC0
  • TestSuite.lua This is so that other classes can define “testsuites” that can then be examined when this project is run by itself. CC0
  • Touch.lua A general touch handler. It gathers all touches to itself, then analyses them, and hands them to other objects together with a fair amount of extra information to make it easier for objects to recognise different gestures. CC0
  • TrendGraph.lua See DataSeries.lua.
  • UI.lua User Interface class. Lots of the other classes are really only run via the UI class. For example, instead of invoking the keyboard directly, you would ask the UI class to get a string and it would then invoke the keyboard.
  • Utilities.lua Some auxiliary functions that don’t fit elsewhere (such as a mesh-based rounded-rectangle). CC0
  • Vec3.lua Believe it or not, the vec3 object used not to have any methods and this was to obviate that lack. CC0
  • Vector.lua For arbitrary length vectors, including vectors of complex numbers. Standard methods, also now includes an implementation of the Fast Fourier Transform. CC0
  • utf8.lua For manipulating utf8 strings. Lua can handle unicode, but some of the string manipulation functions work on bytes rather than characters. CC0
  • utf8Case.lua Auxiliary file for the utf8 library which contains the unicode upper/lower case table. Derived from a file on the unicode website which has no licence.

Brilliant - thanks for sharing.

This is very helpful. Thank you so much for posting this library.

That is a massive library @Andrew. Looks incredibly useful, thank you for packaging it up and sharing it so generously.

This my url contains an index of Codea and Lua sites…
Thanks for your work.
Elvio - Alessandria - Italy

http://memolinux.altervista.org/joomla/codea-index

Ho

@Andrew_Stacey Hi Andrew, do you know an easy way to copy the whole library directly in the ipad from the adress you gave? None of my apps seems to work, and i don’t want to use a PC to do the download (i’m trying to do everything from the ipad) Could you zip the library and put it on github? Ho no, please don’t kick my ass… :wink:

I can put up a zip file, sure. Does it have to be on github? I don’t have an account there. As for getting it on to your iPad, I’m afraid I don’t know an easy way without a computer. I use libimobiledevice on a Macbook or Linux machine as I don’t need to jailbreak for that.

Okay, I’ve uploaded them as a zip file and a single file:

@Andrew_Stacey. Wow! You are such a nice guy, I ow you that one, thanks!
Now I get it really easy:

  • I put the zip adress in Safari, which download the file and propose open in… dialog,
  • I choose open in phone drive, where I dezip the file easily
  • then with iFiles I copy and paste the directory in Codea
    This take less that 1 mn, all on the iPad only, but I need the Jailbreak to get iFiles (by the way the jailbreak of IOS5.1 with Absynthe is really easy on iPad1). I don’t know how to do it without the jailbreak, because .codea files do not open in Codea. By the way, there is a number of apps that support the unZip… Why not Codea then? Maybe it would be accepted… Nahhh, forget it, Big Daddy will never agree…
    Thanks a lot for your help. ^:)^

@Andrew_Stacey hi! I’ve tried to use you library but i have experienced a strange behavior. Wen i open the project i see all the tabs, then everthing is fine. I went through the ComplexPlane tab for instance, no problem. But on some other tabs, like shape or UI, codea suddenly closes after some time scrolling the tab. I though this was maybe due to very long comments (many lines) but i am not sure. I don’t run the project, i just read it from my ipad in codea. Any idea of what is happening? I have an ipad 1 , and last release of codea. Thanks for your help.

This is awesome, Andrew. Even more awesome would be some examples of use. If you have any, I’ve not found the link. I might try some of them and if so will post examples here somewhere. In any case, great for learning and borrowing. Thanks! :slight_smile:

@Jmv38 I suspect that might be to do with the current memory bugs, but I can’t say for sure.
Fortunately, you don’t need to load the code in the editor to use the library.

@RonJeffries I have been thinking of doing that. If you have any suggestions or requests, please say so.

Darn! I can’t even figure out how to select these and copy them to the copy buffer. Weird?

Can’t really help on that. I use a filesystem access method to transfer stuff to and from my iPad.

@RonJeffries http://www.digidna.net/products/fileapp (Free)
works great. You can download the zip file, unzip it, open each text file and “select all” at will.

-scottyd