Over at http://www.falstad.com/circuit/ there’s a pretty awesome circuit emulator written in Java. The best part is that the entire source code is downloadable. I’m currently going thru it doing some basic formatting to make it more readable, but i’m curious if anyone has any tips for where to begin porting over a Java app into Codea/Lua. Since it’s all about drawing a circuit, and rendering how current flows thru it, it would be an ideal fit for a project in Codea, which is based around drawing a picture 60 times a second.
Firstly, make a list of all the classes - each Java class can in theory be represented by one in Codea, I haven’t looked at the app (not got the plugin installed on my work laptop) - however most Java apps are usually based on the event based model - that is behind the scenes the code runs in a tight loop and waits for an event to occur and when it does it, a function is called (usually a button handler to handle the button press).
Out of the box Codea doesn’t really support the event based model, you have to do it yourself, I’d suggest looking at the Cider library which does provide UI widgets, alternatively you can create your own. A simple UI button system would allow you to define a “button” as a 2D box on the screen which is added to a list along with a handler function. To draw the buttons you simply loop through the list each frame drawing each one, and then to handle button presses you loop through the list in the “touched” function and see if the touch location is within the bounds of the button box and if it is you call the associated handler function.