Wednesday, September 2, 2009

fractal pinwheels

These are some little pinwheels made by a little fractal line drawing + you typical draw lines around a circle code:



You can see it in action here. Click anywhere to draw a random pinwheel... and hit space key to clear them

Here is the function to draw the lines:

public function funky_line( g:Graphics, x1:Float, y1:Float, x2:Float, y2:Float, depth:Int, max:Int ) {
if ( depth > max ) {
g.moveTo( x1, y1 );
g.lineTo( x2, y2 );
} else {
depth++;
var nx = -1 * ( y2 - y1 ) * ( depth / ( depth * depth ) );
var ny = 1 * ( x2 - x1 ) * ( depth / ( depth * depth ) );
var xm = x1 + ( x2 - x1 ) / 2 + nx;
var ym = y1 + ( y2 - y1 ) / 2 + ny;
funky_line( g, x1, y1, xm, ym, depth, max );
funky_line( g, xm, ym, x2, y2, depth, max );
}
}


Max is the number of recursions and count is the number of lines to draw around the circle...

Neato...

Monday, August 17, 2009

xquery script

The other day, I really wanted to be able to run an xquery expression over some xml and use it as some scripting input... I was really surprised to see there really doesn't appear to be a nice way to do this!

After all... xquery is the xml equivalent of grep. Imagine! Landing in an OS with no grep equivalent!

Oh, wait... I just described windoze...

I wrote a small piece of XLS wrapped in a script( xsnap.sh) the script got a slightly more complicated once I found out that if an input document has a namespace defined, you have to use it in your expression.

Now this is handled like magic, but can be turned off by uncommenting the line "XSNAP_SMARTY" then you can specify "xsnap:expression" to match the default ns of the document.

Here is the dealio: xsnap.sh "groupId/text()" pom.xml
junit
hsqldb
...

And viola! A "grep-like" tool for xml!

This mechanism is more robust that just grepping xml since it uses the xquery standard junk.

Saturday, June 6, 2009

Voronoi diagrams as seamless tiles

Check out my groovy new seamless tiles.





I now have an easy way to use Voronoi diagrams to generate seamless tiles! Fun!

Feel free to get any sort of use out of them you can.

Friday, May 29, 2009

file timestamp in RFC-2822 format

Creating an RSS feed from a script was pretty straight forward, but I ran into some nuisance getting the file timestamps in the right format:

element pubDate: Schemas validity error : Element 'pubDate': [facet 'pattern'] The value 'Thu May 28 22:53:18 EDT 2009' is not accepted by the pattern '(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)), *)?\d\d? +((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec)) +\d\d(\d\d)? +\d\d:\d\d(:\d\d)? +(([+\-]?\d\d\d\d)|(UT)|(GMT)|(EST)|(EDT)|(CST)|(CDT)|(MST)|(MDT)|(PST)|(PDT)|\w)'.

element lastBuildDate: Schemas validity error : Element 'lastBuildDate': 'Thu May 28 22:53:18 EDT 2009' is not a valid value of the atomic type 'Rfc822FormatDate'.

That's the output of validation from xmllint and the XSD I have... if it's "RFC 822", "RFC 2822", doesn't really matter that much to me...

I finally got ls to produce this output format:


% ls -l myfile --time-style=+'%a, %d %b %Y %T %z' | cut -f6-11 -d' '


The date command has a nice flag (-R) that will print in this format too:


% date -R ; date +'%a, %d %b %Y %T %z'
Fri, 29 May 2009 10:14:53 -0400
Fri, 29 May 2009 10:14:53 -0400


Makes me wish we could just use %s... :-P

Wednesday, May 27, 2009

css sprites for js games

The other day, I started to look at css sprites again.

Imagemagicks' montage command is a groovy way to concatenation images together:

montage  ???1.png   -tile 1x -geometry +0+0 -background none last1.png


Along with some js shenanigans, I was able to write a small bejeweled-like puzzle game.

It's pretty neato! Give it a go!!