Category Archives: LiveCode

Evolution of Reactor Lab

Reactor Lab celebrated its 27th anniversary in March 2020. Starting in 2003, the desktop version was integrated with the Internet, with advanced features for that time.

These advanced features included automatic download and installation of updated files for off-line work, a conference (chat) room for discussions within Reactor Lab, and the ability to run process simulations involving local units and units at other locations in the same system. At that time, one could not assume constant connection to the Internet, as we do now. Once, from San Diego, I had a three-way discussion with a person in Michigan and a person in Turkey in the conference room.

I retired from the University of California at San Diego – UCSD – in 2014. Since then, my interest has shifted from the desktop version, which was constructed with LiveCode, to the HTML5-based Web Labs at this site.

This shift has been for a number of reasons, including omnipresent Internet connection in much of the world, almost everyone has access to the web and a web browser without having to download an application file, and the fast speed of Javascript built into web browsers.

That said, desktop apps have advantages over web pages such as saving data files to disk. In Web Labs, one has to go through an extra step to copy text from a popup window and save to a disk file. There are so many features that were built into the desktop Reactor Lab that duplicating them all in HTML5 might not happen.

I used to post standalone application files for Windows and Macintosh. With the evolution of operating systems and the evolution of LiveCode, I no longer wish to make the revisions necessary to build standalones.

However, one can continue to use the desktop Reactor Lab on Windows, Mac, and Linux. This can be done by opening Reactor Lab in LiveCode, version 8.0 or higher. LiveCode can be obtained at LiveCode.com. Download the free, open-source version of Reactor Lab from my github site at github.com/RichardHerz.

Instructions for how to do this are posted at the Download tab.

Web Lab development update

We now have six web labs posted. The newest is the dynamic heat exchanger simulation, and we recently updated the code structure of the reaction-diffusion lab and first temperature control lab to match the newest version.

In addition to the jquery and flot (plotting) libraries, each web lab is driven by six javascript files: (1) _main which runs the simulation loop, (2) _interface which handles the run-pause and reset buttons and gets and verifies inputs from the input fields, (3) _units which has simulation parameters and the process unit code, (4) _plot_info which contains definitions of the plots, (5) _plotter which makes the profile (static x,y) and strip chart (scrolling x,y) plots, and (6) _spacetime which makes the space-time, color-canvas plots.

Four of the six files are the same for all web labs. The two files specific to an individual web lab are the (3) _units and (4) _plot_info files.

We are amazed with the fast computational speed of javascript! Somewhere recently I read that the speed of javascript in browsers has increased by a factor of ten in the last year and a half. Years ago, computation in LiveCode (as MetaCard) was many times faster than javascript. Now, computation in javascript for our labs is much faster than native LiveCode script, although LiveCode 9 makes coupling to other languages for computation possible.

A feature unique to the heat exchanger lab is a check for attainment of steady state. When no significant changes to the system state are detected, the main simulation loop continues to run but unit computations and display updates cease until a change in input parameters is detected. When steady state is reached, the CPU load of the simulation decreases significantly. We don’t plan to implement this for the reaction-diffusion and temperature control labs because these usually operate under unsteady-state conditions.

The code is developing over time as we follow our usual development practice, which is repeat the following: (1) get something working, (2) notice repetition, (3) reduce repetition by writing functions and common library files.

LiveCode apps on the web – loading speed may improve dramatically

Experiments by others show that the speed at which LiveCode web apps load can be made much faster through several techniques. In my first experiment, the files loaded to the Western US from the LiveCode server in France. Putting the large files, which are common to all LiveCode web apps, on CDN’s (Content Delivery Networks), which post copies on servers around the world, may speed loading dramatically. Other techniques may include loading only the parts of the modular LiveCode engine that are needed for a specific app.

See work by [-hh] at the LiveCode Forums and click the link “test it here” on that post.

Initial impressions – HTML5 vs. LiveCode

The Reactor Lab desktop app is built with LiveCode, a cross-platform rapid application development tool. In the Resources, Web app experiments section of this site, we are experimenting with HTML5 technologies – Javascript and CSS – to make interactive web apps. Here are some initial impressions.

HTML5 web apps have the advantage of cross-platform deployment – of a single set of files – on all platforms (operating systems) via web browsers. Web apps don’t have all the functionality of desktop apps and smart phone apps but they do have the main functionality we are looking for. LiveCode has cross-platform deployment on the desktop and as smart phone apps but you have to build and deploy a separate distribution for each platform. Web deployment is under development in LiveCode version 8 but our initial experiments show that loading the first app is slow: about 40 s currently in my browser in California fetching the page from the server in France, where load times increase with distance from the server. But this is a development version of LC 8 and speeds may improve in the future. In contrast, HTML5 web apps are small and load fast.

Layout of LiveCode screens (“cards”) is easy and fast. Just drag and drop both active (e.g., buttons and widgets) and graphical elements. You can easily change the appearance and locations of elements with script when the app is running – so far it seems more easily than in HTML5. For HTML5 apps, we are using the desktop tool MACAW. In that tool, you can also drag and drop elements onto a page, then generate HTML and CSS files but not nearly as easily as LiveCode.

LiveCode is programmed with a very high level, English-like language that is easy to learn. Code (scripts) can be embedded in objects on the screen (e.g., buttons) or placed at a top level (card, stack). Proprietary code can be encrypted in the paid version. HTML5 web apps are programmed with Javascript. We have found Javascript easy to learn, although we have been programming for 50 years in a dozen languages, so we can’t say how easy it will be for a novice. The site w3schools.com is a great resource for learning Javascript, as well as HTML and CSS. Javascript is not attached to individual screen elements but placed at a top level, either in a script tag in the HTML file or, better, in a separate JS file. We haven’t tried text handling in Javascript but text handling in LiveCode is super easy.

Bottom line of initial impressions? LiveCode wins in ease of development and power. HTML5 wins in deployment – one set of files across all platforms – and speed of loading. We are leaning to devoting our efforts for future development to HTML5, although we are going to keep an eye on LiveCode to see if the speed of loading web apps improves significantly.

Livecode app on the web

We have added web app experiment 2 to the Resources, Web App Experiments page. This is a LiveCode 8 stack deployed in a web page. LiveCode 8 uses the open-source software Emscripten to compile the LiveCode engine to Javascript, which can then run LiveCode apps in a web page.

The advantage of this approach is that we can develop new apps quickly using LiveCode, which is a rapid app development tool.

One drawback is that a large Javascript file must be downloaded before a LiveCode web app can run. Once downloaded in a browser session, however, multiple stacks can be run without having to download the large file again.

This is very new technology for LiveCode and we expect much improvement in the near future. Get the free, open-source “Community” edition of LiveCode here (link).

LiveCode speed of execution

Reactor Lab was built using LiveCode. Get the free Community version at  LiveCode.org. LiveCode is great because it is cross-platform: write once and deploy on many platforms. Another advantage is that the stack model and scripting language are very stable in the sense of supporting past versions: some of the script dates from 1993 and HyperCard.

In most cases in Reactor Lab, the speed of LiveCode is sufficiently fast. The most demanding lab using math computations in LiveCode script is Division 7 Biological Reactions, Lab 3 Immobilized Enzyme Profiles. In that lab, as the user moves a slider to change an input parameter, LiveCode solves a second-order, ordinary differential equation using the iterative shooting method, and then updates the graphics.

Calculations in the dynamic Catalyst Pellet are too demanding to run in LiveCode script. That lab has a detailed, elementary-step simulation of carbon monoxide oxidation over a porous solid catalyst. A function was written in C++ to do finite-difference integration of a set of partial differential equations. The external is then compiled separately on Mac and Windows to make an “external” (.bundle on Mac, .dll on Windows). The LiveCode stack calls this external to do the calculations. The advantage of an external is that it is fast. The disadvantage is that you must compile a separate executable for each platform.

When the Catalyst Pellet external was written in 2008, we used Revolution 4, where Revolution was the earlier name for LiveCode. The Catalyst Pellet and its external ran great when we finished it but it is not compatible with later versions of LiveCode. Therefore we pulled the dynamic Catalyst Pellet out into its own standalone app. The problem presumably is that the interface specification between externals and LiveCode changed. The stack and its external initially appear to run in LiveCode 7, but there appears to be a memory leak and a crash ensues. We haven’t had the time to keep the external up to date. The original version posted in the Download section works well.

The speed at which LiveCode 7 updates the card graphics appears to have slowed from previous versions. This may be related to the addition of resolution independence and higher resolution target displays. To speed things up, we lock the screen before changing many separate elements in the display, then unlock the screen when everything on the card has been updated.