How to Build Your Terminator Brain

by Hanson Schmidt-Cornelius on September 10, 2015 2 comments

Do you like the Terminator films?

Would you like to build your own Terminator?

Here is a recipe for some of the components involved. As science is progressing, the two most challenging aspects to producing an autonomous agent like the Terminator are the energy supply and the processing capability that allow the Terminator to operate in a dynamic environment.

read more
Hanson Schmidt-CorneliusHow to Build Your Terminator Brain

From LiveCode to LiveMorphs

by Hanson Schmidt-Cornelius on May 7, 2015 No comments

Evolution and natural selection are fundamental principals on which science bases the existence and origin of all natural living beings. The fundamental rules of this process are very simple but provide a vastly powerful means by which adaptation to a particular environment can take place. Evolution is covered to varying depths in biology text books, explaining how these principals influence life on this planet.

read more
Hanson Schmidt-CorneliusFrom LiveCode to LiveMorphs

From Fibonacci to Dr Seuss

by Hanson Schmidt-Cornelius on December 4, 2014 1 comment


blog-text

If you were a Kool-Aid kid then chance has it you are familiar with Dr Seuss and the bizarre, illogical language he uses in his books. What a wonderful mind that can think outside of the box in such a beautifully unconventional, educational and humorous fashion. How could one possibly dream up sentences like: “One fish two fish red fish blue fish…”? Especially as this is not your typical every day level of conversation. 

In this blog I demonstrate how computers can assist us in constructing sentences with similarly bizarre meanings. 

 As hardware has become more powerful and the algorithms explored have become more advanced, computers have been shown to mimic limited reasoning abilities that are most often associated with intelligent beings. I know I am touching on a controversial area here, and I am steering clear of suggestions of artificial intelligence or artificial self-awareness. I make a short reference to the Turing Test here, for the interested reader. This test assesses if a computer can convincingly mimic or simulate the communicative responses of a human being. 

It would takes a bit more effort to implement an algorithm that is worthy of being entered into a Turing Test than we can cover here, but we will be looking at one computational aspect that may well be part of a larger solution. 

If you read our blogs on a regular basis you will know that we have touched on different ways of implementing number sequence generators in blog “Recursion for Runaways“. We are building on the concepts outlined there to create a Natural Language Sentence Generator. 

Before we can get our hands dirty with a bit of LiveCode, we need to take a step back and understand some of the basics that underlie the English language. 

If you are starting to get a déjà vu experience of some long forgotten classes at school, do not worry. We are only scratching the surface of the topics involved, leaving you to explore the relevant fields in more depth at your leisure.  

According to the global language monitor, the English language passed the 1 Million Word mark on June 10, 2009 with 14.7 new words being added every day. Our application is not going to utilize all of these words, in fact we are only going to use a very small subset of these words to build our Natural Language Generator. But in order to utilize any number of words we need to understand how groups of words are arranged in the English language. 

There are eight “Parts of Speech” in the English language that are used to group kinds of words together. These parts are: articles, nouns, adjectives, verbs, adverbs, prepositions, pronouns, conjunctions and interjections. The order by which these “Parts of Speech” are arranged in sentences is determined by rules. For example, a very basic sentence can consist of an article, a noun and a verb, arranged in that order: 

   “A man walks.” 

or 

   “The cat sleeps.” 

 By interchanging the articles, nouns and verbs you can create a large arrangement of sentences with different meanings. From a coding point of view we may store the words in some kind of storage mechanism, for example variables: 

    article = “A,The” 

   noun = “man,cat” 

   verb = “walks,sleeps”  

This could form part of a word database that may allow us to create the two sentences shown, but it would also allow you to create further new sentences, for example: 

   “The man sleeps.” 

   “The cat walks.” 

   “A cat walks.” 

In order to build the English Language Generator we use a database of words, similar to the ones used in the examples shown here. Randomly picking words from the “Part of Speech” entries and placing them in the “article, noun, verb” order is then a perfectly workable approach, but this arrangement would limit our expressive creativity somewhat and probably be quite boring after a while. What we need is some formalism or grammar that allows us to present and order the words in a more flexible fashion. This would allow us to only make changes to the grammar in order to control how the words are ordered. 

We use an array as a database for both the words and the grammar rules and call this database “DCG”:  

    local DCG 

We then add the rule to the database that we used to create the aforementioned sentences:  

   put “-art -n -v” into DCG[“-s”] 

 The tokens are “-art” (article), “-n” (noun) and “-v” (verb) for a sentence “-s”.  

Next we populate the database with words. This time we add a few more words, giving us a bit more freedom to create sentences: 

 

put “the,a” into DCG[“-art”]

 put “man,woman,child,cat,dog,pie” into DCG[“-n”]

 put “walks,eats,combs,cooks” into DCG[“-v”]

Using our rule and understanding of how basic sentences are constructed in the English language, we can now create sentences like the ones we have already discussed. With the word database shown here, and the basic sentence rule, we can create a total of 48 unique sentences. 

Now let us look at how LiveCode can take this kind of database and convert the content into sentences: 

   function evaluateSegment pSegment 

      repeat for each word tItem in pSegment 

         if tItem begins with “-” then 

            put evaluateSegment (item random(the number of items in DCG[tItem]) of DCG[tItem]) after tResult 

         else 

            put tItem & space after tResult 

        end if 

     end repeat 

     return tResult 

   end evaluateSegment 

 Yes, that is it. These ten lines of code are our English Language Generator. It processes the database and randomly selects words to create sentences that are grammatically correct, based on the grammar rules we presented. If you look closely you can see that this function is recursive. The recursive design allows us to create this compact implementation. It also gives us powerful means by which a more complex grammar can be interpreted and processed. 

 You can put this generator together by creating a button and adding the following code to the button script: 

local DCG  

on mouseUp 

   // Grammar Rules 

   put “-art -n -v” into DCG[“-s”] 

   // Word Database 

   put “the,a” into DCG[“-art”] 

   put “man,woman,child,cat,dog,pie” into DCG[“-n”] 

   put “walks,eats,combs,cooks” into DCG[“-v”] 

   // Create Sentence 

   put evaluateSegment (“-s”) 

end mouseUp 

function evaluateSegment pSegment 

   repeat for each word tItem in pSegment 

      if tItem begins with “-” then 

         put evaluateSegment (item random(the number of items in DCG[tItem]) of DCG[tItem]) after tResult 

      else 

         put tItem & space after tResult 

      end if 

   end repeat 

   return tResult 

end evaluateSegment 

This script creates the database each time you hit the button, allowing you to update the entries and apply them for each run. This code opens the message box and displays a sentence. 

Okay nice, we can randomly create sentences, but as you can see, this blog has not quite reached the end yet. Let us now move on to creating sentences with a bit more complexity and start to utilize the recursive nature of the “evaluateSegment” function. 

In order to update your code and implement the following changes you only have to replace the code in the // Grammar Rules and // Word Database sections of your “mouseUp” handler.  

First we update the // Grammar Rules and add the concept of a “noun phrase” (-np):  

   put “-np -v” into DCG[“-s”] 

   put “-art -n” into DCG[“-np”] 

 Fundamentally, this logic generates exactly the same sentences as with the rule we used earlier. The “-art -n” part of the sentence rule has been replace with a “noun phrase” part that itself defines “-art -n”. This means that “evaluateSegment” has to complete the “-np” rule before it can complete the “-s” rule. 

Now why are we creating something more complicated when the simple sentence rule was sufficient? 

Well, this new representation allows us to expand the grammar even further. We can now also add a “verb phrase” (-vp) to our grammar replacing the // Grammar Rules with the following syntax: 

   put “-np -vp” into DCG[“-s”] 

   put “-art -n” into DCG[“-np”] 

   put “-v -np,-v” into DCG[“-vp”] 

 A “verb phrase” can be a verb, as with our original grammar, but it can now also be a verb and a “noun phrase”, which in turn is an article, followed by noun. So what kind of sentences does this new grammar give us? It produces the same sentences as before but can also generate more complex sentences, such as:  

   “A man walks a dog.” 

or 

    “The child eats a pie.” 

We are now getting to a point where the grammar can use different numbers of words to construct English sentences. That is where recursion is in its element. 

This is progress, but let us look at even more complex constructs that can create sentences with thousands of words. – Meet “conjunctions”. Conjunctions are words that bind sentences together.  

