picture home | pixelblog | qt_tools

omino code blog

We need code. Lots of code.
entries for category "scripting"
David Van Brink // Sun 2008.09.14 18:45 // {code scripting wordpress}

simple browser tricks

In a detour to a detour to some longer term goal, I needed to do some minimal HTML/JavaScript coding. The regularly scheduled hardware and WBL tinkering — including soldering, LEDs, and wireless sensors — will resume shortly.


oh, i dont know. what do you think?

David Van Brink // Tue 2008.06.3 08:43 // {scripting}

another JavaScript sighting

Respected cognizant advocates the J-word: Daniel Jalkut over at Red Sweater.

In this case, he’s suggesting making it Apple’s OS-level application scripting langauge.

This darned language just keeps appearing. Standard across the board for Adobe’s application scripting, and Flash (more or less), built into Java 6, built into Qt 4 and later. Interesting.

oh, i dont know. what do you think?

David Van Brink // Thu 2007.11.15 22:56 // {scripting}

Scripting Language Links

Presented without justification, a few links related to the world of scripting.

Bubblemark Animation Test A simple animation of bouncing bubbles has been ported to JavaScript, Java, Flash, JavaFX, and others. Try each of them out, and see the frame rate!

The ECMA Cloud JavaScript expert John Resig has drawn a marvelous diagram showing the lineage, deployment, and hookups of many implementations of JavaScript (aka ECMAScript).

Trolltech’s QtScript Trolltech makes a widely used cross-platform application framework called Qt. It lets you code against their platform and deploy on Windows, Mac OS X, Linux. As of mid-2007, they include QtScript, which is their implementation of JavaScript. (This is particularly interesting to me because my employer Altera is adopting Qt for their main application, Quartus.)

Rhino, BeanShell, Java BeanShell is a little known scripting language for embedding into Java applications, touted for its small footprint & Java-integration. Rhino is a Java implementation of JavaScript which converts scripts to bytecode on the fly. Java is Java. This link compares performance of the three.

oh, i dont know. what do you think?

David Van Brink // Tue 2007.02.27 20:23 // {scripting}

Hacking Sawdust, Part II: Three Dimensions Into Two

This is the second of four parts. Read the first part first.

Suppose you wanted to make one of these:

Here’s one way to proceed.

First, use a three-dee modeling program to create a single sphere. I used LightWave.

Next, we need to translate height to brightness. I chose to write a “shader plugin” in LightWave. LightWave has a cute little scripting language called LScript which, like every misguided cute little language, resembles C or Perl or whatever, but isn’t. It’s really quite tragic. I’m thrilled that newer endeavors seem to favor standard languages; all of the Adobe apps use JavaScript. Good work, Adobe! And a pox upon those who still cling to TCL, despite its standard-ness. And don’t get me started on LSL… cute but oh so wrong.

Meanwhile, LScript actually does work just fine, and here’s the LightWave plugin I wrote. It should be fairly easy to read, and provide a good starting point for other simple shaders.

LightWave’s user-model is a train-wreck. Parts of the UI are deep and other parts are shallow, and some parts that appear shallow have a secret button to reveal incomprehensible depth. To apply this plugin, you need to go to the Shaders tab of the Surface Editor and apply an LScript shader. Then edit the Properties of the shader to apply the script above. See what I mean? But it works.

The other trick is to apply an orthographic camera. I haven’t explained what our goal is yet, so here it is: Create a “height-map” for a sphere, where white is high and black is low. An orthographic camera captures an undistorted view, like so.

And with the shader applied, renders like so.

That was a rather complicated way to get such a simple bitmap. A 20 line C or Perl program could have produced the bitmap for a sphere like that… the value is that I now have a toolflow for three-dimensional models — from a very good modeling program — into these “height map” thingies.

Next stop, Photoshop.

Mysterious Trivia
Interestingly, mapping height to brightness looks exactly like certain solar images. Normally, a glowing object appears “flat” in color, as every point radiates equivalently. This apparent dim-around-the-edges behavior might occur if the Sun tends to emit more photons perpendicular to its surface. (Or if it was transparent, but the Sun is in fact opaque.)
Chris Hatton // Wed 2007.06.27 03:403:40 am

