Yesterday was Towel Day, which is an unofficial holiday to mark the anniversary of the death of Douglas Adams. I had no idea when I started writing these blog posts that there was such a thing, and it’s not why I chose to title them after the novels in Adams’ Hitchhiker series. But it is serendipitous.
In this post I’ll be talking about the specific programming decisions and techniques I used. But don’t don’t get too excited – I’m pretty sure that the techniques I used are either hack jobs or very low-complexity stuff. My original idea was to create a program that read words and then sorted them. This is a very simple idea and does not have a great deal to explain; I wished to make the computer do the hard work of counting for me, rather than me doing the hard work for computers, as actually turned out in this module.
As the stated aim for the project was to read from a text file I assumed that the best way of doing this was to break apart the text and load it into a string array. One of the first big mistakes I made in this area was to assume that the string array would be a two-dimensional array – after all, I was counting lots of different things, rather than making something like a time-graph for one thing. Right?
No. A 2D array was far too complex for me, and didn’t actually do what I needed. If a regular (one-dimensional) array has storage for an item at each defined point, a 2D array has a list of arrays, each with storage at a defined point. That storage can be used for one defined type of data, like integers, floats, or strings. As I was determined to count specific words that I had chosen, the idea of a 2D array was overkill. Not only that, but the method I was using to break up the text and read it wasn’t really compatible.
Another big error was wandering into regular expression-land with a dazed look on my face. Perhaps if my project was more technically acute, there might have been some call for the use of regular expressions, but as the code was merely sifting through an array of strings it was much better to do a straight comparison using relational operators. In the current level of code I have been using an ‘if’ statement with a ‘directly equals’ (==) comparison.
I was convinced for a long time that regex was what I should be doing, but the documentation for regex is so dense and tough that I think you have to have some sort of special programming gene to be able to get your head round it. Every time I looked at it I found all of it so dense and unwieldy that I couldn’t get into it, and I found that the examples it came with were not something that really matched up with what Processing could use. The few times I did have success with regex and Processing were using the match() command, which seemed to behave in a way that I didn’t expect, although on closer reading of the documentation it was nearly as it said on the tin.
Moving onto discussion the actual production of a graphical output, this was something I started working on first. My working practice with Processing might not have been the most methodical, but I find that when I get stuck working on something within Processing I tend to pop open a new window and then start chewing on it in a separate bit of code. Pretty soon I have enormous amounts of windows open in Processing and I can’t remember what I was doing with half of them.

See what I mean?
For the graphical output I started working on modular blocks of code that I could call from elsewhere in the program. This approach mostly worked, but when I started compiling code together in one big bloc (what I’ve saved as version 3 in the repository of code) I found the way I had of fading in and out the text caused some sort of massive slowdown in the program.
After much experimenting the cause was not the fact that the text was fading in, but the fact that I had two different PFont’s being called, one inside a function, and one inside the main setup. Debugging this problem was pretty much the only time I felt successful at solving a problem during the entire run of the module, and after changing the way the typefont call worked the program was back up to speed.
Finally, after much unsuccessful toil and experimentation with what amounted to The Wrong Stuff, I ended up with a program that could count through a text and produce a small graph whilst doing so, and then output a text file that contained the ‘count’ of all the words searched for. This program, whilst technically fulfilling the brief I wrote for myself, is still a long way away from what I would like. For instance, the idea of changing the words searched for or the text would involve the user diving into the code and being prepared to edit it. This is not the ideal usage for most people, but as the code is written for a target audience of one (myself) I think I can handle it.
I have also not prepared a sketch to show what can be done with the output of the program as yet, despite making some mock-ups. Here, however, is the original sketches from my notebook about the depiction of the program:

