
Two volumes I found quite helpful in my research for the creation of this site. |
Using Javascript to Randomly Deal a Tarot SpreadThis project came about as I was attempting to teach myself the basics of Javascript for advanced design of web pages. For those of you unfamiliar with it, Javascript is a series of coded instructions embedded on a web page (not requiring an outside program application or lengthy download) to manipulate data and images within that web page, or within another designated page. For example: Have you ever noticed that some websites automatically have the correct date and time pop up on their page somewhere when you visit the page? When you have the understanding that a standard web page is just text and a few tags arranged to display the page, you begin to wonder how the date or time automatically changes with subsequent visits to that page. The secret is in the processing of certain instructions on the page by your own PC as you peruse those pages. In the above example, the web designer has sent a coded message to your PC to display the most current date and time on the web page. The system checks the internal clock and calendar on your PC and updates the page content. And voila! You may have noticed that each time you visit one of the pages in this website, the cards to the left are changing, and rarely display the same image twice. Go ahead and refresh this page - all the cards to your left will change. This is because I have used JavaScript to create a random number generation and display six cards at random from the Tarot deck. In creating the card spread, I first had to scan in the entire deck, one card at a time, and assign a number to each card. This part was not difficult, but it was time-consuming as I also had to design a single HTML page for each individual card in the deck, containing all of the data and important divinatory information relating to that card. These individual pages would be immediately called for once the corresponding card was revealed and displayed.
Once the basic layout of the site was in place, I had to generate ten random numbers to represent cards in the Tarot deck. This may sound easy but it actually involved multiple steps (and headaches!) until I had the system working the way I wanted it to. First, I had to generate those random numbers. This was fairly easy, since JavaScript has several subroutines to automatically generate numbers within paramaters you set. I instructed the system to give me ten numbers between 0 and 77 (the corresponding numbers on the deck of Tarot cards that I had assigned, with The Fool being zero). The system, did generate randome numbers for me. Unfortunately, they were rather complex figures such as 7.556423, 23.454475, 2.19238, etc. In other words, the random numbers were not whole integers... So I had my random numbers, but now came the task of rounding them to the appropriate whole number. This required me to create a new series of ten variables which took those ten cards, and extrapolated only the appropriate integer, rounding up or down as necessary. However, this created a new wrinkle. Remember, the random numbers were truly random, but when rounded, they also could equal one another. That is, the number 2.1246 and the number 1.99543 are different from one another, but rounded to the next nearest integer, both would equal "2". For this reason, I had to go back and restructure my generation of randoms to account for ten numbers which had to be whole, and which could not equal one another. If the system came across numbers that matched, it would find one of the errant numbers and automatically redraw a new integer... All of this worked great, except for one more thing... This meant I had to compare all numbers generated against their predecessors.
Lastly, I had to use JavaScript to write my cards into a web page in the appropriate layout. And then of course, I had to provide the interpretations. This was presented me with two issues: First, I had to provide individual interpretations of all 78 cards in the deck (not difficult, but time consuming), and secondly, I had to provide a method of calling for and displaying each individual interpretation when the card itself was clicked. This was accomplished by generating a function to reveal the card when it was clicked, and then calling for a web page in a secondary window. I discovered through trial and error that, when I called for the separate window, it was a bit of a hassle because it would sometimes cover up the initial spread, and it would require the card reader to close that window. Doing this ten times would have been annoying and would have driven people away. So instead, I created a framed spread, with the initial spread to the left, and the interpretations to the right. I think you will agree the final result makes much better sense. I encourage you to examine the source code in the spread page, since that is where the bulk of the real work occurs. If you have questions or comments regarding the design of this site, please feel free to e-mail me. |