For the next step we update the grammar rules again and also add some more words to our word database. Let us start with the // Grammar Rules first and replace them with: 

   put “-np -vp,-s -conj -s” into DCG[“-s”] 

   put “-art -n” into DCG[“-np”] 

   put “-v -np,-v” into DCG[“-vp”] 

Essentially we are now allowing sentences to be constructed as before, but we are also creating sentences that are joined by a conjunction.  

The // Word Database is updated by adding the following words as conjunctions: 

    put “and,or,but,so,because,although” into DCG[“-conj”] 

We now have a grammar that has the potential to generate massive sentences. This is because the grammar can join an arbitrary number of sentences through conjunctions. 

So what can we expect to be generated after this update? 

We can expect sentences like the following: 

   “A man eats the pie because the dog cooks.” 

   “A cat cooks so the woman eats.” 

Now these make sense to a degree but may not reflect everyday situations. We can also expect a lot of very different sentences with varying lengths that are total gibberish. In fact I have generated sentences that are several times longer than this blog post and at times even hit the recursion limit. It is natural that we sometimes hit that limit as we do not set any restriction on the length of sentence that can be generated. 

You will probably find that only a very few of the sentence generated make any sense at all. So have we created an English Language Generator or is this maybe more a “Dr Seuss quote generator”? 

Seeing how easy it is to string words together in a grammatically concise way is nice, but adding meaning to what they represent is maybe a skill best left to those with a unique awareness and understanding of themselves and the environment they live in, or as René Descartes may have put it: “Cogito ergo sum”. 

The English grammar is certainly more complex than I let on in this blog, but you now have a basic LiveCode framework to build a language generator with a lot more complex grammatical constructs. Try expanding the word database and the grammar rules to update and create your own language generator. If you are a linguist or know other languages, why not see if you can get some meaning out of this code in a different language.

read more
Hanson Schmidt-CorneliusFrom Fibonacci to Dr Seuss

Recursion for Runaways

by Hanson Schmidt-Cornelius on October 16, 2014 15 comments

Fibonacci-Spiral

If you like to tinker with maths and are looking for more exotic operators, for example to calculate the Factorial or the Fibonacci series, then this is something you are going to have to implement yourself in LiveCode. But there is no need to despair, this can be done pretty much with a single line, wrapped in a function definition.

MATHS HAZARD – You may skip the following paragraph if you are not a friend of mathematical definitions.

The Factorial of a non-negative number n can be defined as the product of all of its positive integers that are less than or equal to n, with the Factorial of 0 returning 1. The operator for Factorial is denoted by an exclamation mark (!), allowing us to write the operation as follows: n!

The following example demonstrates how Factorial is calculated for the number 6:

6! = 1*2*3*4*5*6 = 720

Now this does not seem to be too much of an issue to implement or write, but how do you go about writing a function in LiveCode that does all the heavy lifting for you, so that you do not have to write a long sequence of multiplications?

Well, there are fundamentally two algorithmic approaches you could consider. These are iteration and recursion. They both operate in quite different ways and have advantages and disadvantages.

Let us look at the iterative approach first, as this is possibly the programming paradigm most people are familiar with. 

We create a function that takes an argument for which we are calculating the Factorial product. This function then cycles through all the positive integers that are less than or equal to the initial argument and multiplies all of these integers together. The function result is the Factorial result.

function factI x
  local tProduct = 1
  local tCounter
  repeat with tCounter = 1 to x
     multiply tProduct by tCounter
  end repeat
  return tProduct
end factI

Now in order to implement this algorithm we need two local variables and a repeat loop. This keeps track of the result as it is being updated through each iteration of the loop. But what if you really do not want to be bothered with local variables and loops and keeping track of data?

Well, meet recursion. Recursion can remember all the data that is specific to an instance of a function call. This means that we can pretty much throw most of the code away that we use in the iterative approach. Yes, we do not need local variables and we do not need a repeat loop. In fact, we can calculate the Factorial of a number with a single line of code in a function.

A recursive implementation usually contains some kind of condition check so it knows when to stop and when to call itself. This has been implemented in the following code using an “if then else statement”. If we are below a certain value stop, otherwise call the function again, but with a changed argument.

function factR x
  if x < 2 then return 1 else return factR (x - 1) * x
end factR

Now that was not too painful, but what is actually going on here that allows us to write code that is so much shorter?

Consider calculating 6! and let us expand how factR calls itself at each recursive level:

Level 1: factR(6)
Level 2: (factR(5) * 6)
Level 3: ((factR(4) * 5) * 6)
Level 4: (((factR(3) * 4) * 5) * 6)
Level 5: ((((factR(2) * 3) * 4) * 5) * 6)
Level 6: (((((factR(1) * 2) * 3) * 4) * 5) * 6)
               (((((1 * 2) * 3) * 4) * 5) * 6) = 720

Note: The parentheses demonstrate the execution order at each level and are not intended to be interpreted in a mathematical sense. The commutative law applies.

So this gives us a total of 6 calls to the function factR for 6! 

Another number sequence we mentioned in the beginning is that of Fibonacci. This sequence received its name from Leonardo of Pisa who published the historical mathematics book “Liber Abaci” around 1202. Leonardo of Pisa was also know by the name Fibonacci.

This Fibonacci number sequence starts: 1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,. . .

 This sequence has fascinated mathematicians for centuries and reveals remarkable patterns that are very much linked to natural structures, such as the formation of shells, branches and even the arrangement of the seeds in sunflowers. My particular interest is the use of the Fibonacci numbers for the close approximation of the Golden Ratio.

A Fibonacci number is generated by calculating the sum of the previous two numbers in the Fibonacci sequence. This operation is quite different to that used to derive the Factorial number sequence, never the less, it is possible to also wrap this into an iterative and recursive implementation.

Calculating the Fibonacci numbers iteratively requires additional local variables, compared to calculating the Factorial numbers. We step through all of the Fibonacci numbers and create the next ones by adding the previous two numbers together.

function fibI x
  local tFirst = 1, tSecond = 1
  local tCounter, tSum
  repeat with tCounter = 3 to x
     put tFirst + tSecond into tSum
     put tSecond into tFirst
     put tSum into tSecond
  end repeat
  return tSecond
end fibI

 In order to implement this algorithm we need four local variables and a repeat loop. As with the Factorial calculation, this keeps track of the result as it is being updated through each iteration of the loop.

The recursive approach can again do away with local variables and the repeat loop, creating the implementation as follows:

 function fibR x
  if x < 3 then return 1 else return fibR (x-1) + fibR (x-2)
end fibR

 Now I am not going to demonstrate how the recursive levels are expanded here and would like to leave this for the reader to explore. What I would like to add is that calculating the Fibonacci number for 6 calls fibR a total of 15 times.

Now recursion (or meta programming as it is sometimes referred to) is great as it can really reduce your code and hide a lot of the complexity, but beware. Some algorithms are better suited to recursion than others, and recursion can be computationally more expensive than iterative approaches. For example, calculating 20! calls factR 20 times, and that is great. Calculating the Fibonacci number of 20 calls fibR a staggering 13529 times.

read more
Hanson Schmidt-CorneliusRecursion for Runaways

Koch Island: Fractal Basics with LiveCode

by Hanson Schmidt-Cornelius on August 22, 2014 11 comments

Have you ever thought it would be possible to create something that had an infinitely long edge in a confined area? Yes, it is theoretically possible. Math’s is full of this kind of stuff and even thinking about the very basics of this can be great fun.

Let us consider a little island that was discovered in 1904, not by an explorer or seafarer Helge von Koch, but the Swedish mathematician with that name. This island is a mathematical idea and is considered to be one of the first fractals. It starts out as a very basic geometric construct, an equilateral triangle, which is a triangle with equal angles and equal sides. This triangle is then reshaped by dividing each line into three equally long segments and then replacing the middle segment with another equilateral triangle. The base line of that new triangle is then removed, leaving a line with a pyramid in it. The algorithm can then be applied repeatedly on the new shape, again splitting each line segment into three segments and replacing the middle one with an equilateral triangle and then removing the base line of that new triangle. After only a few iterations, it becomes apparent that the curve surrounding the island becomes increasingly longer. In fact the length of the curve increases by one third at each iteration. At the same time, the island does not appear to grow excessively and take up much more area.

Now this is all great as a mind model and we can get the principal behind the process, but what is with the infinitely long edge in the confined area that we mentioned in the beginning? Well, we could consider drawing this kind of island on a sheet of paper and think about what that would entail. From a mathematical point of view, we can represent this, we have symbols to represent infinity and the LiveCode logo has one of these infinity symbols hidden in the fifth and sixth letters, but if we really wanted to draw such an island we would have to consider what infinite really means to us in the real world.

Regardless of how fast we could replace the line segments, if it took anything longer than infinitely quick, then it would take us infinitely long to draw the island. So that is a possible showstopper. Our pen would have to be able to draw lines that are very, very thin, in fact we would have to be able to draw lines that are infinitely thin. This would then also have an impact on visibility, as lines that are infinitely thin are hard to see or measure.

These circumstances are restrictive, but it should not stop us from considering such exercises and allow us to have fun with these kind of ideas that we can partially visualize with computers. The following LiveCode scripts allows you to draw what can only be considered the tip of the iceberg of Koch island.

You can create your LiveCode Koch Island generator as follows:

1. Create a new stack.

2. Create a button “New” and place script “New” into the button script.

3. Create a button “Iterate” and place script “Iterate” into the button script.

You now have your infinitely long island curve generator that draws the first few stages of this fractal. The code is intentionally short for the blog here and shortcuts were taken in order to get here. If you want to explore this concept in more detail and see how far you can dig into the fractal, then consider updating at least the following three areas:

1. Increase the accuracy by preventing rounding from real to integer numbers at each cycle.

2. Calculate the exact height of each new pyramid with a more accurate constant. You can get the exact value by using Pythagoras.

3. Filter out duplicate point entries from “the points of graphic “island””.

Hope you have fun with this simple fractal example!

********** Script “New” **********

on mouseUp
   if there is no graphic "island" then new graphic "island"
   set the style of graphic "island" to "polygon"
    set the points of graphic "island" to "100,100" & cr & "300,100" & cr & "200,273" & cr & "100,100"
 end mouseUp

********** Script “Iterate” **********

on mouseUp
   local tLastPoint, tCurrentPoint, tCurrentIsland, tNewIsland
   put empty into tLastPoint
   put empty into tNewIsland
   put the points of graphic "island" into tCurrentIsland
   repeat for each line tCurrentPoint in tCurrentIsland
      put calculateSegment (tLastPoint, tCurrentPoint) after tNewIsland
      put tCurrentPoint into tLastPoint
   end repeat
   put line 1 of tCurrentIsland after tNewIsland
    set the points of graphic "island" to tNewIsland
end mouseUp
 
function calculateSegment pP1, pP5
   local tP2, tP3, tP4, tTran, tHeight
   if pP1 is empty then return empty
   split pP1 by comma
   split pP5 by comma
   put pP1[1] - pP5[1] into tTran[1]
   put pP1[2] - pP5[2] into tTran[2]
   put pP1[1]-tTran[1]/3 into tP2[1]
   put pP1[2]-tTran[2]/3 into tP2[2]
   put (pP1[1]-tTran[1]/2) - tTran[2]/2.886 into tP3[1]
   put (pP1[2]-tTran[2]/2) + tTran[1]/2.886 into tP3[2]
   put pP5[1]+tTran[1]/3 into tP4[1]
   put pP5[2]+tTran[2]/3 into tP4[2]
      return pP1[1] & comma & pP1[2] & cr & tP2[1] & comma & tP2[2] & cr & tP3[1] & comma & tP3[2] & cr & tP4[1] & comma & tP4[2] & cr 
end calculateSegment

Koch

read more
Hanson Schmidt-CorneliusKoch Island: Fractal Basics with LiveCode

LiveCode for Tiger Moms

by Hanson Schmidt-Cornelius on May 23, 2014 3 comments

Over the last few years, more information has been emerging in the media, contrasting differences in education practices between Asian and Western parents and guardians, with books being published and reports appearing in prestigious journals. I do not intend to poke around in a bees nest here and will leave judgement on child education to the respective parents and guardians. 

What I do offer is an insight into how LiveCode can assist would be Tiger Mothers, parents and guardians who would like to raise their children’s mental maths ability and self-esteem.

In most societies, mathematics is part of an educational curriculum and there are a number of tested and proven approaches to teach this and encourage sprogs to enjoy their learning. However, especially when it comes to learning the basics of manipulating numbers and using mathematical operators, you may come across a degree of resistance.

