Making tileable images with Python

July 18th, 2009

Here's an interesting bit of Python code I hacked together – it's a script that takes an image and warps it so that it is tileable (making it suitable for a repeating backgound or a texture in a game).

A fractal

A Mandlebrot fractal

If you use it on a photograph, it will come out looking like a fair-ground mirror. But it works well when applied to a pattern, or something more abstract, such as the fractal image on the left.

The code is public domain – use it for whatever the heck you want!

 

Python Job Alert

July 14th, 2009

My employer is looking for a new Python developer to work here in Oxford, UK. The company I work for runs 2degreesnetwork.com, which is collaboration service for sustainable business. Basically, it's a social networking type of site for businesses to collaborate on climate change and related issues. I'm not officially allowed to say this, but the closest analogy is ‘Facebook for Businesses’.

 

To err is human

July 12th, 2009

I noticed recently that I say ‘err’ or ‘umm’ a lot when asked a question, particularly for questions that aren't factual in nature, and have no right or wrong answer. For instance, if I were asked “what is the capital of Turkmenistan” I would answer “Ashgabat” (which everyone knows) without any umming or erring. But if I were asked “would you like milk in your Americano?” I would answer “err… yes”.

 

Birthday Boy

July 5th, 2009
0 AW (After Will)

I'm on the right. I have put on a little weight since then.

Today is my birthday. The universe is officially 35 years old today! :-)

Another year without anyone discovering that I have been faking being a grown-up for all these years. Maybe soon I'll have to start being all responsible.

My forties are not long off. Funny how round numbers are psychologically significant; there is nothing I can do at forty that I couldn't do at thirty nine (or vice versa). Then again, maybe I'll start wearing knitted cardigans and voting conservative – who knows!

Actually I think I'm going to avoid all that “OMG I'm going to be forty!” nonsense, and only worry about ages that are a power of two. Sixty-four is a long ways away, so I can relax for a while. Maybe by then I'll also be a grown-up for real, or I may just leave that for my one-hundred-and-twenty-eighth birthday.

 

I take it back, this is the most inneficient code ever

July 1st, 2009

Here's the most convoluted “Hello World!” script I could come up with (in response to this). I don't know if it works. I've proven it correct, but I haven't tested it.

from random import choice
from itertools import count
from zlib import crc32
import sys
any(crc32(h)==472456355 and not sys.stdout.write(h) for h in(''.join(choice('! edHlorW')for _ in '.'*12)for _ in count()))

I promise my production code is (marginally) more readable this this…

 

Jen's Wedding

June 23rd, 2009

My little sister got married! Congratulations Jen & Scott, I'm so happy for you both.

www.flickr.com

More Photos

 

A 3D Texture-Mapped Globe Rendered with Javascript and HTML

May 30th, 2009

I've been working on a large-ish Javascript project lately (still in stealth mode). One that could be described as a Javascript application. And since I've been up to my elbows in Javascript, I have found my contempt for the language waning. Not entirely, of course – I'm still a Python fan-boy. But enough for me to knock out a 3D(ish) spinning texture-mapped globe, using nothing but Javascript and HTML, as a way of honing my JS skills.

Without further ado, I present you with a 3D Javascript Globe.

 

Django like templates in Javascript

April 5th, 2009

Here's a quick ‘n’ dirty Javascript function I hacked together that provides Django-like template substitution.

function sformat(template, data)
{
    return template.replace(/{{(.*?)}}/g, function(m, n) {
        return eval('data.'+n);
        });
}

Used something like this:

sformat("Hello, {{ name }}!", {name:"World"});

Which returns the following string:

Hello, World!

Alas, it doesn't support anything other than substitution. If you need anything more advanced (loops etc), you should investigate Javascript template engines.

 

There's always a way

April 3rd, 2009
Always a way

Where there is a Will, there is always a way.

Spotted in a deli in Oxford. It says ‘Where there is a Will, there is always a way’.

Thats right – always a way!

Just saying.

 

Fuzzy Thinking

April 1st, 2009

I have an idea germinating that involves using fuzzy logic, something I only had a passing knowledge of. After reading the Wikipedia articles and Googling for it I'm more informed but still haven't found a perfect resource.

The only Python code I have found was informative, but it was from way back in 1990. If there are any Pythonistas who know of a more up-to-date fuzzy logic module, or fuzzy logic resource in general, please let me know!

 

My Tweets

Will McGugan

My name is Will McGugan. I am an unabashed geek, an author, a hacker and a Python expert – amongst other things!

Search for Posts
Popular Tags
 
Archives
2009
 
Recent Comments
Hi Will, I brought your book from Amazon. I think its a great book. It has given me everything i ...
- P K on A bad review
yeah! red hair looks good!! thanks 4 your help in our project in science under maam b.
you have a nice decision.
@ Anatoliy But this is, hopefully, what you're looking for. His library is extensive enough that it provide the features ...
Thanks for this. I started writing my own and was starting to get a little frustrated when a friend pointed ...
- Ahlywog on BBCode Python Module
 
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan