Sunday, September 24, 2006

Select distinct in XSLT

Hard to believe, but there is no equivalent in XSLT to the SELECT DISTINCT SQL command. After doing some research, I came across a technique for getting distinct data called the "Muenchian Technique". Here is an example I made based on this method.

First the XML:


Then the XSL:



The result:


I threw the weight in to show that you are getting the first Clumber. Leaving that out would result in a list of all the distinct breeds in the dogs.xml file.

Another cool find was this site describing the key function in XSLT.

XTrans

I've been working with the program XTrans for creating XSL templates. XTrans is a free Windows program. It opens quickly and is very useful with a straightforward user-interface. The workflow is very developer-friendly. You open your XML and then create your XSL viewing them side-by-side, top-and-bottom, or one window at a time. No mouse is necessary when using the app (something I love). It has an XPath query analyzer so you can easily test your XPath queries. With the Normalize command, you can have XTrans indent your XML or XSL. By pressing the context menu key (or a right mouse click) you get a menu for inserting and XSL command/statement. I've been trying some other apps recently, but I keep coming back to this one.

Saturday, September 16, 2006

Painter

I finally bit the bullet and bought Corel Painter 9.5 and an Intuos 3 tablet. Ever since working through the Photoshop part of The Photoshop and Painter Artist Tablet Book, I've been interested in giving Painter another try.

Years ago, I tried the original Fractal Painter as well as Painter X2. One of the features I found very useful for a particular project was the ablitly to record your brush strokes, and then play them back at a higher resolution. In the days of 68K Macs and 8MB of RAM, that feature was great for print projects (it was the pre-web days of the early 1990s).

Painter has improved immensely. The interface is much more intutive if you are familiar with other graphics programs. While the interface is no longer quirky, the packaging is... The CD in the package has no jewel case or even envelope, it just has a spot in the box. The manual is not much of a manual for reference. It is mostly made up of tutorials from various artists. That's a good idea, but the implentation is weak. The quality varies from tutorial to tutorial, some being more an overview as to what was done as opposed to a tutorial. The font size chosen is also too small.

It does come with a CD which has lynda.com video tutorials. These seem more useful, unfortunately they wrapped the QuickTime movies in a Director interface which doesn't provide a fast-forward button. I often use the QuickTime Player's fast-forward button to play the slower parts (or parts I know) of a video at double-speed (most of the time, the audio is still understandable). The interface of the video app also has a problem where you can't even click all of the links. Fortunately you can access the QuickTime movies directly so you can view them in the QuickTime Player by turning on "Show hidden files and folder" in the Tools>Folder Options...>View tab for that Explorer window. Then you'll see the "D:\data\movies" directory.

I need to spend some quality time with the product. At the moment, it looks like it will be worth the investment.

Thursday, September 07, 2006

Flash Drawing Approaches

It is funny. Sometimes working in Photoshop feels like you can get it done quicker. With a recent Photoshop painting, it is taking a while. Initially, it feels like you are making great progress, but once you get down into the details things slow down.

Flash illustration is more graphic (usually). While vectors can be slower to work with, a graphic illustration will take less time than a more realistic Photoshop painting. I suppose I could do a graphic illustration in Photoshop and see how quick that goes, but the thought of being stuck at one resolution for something that looks like vectors would pain me.

One thing I'm doing in Flash is trying different tecniques for rendering, such as:
  • Starting with a rectangle and control-clicking to add points
  • Drawing with the line tool, then filling, and finally removing the lines
  • Drawing lines, converting to fills, then reshaping the lines (where necessary)
  • Painting with the brush with maximum smoothing
The last technique, I am least sold on. You have the least amount of control and the most opportunity to add unnecessary points.

One approach in Flash I haven't really spent time with is creating with the pen tool. After 19 years of Illustrator's pen, it looks similar but doesn't have the same functionality. Plus, using the above techniques has a more natural feel. I do use the pen for certain specific tasks that I'll cover another day.

Wednesday, September 06, 2006

Globals in Director, Flash, and Perl... Oh my!

Globals can be the bane of the programmer who needs to maintain another programmer's code (and sometimes even his own). When you use a global variable in a function, you've added another entrance and exit point for data into the function. When you change the state of a global, you are changing the state of the application. It makes debugging problems more difficult.

For years I worked with Director. In Director's language, Lingo, you can use global variables. I avoided using them, but occassionaly they were useful in transfering data from one movie to the next. In order to better handle the problem of maintaining code with globals, I took a page out of the OOP handbook and created getter and setter functions. This way I had an easy way to intercept the change in value of a global or even just determine when a particular global is being read. In fact sometimes, the globals would add up to the suggestion of the necessity of another parent script.

