Wallpaper Cycles in GNOME

GNOME has supported wallpaper cycles for a while now. I know that Ubuntu includes several of them in the default install. (Check them out; there's a Space image cycle, and a cycle for winners of a wallpaper contest.) However, if you want to make your own cycle, then you're SOL, cause there is no official GNOME editor for these wallpaper rotations. So I wrote a simple utility to make them:

#!/usr/bin/env python

import os, sys, datetime, random

# Configuration:
extensions = [ "jpg", "jpeg", "bmp", "gif", "png" ]
period = 5 * 60 # 5 minutes
transition = 5 # 5 seconds
starttime = datetime.datetime.today()
randomize = True


# Verify that we were given a filename:
if len(sys.argv) != 2:
print >>sys.stderr, "Please provide a destination filename."
exit(1)

# Select all images in the current directory:
imgs = filter(lambda x: x.split(".")[-1].lower() in extensions, os.listdir("."))

# Now, get all of their absolute paths:
imgs = map(os.path.abspath, imgs)

# Shuffle if needed:
if randomize: random.shuffle(imgs)

# Functions for writing the XML document:
def write_static(f, path):
global period
f.writelines([
"\t<static>\n",
"\t\t<duration>%d</duration>\n" % period,
"\t\t<file>%s</file>\n" % path,
"\t</static>\n"])

def write_transition(f, start, end):
global transition
f.writelines([
"\t<transition>\n",
"\t\t<duration>%d</duration>\n" % transition,
"\t\t<from>%s</from>\n" % start,
"\t\t<to>%s</to>\n" % end,
"\t</transition>\n"])

def write_header(f):
global starttime
f.writelines([
"<background>\n",
"\t<starttime>\n",
"\t\t<year>%d</year>\n" % starttime.year,
"\t\t<month>%d</month>\n" % starttime.month,
"\t\t<day>%d</day>\n" % starttime.day,
"\t\t<hour>%d</hour>\n" % starttime.hour,
"\t\t<minute>%d</minute>\n" % starttime.minute,
"\t\t<second>%d</second>\n" % starttime.second,
"\t</starttime>\n"])

def write_footer(f):
f.writelines(["</background>\n"])

# Open the file for writing:
f = open(sys.argv[1], "wb")

# Write the XML files:
write_header(f)
for i in xrange(len(imgs)):
write_static(f, imgs[i])
write_transition(f, imgs[i], imgs[i+1 if (i+1)!=len(imgs) else 0])
write_footer(f)

# Done!
f.close()

Usage:

./gen_wallpaper.py output.xml

The script will detect all images in the current directory, shuffle them, and write them into the output xml. You can then open that xml file in the background selection dialog (get the file dialog to show 'All Files') and your background will cycle through all of those pictures.

Have fun! I know this script has been pretty dang useful for me. :)

Cave generator

Well, my current project is at a standstill, cause I need to do some more planning, so I've decided to do a little bit of work towards that tunneler remake project I sort of mentioned in the last post.

First thing I wondered was: "How did Geoffrey Silverton generate those maps?" Indeed, they are real nice, and they rendered quick, even on the limited hardware of the time. However, the levels generated by the old DOS Tunneler are always very similar, with all obstacles cleanly placed along the outer borders. I wanted maps in my version to be larger and more labyrinthine. So, after a bunch of experimentation, I came up with an algorithm that generates fairly interesting maps with high precision. The algorithm is 3-phase:

  1. Tree Generation: A bunch of random points are placed on the screen. Then, we repeatedly make edges between the two closest points which are in disjoint sets. This will generate a non-intersecting, and fairly natural-looking, tree. We then draw this tree, so that the following phases have something to work with.
  2. Random Growth: We iterate over every point on the screen, and any point that is bordering a point that has already been set may then get set. Over many passes, the structure will grow, and will eventually cross some threshold (in this case 62%) where we end this phase. Also, I linearly reduce the probability of points getting set along the borders, so that we don't have have caverns colliding with the borders.
  3. Cellular Automata Smoothing: Using a slightly altered version of Conway's Game of Life, we smooth out the graph. The rules have been altered so that outlying points will die quickly, and so that the entire computation will converge to a solution.

Sample cavern

This isn't the quickest algorithm out there, but it's quick enough. The current version is written in Python, and it takes 14 seconds to generate a new graph. (Most time is spent on the random growth stage.) Once I'm more comfortable with the performance of the algorithm, I'll code it up it C, and hopefully we'll have a nice-n-speedy cave generator.

Any thoughts, btw? This is my first attempt at a random level generator, so it's probably not the best solution out there... But if you can do better, I'd love to see it, and possibly include it as a level option in this Tunneler clone. :)

Source Code (GPLv3)

Ant Farm Redux

Ok, so I've tweaked my program. It now has an extensible interface, statistics reporting, and will compress older folders in the archive with lzma (which I have come to love over the last week or so.) I'm kind of proud of this script, even though it is still very inelegant and hackish. It depends on ssh, scp, and fswebcam being installed.

Also, you'll need to edit the static variables in the ImageUpload class to include a place to ssh into. (Without a password.)

After all that, the usage is pretty simple:

./antwatcher.py VIDEO_DEVICE OUTPUT_DIRECTORY

Which in my case was:

./antwatcher.py /dev/video1 ./out

Source is here: http://www.poweredbytoast.com/files/antwatcher.py.txt

I still want to do some more stability checking on this program... I don't want the whole thing to give out 1 month in. Also, I'm hoping to get my hands on a better webcam. I got this thing for, like, 10 bucks off ebay 4 years ago, and it's age is showing: the video feed is low-res, blurry, and seems to cut out at random times, requiring me to unplug/plug the camera back in from time-to-time.

... oh, and I also need ants. ;)

EDIT: Oh, and happy new year DECADE! :)

Ant Farm

Ok, so for Christmas, my sister got me one of those cool gel-based Ant Farms you see on ThinkGeek. (Thanks, sis!) So what do I do? Webcam!

So, I've got this thing in a cardboard box, with a webcam leading in. This webcam is connected to my computer via a 50 ft USB extension cord, and I've already got a simple Python script that will use fswebcam (really cool program, btw...) to capture images every 5 seconds, and store them in an ordered directory structure, with 'cur.jpg' always pointing to the most recent pic. Then, every 10 seconds, it uploads that picture onto my server. I am crazy excited about this project. I've only got a few things left to do:

  • I want my program to use lzma+tar to compress older folders in the directory structure. That way, my program will only use up 13GB/month, instead of 16GB/month.
  • I want my program to have a nicer interface.
  • I would like to replace my current webcam with something with a higher resolution. (Camcorder, maybe?)
  • I need to get some ants.

Once I'm done with the program, I'll upload the code. Then, I'll get the ants, and I'll try to keep my computer up and running until all the ants are dead. (Should be 1-3 months.) Then, I can merge all of these images together to make a short movie following their hive's construction. It's kind of amazing just how much data this will be though... Given a 2 month run and an output framerate of 50fps, the movie will be nearly 6 hours long! I'm going to need to do some serious trimming...

But until then, I'll leave you with my most recent capture:

Ant Farm!

Utility Mill

It's 3:17AM, and I'm getting tired, but I just wanted to point out this awesome site I just ran across:

http://utilitymill.com/

Loads of fun utilities in thar! All scripts in there are written in Python, and GPL'ed! My current fav: http://utilitymill.com/utility/Markov_Chain_Parody_Text_Generator.

The revision histories seem to date back to at least 2007, though... HOW DO I NEVER HEAR OF THESE THINGS EARLIER!? D:

 1 2 3 Next →

About

User