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.