I’ve been meaning to get a good 3d Perlin noise function ( a method used to create a ‘natural’ kind of randomness, very useful in graphical programming ) into the processing.js library for the past few months, and I must admit to being rather slow at doing so. The task, originally scheduled for the .3 or .4 release, has been pushed back to the .5 and now the .6 release of the library.
Though one reason for this delay has been my lack of extra time and good attention to spend on the problem, I think the main problem has been my newness to Javascript combined with my [ sometimes faulty ] methods of investigation.
Before I get into that, I’d like to write a bit about the meta-process of this whole thing, just in case it makes sense to anyone.
Self-exemplification
In the first post in this series, I shared an image of the paths of investigation shared to us by Tristam Shandy in the fourth of his works, and I must say that the paths represented in that image are rather random, and I would posit that my work with getting 3d Perlin noise into processing.js might resemble one of those paths.
If that were the case, then it could be said that the process of getting 3d Perlin noise ( or ‘natural randomness’ ) working with Javascript is a naturally random process itself. As the late Robert Merton would have said, the process of implementing randomness is a self-exemplifying phenomena, in that its implementation resembles its results. Merton observed a few other processes such as these– the rise of the word ’serendipity’ being one of them ( much more on that in future posts… ). His study of the question over where the phrase, “on the shoulders of giants..” originated from also becomes self-exemplifying rather quickly, as it turns out that the phrase itself, commonly attributed to Sir Isaac Newton, actually stands on giants of its own which date back to the Latin grammarian Priscius, and perhaps even further.
Merton, a lover of dictionaries, lamented in a later work of his that his term ’self-exemplification’ was never included in any dictionary, in his lifetime. Fortunately for him, we don’t use paper dictionaries as much as we used to and perhaps the internet can help spread his concept for us instead of Merriam et al. But back to the task at hand-
inexperience with the path
For a long time I have ignored trying to understand subjects such as how a web page loads, how javascript and HTML work together, all the DOM stuff because I have had the crutch of flash. I’ve not really looked into the intricacies of how to do all of those things properly before, because the only HTML and Javascript I needed to know was enough to embed my flash document.
But things, as they are wont to do, have changed and now that I’m working with these matters I’m just not that good at it. I don’t fully understand Javascript, the DOM, CSS. I have much to learn. I don’t have the expertise with the topic that I have with Actionscript, and that can be frustrating to me. This project seems to be my first attempt to speak accurately in a different language, and in being so I am almost uncomfortable with the task in its enormity. I’m not the best programmer. I’m not sure how I ended up here. Others would have finished it ( and probably are doing so now
) in minutes or hours rather than the days, weeks and months I’ve spent with the problem.
Where do I get lost on the way, where is my time spent?
paths followed backward
In my efforts with Actionscript programming, I’ve always loved to use Perlin noise to create a natural kind of randomness in certain situations. I’ve either used the built in Actionscript perlinNoise( … args ) method ( great for 2d ) and in some cases tried out another’s implementation of 3d Perlin noise. So when I found the need for some noise in Javascript I ported the 3d noise class from Actionscript to Javascript and called ok for now.
At some time, however, I said I could get 3d noise working for processing.js. It was only then that I found the class I was working with, while it worked okay for 2d noise it wasn’t working for the third dimension (’z’ or ‘time’). So I fiddled around for awhile, hoping to make it work until I realized that I wouldn’t even know what it would look like to work. How would I know it was correct? How did I know that the class that had inspired mine was itself correct, and how did I know that the class that inspired me was inspired by something that was correct. I couldn’t do this until I really understood 3d Perlin noise, as Mr. Perlin did. Only after that could I understand it, recognize it, and make it work in Javascript. And, further, only after I had realized how much there was to understand of the subject could I go on to solve the problem.
I think at this point, the .4 release deadline was coming, and I determined to, perhaps as a histriographer, travel back to Ken Perlin’s original code ( written in c in some places, java in others ) in my efforts to bring it forward in time to now. And here I will take pause to share a quote:
Could a histriographer drive on his history, as a muleteer drives on his mule, — straight forward — for instance, from Rome all the way to Loretto, without ever once turning his head aside, either to the right hand or to the left, — he might venture to fortell you to an hour when he should get to his journey’s end; — but the thing is, morally speaking, impossible: for, if he is a man of the least spirit, he will have fifty deviations from a straight line to make with this or that party as he goes along, which he can no ways avoid. … To sum up all; there are archives at every stage to be looked into, and rolls, records, documents, and endless genealogies, which justice ever and anon calls him back to stay the reading of: — In short, there is no end of it
Though I have gotten lost on my trails towards 3d Perlin noise, and there is no end of it, I am getting closer. I am busy reading the documents, the rolls, the genealogies along the way. I apologize that I cannot bring back what I want to bring back as quickly as I had wanted to, and hope you might understand my diversions. I contend that I am close. The solution is just beyond that next horizon. The solution is just behind that previous horizon.
The randomness of the digits of π
“If you were to assign letters of the alphabet to combinations of digits, and were to do this for all human alphabets, syllabaries, and ideograms, then you could fit any written character in any language to a combination of digits in pi. According to this system, pi could be turned into literature. Then, if you could look far enough into pi, you would probably find the expression “See the U.S.A. in a Chevrolet!” a billion times in a row. Elsewhere, you would find Christ’s Sermon on the Mount in His native Aramaic tongue, and you would find versions of the Sermon on the Mount that are pure blasphemy.”
Richard Preston “The Mountains of Pi”, New Yorker -March 1992
A few weeks ago I was inspired by the quote above to create a system to translate the digits of Pi into English, and though my main pursuit will likely remain unfulfilled, I hope to share what I have found today, on Pi day. My initial approach was based on the idea that integers, and also series of integers, would not be evenly distributed throughout the digits of Pi. What I quickly found, however, was that as the sample size of the digits of Pi increases, the distribution of different integers ( and also series of integers ) becomes more equal.
I am sure that this observation is trivial to anyone with a stronger understanding of Number Theory or Statistics, but it was surprising enough to me that I wrote a program to visually demonstrate the results I was seeing. The video below demonstrates both the observations I made and also how to use the program.
You can use the program here, view the source of it here, and also, if you’d like, have the first 10 million digits of Pi for yourself to play around with here.
In my endeavors, I’m indebted to the maker of apfloat, a program that can be used to efficiently calculate many digits of Pi, among other things. Keith Peters and Justin Windle are also awesome for creating the Simple GUI components set used in the tool.
Though my initial intentions did not involve making a tool to create pretty pictures, I think that’s what I ended up with. I hope in the future to re-purpose this code to visualize different data sets ( a tool is only as interesting as its possible uses ), and also plan to port it to both JavaScript and Objective-C, but that will have to wait until some of my other projects are a little more complete. Please let me know with any ideas on improving the interface of the tool and how it should function. Since it was developed in a vacuum I would very much appreciate any ideas. Also, if you’re interested in print resolution images from this tool let me know as well.