I wanted to draw a bunch of stick figure men carrying spears, going on a grand hunting event. There will be at least 15 men in the group. Of course I could draw them all by hand, but I decided to put my Photoshop Scripting abilities to good use.

I started with a drawing of three stick figure hunters. This drawing was made in Adoble Flash CS3 using a Wacom Bamboo tablet. Separating the legs from upper body gives me a set of 3 upper bodies and 3 pairs of legs. We can make 3X3=9 different hunters using these. The idea is very simple, match upper body with legs to form a member of the hunting group. I decided to randomly pick an upper body and a pair of legs to form each member of the group and keep looping until there isn’t space left on the image.
This is the script I wrote:
var defaultRulerUnits = preferences.rulerUnits preferences.rulerUnits = Units.PIXELS var imageWidth = 965 ; var imageHeight = 150 ; var legWidth = 60 ; var legHeight = 75 ; var torsoWidth = 75 ; var torsoHeight = 150 ; var nLeg = 3 ; var nTorso = 3 ; //open leg images for(i=1;i<=nLeg;i++) { var fileRef = new File("C://hunt//leg"+i+".png"); var docRef = app.open(fileRef); fileRef=null; docRef=null; } //open upper body images for(i=1;i<=nTorso;i++) { var fileRef = new File("C://hunt//torso"+i+".png"); var docRef = app.open(fileRef); fileRef=null; docRef=null; } var newDocument = documents.add(imageWidth,imageHeight); //make some random hunters for(j=0;j<17;j++) { app.activeDocument = app.documents[Math.floor(Math.random()*nLeg)]; var AD = app.activeDocument; AD.artLayers[0].copy(); app.activeDocument = newDocument; var layer = newDocument.paste(); layer.translate(j*legWidth-imageWidth/2,legHeight); app.activeDocument = app.documents[3+Math.floor(Math.random()*nTorso)]; AD = app.activeDocument; AD.artLayers[0].copy(); app.activeDocument = newDocument; var layer = newDocument.paste(); layer.translate(j*legWidth-imageWidth/2,legHeight/2+2); layer.merge() } //close all files except for the final result for(i=app.documents.length-2;i>=0;i--) { var AD = app.documents[i] AD.close(SaveOptions.DONOTSAVECHANGES); } preferences.rulerUnits = defaultRulerUnits;
And here is the result.

Since the hard part was already done, I decide to play around a little more and came up with this for a banner here. Hopefully It will stay there for a day

Anyone who have tried making rectangles with rounded corner must have noticed how odd those corners look as they tend to get pixelated and stick out from the body of the rectangle. See the image bellow if you still don’t get what I mean. Notice how odd those pixalted corners look. The same thing can happen with a curved line as well.
![]()
This is due to the anti-aliasing performed on the curved lines by flash. This looks worst when the rounded part is small. The problem is still present when the curved part is large, but it becomes less noticeable. Anti-aliasing is generally a very helpful feature. This case is one of the rare exceptions when anti-aliasing is better not performed.
To let flash know that you don’t want anti-aliasing to be performed on your curved lines, you have to enable stroke hinting. When stroke hinting is used, flash colors the whole pixels only during rendering. Skips the fractional pixels. Thus anti-aliasing is avoided. See result after enabling stroke-hinting in the image bellow.

Being respectful to traditions, let us start with a script for drawing “Hello World” in Photoshop. One can use Javascript or VBScript in windows or Applescript in Mac for photoshop scripting. The following Javascript code will produce a “Hello World” photoshop document.
var originalUnit = preferences.rulerUnits preferences.rulerUnits = Units.PIXELS // Create a new document var docRef = app.documents.add( 300, 300 ) // Create a new layer var artLayerRef = docRef.artLayers.add() artLayerRef.kind = LayerKind.TEXT // Write our text artLayerRef.textItem.contents = "Hello World" // Release references docRef = null artLayerRef = null textItemRef = null // Restore unit setting app.preferences.rulerUnits = originalUnit
Code explained :
First of all, we need to keep record of the current unit settings since we are going to change the unit settings according to our preferences. After saving the current units settings, we change the units to PIXELS.
Next, we create a 300X300 pixel document. Then we add a new layer to the new document. Since we want this to be a text layer, we set LayerKind to TEXT.
On the new layer, we write our text, “Hello World”.
At the end, we dereference the variables and restore the previous unit settings.
Search
News
Blog
- Pass variables into flash
- Fetching data from multiple tables in one MySQL query – Part 2
- Fetching data from multiple tables in one MySQL query
- Let’s Go A Hunting
- Java Applet and Javascript message passing
- The Right-Click Menu in Flash
- Stroke hinting
- Python: C++ style cin, cout in Python
- Python: Working in Unicode
- Website Security : Directory Listing Issue


January 6, 2010 in