Maybe this is because a certain games console is being neglected or there is a lack in agreement on the importance of being able to add a couple of numbers together. On the other hand you may find yourself with a child who is just purely bored with the level of mathematics offered at school and requires more challenging content. And no, the latter kind of children are not just fabled beings, they do actually exist and can be a challenge to work with.

There are of course applications that teach maths, and there are text books that have problems upon problems your kids are encouraged to indulge in. These tools are limited by what the application designers consider appropriate or by the number of equations one can squeeze on the page of a textbook. As most parents/guardians will know, children develop at different speeds, and motivation can be a balancing act between joy and tantrums.

This is where LiveCode comes in. Properly applied, LiveCode can help you emerge victorious from any battle and empower you to generate an endless numbers of equations that are at the right level for your child.

And of course the answers are also provided, allowing you to keep your street cred. Children have a miraculous tendency to remember events where you display any sign of weakness, and they utilize this knowledge to maximize their advantage in the next round of homework activities.

The code in this blog is a mathematical problem generator that can be placed in the script of a button control and modified at will. There is no woolliness in the code, only functionality that serves the purpose of generating equations for endless fun at learning.

You can of course modify the code to create your own stack that populates the configuration information with the appropriate variables and outputs the problems in a more interactive fashion. If you are really adventurous, why not ask your child to update the code for you, teaching them to build their own learning aids. 

I have added comments after the lines of code that are intended to be updated. These lines set variable values that control how the problems are generated:

1. tOperators stores a list of operators that should be used in the equations.

2. tInputRange1 defines the range of the first number in the equations.

3. tInputRange2 defines the range of the second number in the equations.

4. tOutputRange specifies the range of valid result values.

5. tAllowReal is a flag that determines whether or not the output can be a floating point number.

6. tProblemCount defines the maximum number of equations that are to be generated.

on mouseUp
   local tOperators, tInputRange1, tInputRange2, tOutputRange, tProblemCount, tAllowReal
   local tProblems, tProblemIndex, tEquation, tOperator, tVariable1, tVariable2, tResult
   // Parameters to be updated.
   put "+,-,*,/" into tOperators // The operators that are used in the equations.
   put "-50,50" into tInputRange1 // The range of the first number in the equations.
   put "1,100" into tInputRange2 // The range of the second number in the equations.
   put "-500,500" into tOutputRange // The permissible result range.
   put false into tAllowReal // Are the results allowed to have floating point values (true/false).
   put "20" into tProblemCount // The number of problems to generate.
   put empty into tProblems
   repeat with tProblemIndex = 1 to tProblemCount
     put item random (number of items in tOperators) of tOperators into tOperator
     repeat with tTestValidity = 1 to 100
         put random (item 2 of tInputRange1 - item 1 of tInputRange1 + 1) + item 1 of tInputRange1 -1 into tVariable1
         put random (item 2 of tInputRange2 - item 1 of tInputRange2 + 1) + item 1 of tInputRange2 -1 into tVariable2
         // Do a bit of testing to ensure we do not violate some fundamental rules.
         if tOperator is "/" and tVariable is 2 then next repeat
         do "do" && quote & "put" && tVariable1 && tOperator && tVariable2 && "into tResult" & quote
         // Test if the answer is allowed to contain floating point results.
         if tAllowReal is false and tResult is not an integer then next repeat
         // Test if the answer is within the specified range.
         if tResult  item 2 of tOutputRange then next repeat
         put tVariable1 & tab & tOperator & tab & tVariable2 & tab & "=" & tab & tab & tab & tResult into tEquation
         // Check that we do not already have the new equation we generated.
         if tEquation is among the lines of tProblems then next repeat
         put tEquation & return after tProblems
         exit repeat
     end repeat
   end repeat
   put tProblems into msg
end mouseUp

The default settings, as shown in this code, were used to generate the output shown in the attached image. The output is written directly into the message box. This output can be copied and pasted into other applications for printing or other manipulation. I left a larger gap between the problems and the results. This allows the results to be covered up when the problems are being solved and revealed when the answers are being checked.

example-output

read more
Hanson Schmidt-CorneliusLiveCode for Tiger Moms

What else can you do with LiveCode?

by Hanson Schmidt-Cornelius on April 28, 2014 1 comment

