Tuesday, February 23, 2010

I was having some trouble with getting the line graph working properly. In fact a few hours were spent getting frustrated with the lua script because it wasn't doing what I wanted it to do!

But then I had a breakthrough and after that it was pretty straightforward :)
This is what the current script is capable of displaying.

In fact the first figure was what I had been after for a while. I wanted my graph to resemble an electroencephalogram.

I'm sure there is more that can be done from this basis so I may well be posting updates in the future.

You can get the code from my post in the crunchbanglinux forum here. You can also watch a short clip of an earlier form of this script in action.

The problem was the transfer of information from the data generating function to the figure drawing function. The problem was that you can only transfer data held in strings. In the data function I was generating a table something like this:

for i=1,n do

This would give me a table with 10 entries, the entries being the numbers 1 to 10.
If i did this:

print (table[i])

I would get this output in the terminal:


Which has been fine so far, but the table I was using was much more complicated than this and I just couldn't get things working by simply transferring the string "table[i]" to the figure drawing function. What I really needed was to transfer the whole table to the drawing function.

The breakthrough was the use of this command:
string=table.concat(table, ":")

What this does is to take a table and turn it into a string, in this case, each entry in the table will be seperated from the next by a ":" in the string. So our example table from above, print (string) would output the following:

I could then take the string, pass it to the drawing function and use the split string function to turn it back into a table. Then I could work from the table to achieve the figure.

No comments:

Post a Comment