As I work with Flash and it's language, ActionScript, I find myself using a similar strategy. Flash also supports global variables and they are even more convenient to use than in Director (where you had to declare their usage). So I've created getter/setter functions for ActionScript (see below). A difference with ActionScript is you do not need to declare a global before using it. This necessitates more discipline. I try to give globals initial values in the same script as the getter/setter functions. The GetGlobal function will send a message to the Output window if you set an undefined variable. This helps since you can easily mistype a variable name and ActionScript will simply assign it without complaining. You can see in the SetGlobal function I commented out the line to trace what is being assigned. It is a useful place to test for a particular variable name and value if you are debugging.



As I learn Perl, I read that Perl's variable's are global by default unless you declare them with the "my" keyword. If that is the case, it will take even more discipline to write Perl programs in a structured (or object-oriented) manner.

Saturday, September 02, 2006

Digital Painting


Photoshop is a great way to manipulate images, but it is also a good tool for creating images from scratch. A few years ago, I picked up a book How to Paint Like the Old Masters by Joseph Sheppard. Sheppard paints like a modern day Michelangelo. I picked up his book with the thought of actually doing some oil painting, but I decided to see if his techniques would work in digital painting. For the most part they do! I did this Spider-Man from scratch in Photoshop, starting with an underpainting, similar to what Sheppard describes.

I find I like to keep shape dynamics off on my brushes. I usually have other dynamics on, affecting the opacity based on pen pressure. This setup keeps me busy with both hands, one with pen and the other with the keyboard. Since I don't do shape dynamics, I am always hitting the square brackets [] to alter the brush size. As well as hitting the D (sets the colors back to black and white), X to swap the foreground and background colors, and spacebar to move around. Seems to be a constant battle, tabbing to show and hide palettes.

I'd like to give Painter a try. It seems to be more geared towards illustration. That and upgrading from my Wacom old Graphire to an Intuos is also on the list.

Thursday, August 31, 2006

The Programming Road

I've always considered C to be my first programming language (subsequently I judge all languages against it). I picked up Learn C on the Macintosh in 1991. Technically, I did do Fortran on punch cards in 1983, but that was a different world. It occurred to me today I programmed in HyperCard and its HyperTalk language in 1988-90, I remember writing two small programs for use in our family business. I guess I never thought of it as programming because it seemed very easy to get a result. Maybe that is why HyperCard was so popular, that and it being installed on the early Macs. Nothing like free software that's easy to learn. 

After painfully working through Learn C on the Macintosh, I actually started understanding some of the basics of programming. From there I moved to Prograph CPX at the end of 1993. In early 1994 I took a programming logic course that helped solidify my understanding of what was going on. The course was interesting, you didn't use a computer, just flowcharting and pseudocoding. That same year I picked up AppleScript to script QuarkXPress using Frontmost (later FaceSpan) to have a front end to my scripts, and in the fall I learned Lingo with Director 4.

I actually tried Director in 1993 and made an interactive portfolio for my company. It was with Director 3.1.1 and I was not too impressed. Version 4.0 of Director did impress me. I'd found the joys of Object-Orient Programming (OOP) thanks to Prograph CPX. With version 4.0 of Director, Lingo was now a powerful OO language.

I stayed with Director for several years, dabbling in JavaScript in 1997. That year also marked my first introduction to Java. I was not too impressed (deja vu!). I continued with Director until 2000, co-authoring two books on the subject and tech editing two more. That year I took an instructor job at Sun Microsystems. I taught several Java courses, a shell scripting course using Bourne and Korn, and learned the Vi text editor. I also picked up programming the C Shell in order to teach a course in it. In the shell scripting courses I was introduced to grep, sed, and awk. Awk I loved!

After leaving Sun, I got a job where I got to do a little Director again and was exposed to the classic ASP. I found I did not care much for ASP or VBScript. I learned to program in ActionScript with Flash 6 and the Flash Communication Server APIs. After that I migrated the company from VBscript and ASP to C# and ASP.NET. I learned SQL, I enjoyed pair-programming, and discovered Visual Studio was the best IDE out there. Along the way I got to briefly pick up and program in XSLT and created a .NET Windows Forms application.

After that job I came to StorageTek where I worked with the Docent LMS and CDS. The LMS used a server-side JavaScript that was a step up from classic ASP, but not a big step. I managed to make use of both my ASP.NET and Windows Forms skills. I tinkered a little with JavaScripting Photoshop for a project.

Sun bought StorageTek, so I'm back at Sun. But I'm not back using Java (yet), I'm actually learning Perl and MySQL.