In my last blog I discussed how much fun it can be for kids to work with LiveCode, but have you ever thought about how much fun it is for adults too? And I am not taking about writing code. LiveCode is so versatile that you can also do other things with it. In particular, I have come across two other interesting applications for which people use LiveCode:

1. An Image Editor/Drawing Tool

Yes, I have found that LiveCode is being used as a drawing and image editing tool, and you can literally draw to your heart’s content.

Used as a Drawing Tool

Used as a Drawing Tool

You can drag and drop controls onto a card and update a range of graphics and blending effects through the property inspector of the particular objects.

You can import images by selecting “File > Import As Control > Image File…” and then use the controls in the bottom half of the tools pallet to update and alter the image.
Now you may think the magnifying glass is missing from the tools, but don’t despair, LiveCode has one of these handy little gizmos too. You can zoom into a region of the image with a drawing tool that you want to apply to the image: Select a drawing tool and press cmd+Mouse Button on Mac or Ctrl+Mouse Button on Windows over the area you want to edit and a new window opens in which you can update the enlarged pixel area.

Once you have finished updating your image, you can save it with a command like:

export snapshot from image “YOUR IMAGE NAME” to file “MY-IMAGE.png” as PNG

or something similar if you want to export a capture of some other control or even the entire card.

2. A Presentation Editor

Building on the use of LiveCode as an Editor/Drawing Tool, a logical extension is the creation of presentations.

LiveCode as a Presentation Tool

LiveCode as a Presentation tool

Admittedly this does require a bit of coding in order to navigate between cards, but this is relatively trivial, and of course LiveCode has a large range of visual effects that you can use when transitioning between slides.

The nice thing about slides written in LiveCode is that you are not bound to the particular device you created the presentation on. You can transfer the presentation to other hardware architectures and operating systems.

Any Other Ideas?

 If you can think of anything else that LiveCode could be used for, other than programming of course, then I would love to hear from you.

read more
Hanson Schmidt-CorneliusWhat else can you do with LiveCode?

Kids and App Fun

by Hanson Schmidt-Cornelius on March 25, 2014 3 comments

It is great teaching children how to program and their motivation can be particularly high if the turnaround time is short and the app has a practical benefit to them.

My daughter has a passion for all stuff technical and especially loves mathematics, and of course she is not new to LiveCode. When she was eight I introduced her to the idea of writing a calculator and it did not take much arm twisting to get the project going.

We started by creating the UI and dragged a field onto a card for the display and buttons for the input. We then added symbols to the buttons that you would normally expect to see on a calculator. UI done, and this was clearly the most fun part for my daughter.

Then came the code that we placed in the card script. If you have experience with other programming languages, then implementing a generic evaluation function for equations can be somewhat beyond the level of a simple childrens’ app. Anyway LiveCode has this covered and allows you to implement a basic calculator algorithm in less than 10 lines of code, and that includes the handler name:

on mouseUp
   if the short name of target is "=" then
      do "do" && quote & "put" && field 1 && "into field 1" & quote
   else if the short name of target is "C" then
      put empty into field 1
   else if word 1 of the name of target is "button" and (char -1 of field 1 is a number or char -1 of field 1 is not the short name of target) then
      put the short name of target after field 1
   end if
end mouseUp

This code consists of an "if statement" in which three possible display altering lines of code can be executed. The first part of the "if condition"
tests if the "=" button was pressed, with the "do …" line performing all of the evaluation magic and placing the result into the display field. Take a closer look at that line and check out how much it actually does.
The next part of the "if statement" tests if the "C" button was pressed and then allows the code to be executed that clears the content of the display field.
The last part of the if condition tests if the button pressed is valid for display in the display field. If it is, the value is placed at the end of the content that is already displayed in the display field.
Calculator done, we decided to skipped some of the "do" details and enjoyed the fact that it worked.

Now this is a very simple implementation of a calculator and certainly keeps attention focused while you put the app together. There are obvious shortcomings that would merit further development, for example some graceful exception handling if the function evaluation should fail, and of course calculators can come with loads more buttons than the ones shown here. Try adding some other features and see what else you can calculate with this app.

If you have similar experiences or suggestions for cool kids’ apps, then I would love to hear from you and see what great experiences you have had.

read more
Hanson Schmidt-CorneliusKids and App Fun