While this is a working solution (and kudos for dealing with the uneasy world of LScript), unless I misunderstand your aims I can think of an alternative to using the script which turn out to be more flexible. Simply, apply a Gradient layer to the colour texture of your surface, specifying the gradient as ‘Y distance to target’. Use a null object at 0,0,0 for the target. Then set black at distance 0 and white at the maximum distance/height of your surface. Then continue to use the orthographic camera as you’ve stated.

David Van Brink // Wed 2007.06.27 09:169:16 am

Hi Chris — Ha! You’re so right. Sometimes I’m drawn to doing things the hard way. Thanks for the tip, and the pointer to one of the many many useful bits lf lightwave, which I’m learning of so slowly. :)

oh, i dont know. what do you think?

David Van Brink // Sun 2007.02.25 12:48 // {scripting}

Two Handy After Effects Scripts

Two Handy After Effects Scripts


After Effects is just about my favorite application. Sure, I use Photoshop more. But Photoshop (and Illustrator, for that matter) lacks the elegance, the flexibility, the ruthless consistency of After Effects. After Effects has its user model of layers and compositions and timelines and parameters, and just goes all the way. It’s a beautiful app.

And around version 6.5 they added scripting. And the scripting works. Photoshop 7.0 and later also has scripting, but unlike After Effects the script execution is strangely slow and usually you can see it visibly manipulating the UI.

From this, I speculate that the internal architecture of After Effects is a bit tidier than Photoshop’s.

The First Script: launcher.jsx

Such speculation is fun, but I have work to do, and scripts help me to do it. Running a script from After Effects is a bit of a tedious affair. You have to choose a submenu from File, and then select the script to run. Well, how ever could we make that into a one-button process? Ah ha! With a script.

This little script, Launcher, scans one or more directories, and presents a set of buttons, one for each script it finds.

It’s a bit like the included “DemoPalette.jsx” but dynamically reads a directory. Also, it has a handy checkbox to drop into the debugger before running the script, if you’re developing fresh ones.

How To Use It:

  • Download it from the code-display below, with the download button. Put it in either <After Effects>/Scripts (to run it manually) or <After Effects>/Scripts/Startup (to have it start automatically).
  • Edit the file and change the first lines to point to where you keep your scripts. Be default, it just includes the regular scripts folder

The Second Script: rerenderMostRecent.jsx

This next one is trivial but handy. Sometimes I’m doing rough renders and I change my comp just at little and want to try again. This script simply redoes the last render you did. Thanks go to Dan Ebberts for helping work around a bug in the RenderQueueItem.duplicate method.

How To Use It:

  • Download it from the display below. Put it somewhere convenient (perhaps where Launcher can see it). Run as needed.
  • Caveat — it does not properly handle “based-on template” items. Create a unique Template from Edit:Templates:Output Modules instead.

Post Scriptum

Actually, I use Eclipse (a Java IDE) more than any other program, what with the Day Job and all. Another fine program, that.

oh, i dont know. what do you think?

David Van Brink // Mon 2006.12.11 13:14 // {java scripting}

Java 6, JavaScript

Java 6 is now available. There’s just one feature that caught my eye: JSR 223, support for JVM-based scripting languages.

Now, of course, that’s all wonderful, and they’ve got this full infrastructure to plug in any number of scriptable languages via a ScriptEngineFactory and that there’s all sorts of compliant languages that might be available… I’m sure it’s all quite fascinating.

The only thing I care about, though, is that, hooray, they include exactly one scripting language as standard in the JRE: EcmaScript, implemented by Rhino.

Now, of course, that’s all wonderful, and gives you the opportunity to add scripting to your application, oh how very moderne, obedy dobedy do and so fothe. But check out this super simple exciting usage! Forget all the power and generality, here’s a simple trick that solves a real problem that I bet you’ve had occasionally: simple text-based expression evaluation. Yeeha!

public static void main(String[] args) {
  RhinoScriptEngine e = new RhinoScriptEngine();
    Object o = e.eval("a = 24; b = 11; Math.sin(a) + b;");
    Console.print("result: " + o + " (" + o.getClass().getName() + ")");
  } catch (ScriptException e1)
      // (probably a syntax error in your expression)

Produces the following output:

   result: 10.094421637993376 (java.lang.Double)


Douglas // Tue 2006.12.12 23:5711:57 pm

Hey, that’s cool!

oh, i dont know. what do you think?

(c) 2003-2011 omino.com / contact poly@omino.com