At some point in my research I experimented with using Apple’s Automator program to collate and collect text files from a specific directory. I was less than successful with this, and the results of the script actually ended up meaning I had to restart my machine. However, in the spirit of completeness, I am including those results along with my other code in this blog post.
Applescript application (OS X Only): basic-text-scan
Online repository of Processing Sketches for this project
ADDENDUM: Production list of Processing Sketches, in reverse order:
Buttons_test
Buttons_test-090428a.zip
I_dont_understand_match
basic_tech2
experimental_envisioning
fake_values
fake_values_2
match_test
orange_text_example
orange_text_example-090428a.zip
orange_text_test
orange_text_test.zip
printreader_again
printreader_again-090428a.zip
roma
roma_two
slight_succes2
slight_success
version_1
version_2
version_3
word_lines
basic_tech/.DS_Store
basic_tech2.pde
basic_tech/basic_tech2/basic_tech2.pde
Buttons_test.pde
conjoining_list.pde
data
basic_tech/Buttons_test/.DS_Store
basic_tech/Buttons_test/Buttons_test.pde
basic_tech/Buttons_test/conjoining_list.pde
Serif-200.vlw
basic_tech/Buttons_test/data/Serif-200.vlw
basic_tech/Buttons_test-090428a.zip
experimental_envisioning.pde
basic_tech/experimental_envisioning/experimental_envisioning.pde
conjoining_list.pde
fake_values.pde
basic_tech/fake_values/conjoining_list.pde
basic_tech/fake_values/fake_values.pde
applet
fake_values_2-090502a.zip
fake_values_2-090502b.zip
fake_values_2.pde
basic_tech/fake_values_2/.DS_Store
fake_values_2.jar
fake_values_2.java
fake_values_2.pde
index.html
loading.gif
basic_tech/fake_values_2/applet/fake_values_2.jar
basic_tech/fake_values_2/applet/fake_values_2.java
basic_tech/fake_values_2/applet/fake_values_2.pde
basic_tech/fake_values_2/applet/index.html
basic_tech/fake_values_2/applet/loading.gif
basic_tech/fake_values_2/fake_values_2-090502a.zip
basic_tech/fake_values_2/fake_values_2-090502b.zip
basic_tech/fake_values_2/fake_values_2.pde
I_dont_understand_match.pde
basic_tech/I_dont_understand_match/I_dont_understand_match.pde
match_test.pde
basic_tech/match_test/match_test.pde
data
orange_text_example.pde
basic_tech/orange_text_example/.DS_Store
Georgia-Bold-16.vlw
basic_tech/orange_text_example/data/Georgia-Bold-16.vlw
basic_tech/orange_text_example/orange_text_example.pde
basic_tech/orange_text_example-090428a.zip
conjoining_list.pde
data
orange_text_test
orange_text_test-090513a.zip
orange_text_test-090525a.zip
orange_text_test.pde
positions.txt
basic_tech/orange_text_test/.DS_Store
basic_tech/orange_text_test/conjoining_list.pde
Georgia-Bold-16.vlw
it.txt
terribletest.txt
basic_tech/orange_text_test/data/Georgia-Bold-16.vlw
basic_tech/orange_text_test/data/it.txt
basic_tech/orange_text_test/data/terribletest.txt
conjoining_list.pde
data
orange_text_test.pde
basic_tech/orange_text_test/orange_text_test/.DS_Store
basic_tech/orange_text_test/orange_text_test/conjoining_list.pde
Georgia-Bold-16.vlw
it.txt
basic_tech/orange_text_test/orange_text_test/data/Georgia-Bold-16.vlw
basic_tech/orange_text_test/orange_text_test/data/it.txt
basic_tech/orange_text_test/orange_text_test/orange_text_test.pde
basic_tech/orange_text_test/orange_text_test-090513a.zip
basic_tech/orange_text_test/orange_text_test-090525a.zip
basic_tech/orange_text_test/orange_text_test.pde
basic_tech/orange_text_test/positions.txt
basic_tech/orange_text_test.zip
data
positions.rtf
positions.txt
printreader_again.pde
positions.txt
basic_tech/printreader_again/data/positions.txt
basic_tech/printreader_again/positions.rtf
basic_tech/printreader_again/positions.txt
basic_tech/printreader_again/printreader_again.pde
basic_tech/printreader_again-090428a.zip
roma_movie
roma_movie.pde
basic_tech/roma/roma_movie/roma_movie.pde
roma_two.pde
basic_tech/roma_two/roma_two.pde
slight_succes2.pde
basic_tech/slight_succes2/slight_succes2.pde
slight_success.pde
basic_tech/slight_success/slight_success.pde
version_1-090422a.zip
version_1.pde
basic_tech/version_1/version_1-090422a.zip
basic_tech/version_1/version_1.pde
button_class.pde
conjoining_list.pde
data
version_2.pde
basic_tech/version_2/.DS_Store
basic_tech/version_2/button_class.pde
basic_tech/version_2/conjoining_list.pde
basic_tech/version_2/version_2.pde
button_class.pde
conjoining_list.pde
data
version_3.pde
basic_tech/version_3/button_class.pde
basic_tech/version_3/conjoining_list.pde
basic_tech/version_3/version_3.pde
conjoining_list.pde
word_lines.pde
basic_tech/word_lines/conjoining_list.pde
basic_tech/word_lines/word_lines.pde
This list was outputted using the command “find basic_tech -exec ls {} ; | open -tf” in the OS X Terminal.
Posted in basic_tech, coursework, newcastle | 1 Comment »