Richard Jones' Log

Sun, 23 Aug 2009
Python's 9th write-a-game-in-a-week challenge

Theme voting for the latest (9th!) write-a-game-in-a-week PyWeek challenge is on!

Everyone should write a game and this is the perfect venue for doing so - you've only got a week (a lot of game ideas can be written in a weekend) and there's lots of help available. And it's a lot of fun!

So get to it!

category: Python | permanent link
Wed, 19 Aug 2009
Something I'm working on...

This will probably be the last of these posts before I make the project public. It has two code parts. The first is model:

import random
class Cell(object):
    def __init__(self, i, j, has_bomb):
        self.i, self.j = i, j
        self.has_bomb = has_bomb
class Board(list):
    def __init__(self, size, chance=.2): 
        self.size = size
        self[:] = [[Cell(i, j, random.random() < chance)
            for i in range(size)] for j in range(size)]
    def count(self, cell):
        '''Count the number of bombs near the cell.'''
        return sum(self[j][i].has_bomb
            for i in range(max(0, cell.i-1), min(self.size, cell.i+2))
                for j in range(max(0, cell.j-1), min(self.size, cell.j+2)))
board = Board(20)

And the second is the withgui code:

with gui.canvas(width=320, height=320) as canvas:
    for column in board:
        for cell in column:
            @canvas.image('cover.png', x=cell.i*16, y=cell.j*16)
            def on_mouse(image, mouse, cell=cell):
                count = board.count(cell)
                if cell.has_bomb:
                    image.value = 'bomb.png'
                    print 'GAME OVER!'
                elif count:
                    canvas.label(str(count), x=cell.i*16+8, y=cell.j*16+8, 

Resulting in (youtube vid, sorry about the quality I'm new to this):

Tue, 18 Aug 2009
Something I'm working on...

with kytten...

Mon, 17 Aug 2009
More pausing

I got distracted mucking about with Python 3.1.1 and Tcl/Tk 8.5 today -- withgui works with both (only had to make very minor edits to get it working under Python 3000.)

More interesting update tomorrow, I hope :)

category: Python | permanent link
Fri, 14 Aug 2009
Brief pause

Today was a day of rest so naturally I spent it refactoring the heck out of withgui*.

The upshot is that a couple of artificial restrictions have been removed and the Tkinter reference implementation is now significantly clearer.

* still a working title; no final title yet ("gui", "show", "pomp" and "fjord" are candidates)

Thu, 13 Aug 2009
Something I'm working on...
with gui.canvas(background='antigravity.png') as canvas:
    with canvas.image('smiley.png', x=0, y=20):
        def animate(image):
            while image.x < 200:
                dt = yield
                image.x += 20*dt
        def on_mouse(image, mouse):
            print 'Got me!'

Screen capture at 10 frames per second; original animation runs smoother.

Comic fragment taken from XKCD #353 "Python". Smiley is all original art ;)

Wed, 12 Aug 2009
Something I'm working on...

No update yesterday because I was at MPUG giving a presentation about this stuff...

with gui.form() as form:
    name = gui.row('Name', gui.text())
    skill = gui.row('Skill level', gui.selection(['Awesome', 'Radical', 'Understated']))
    def on_click(button):
        print 'Got name=%r'%name.value
        print 'Got skill=%r'%form['skill'].value
    def on_click(button):
Mon, 10 Aug 2009
Reminder: Next MelbournePUG meeting: Tuesday 11th August


The next meeting of the Melbourne Python Users Group will be on Tuesday the 11th of August starting at 6:30pm. We'll have use of their projector and time for several short presentations or lightning talks.

Meeting details, location and talks list are at: the MelbournePUG wiki page.

15 minute talks
Martin Schweitzer "Primetime Wordfinding"... It's a rather novel algorithm that I (re)discovered(?)* for finding word matches when given a group of letters (eg. think of the puzzle in the age where you have a grid with 9 letters and have to find words). I then noticed that it had applications to other fields such as bioinformatics (which I won't go into in the talk [unless, of course, there is a particular interest]). It also has a very nice representation in Python - which I will mention.
Richard Jones ... a new cool thing I'm working on
5 minute lightning talks
Chris Miles "Intro to PSI (Python System Information)"

If you've seen something cool or are doing something cool then we'd like you to tell everyone about it! Presentations could be 5 minutes or up to 15 minutes if you'd like to ramble for a bit longer. I'll be getting up to talk a bit about my experiences playing with IronPython - what's cool and what's downright odd :)

If you've got an idea for a talk just add it to the wiki page.

category: Python | permanent link
Fri, 07 Aug 2009
Something I'm working on...
with gui.column():
    text = gui.label('hello!')
    items = gui.selection(['one', 'two', 'three'])
    with gui.button('click me!'):
        def on_click():
            text.value = items.value
            text.foreground = red
Thu, 06 Aug 2009
Something I'm working on...
import withgui
gui = withgui.Window()
Wed, 05 Aug 2009
Something I'm working on...
with gui.button('press me!'):
    def on_click(*args):
        print 'hello, world!'
category: Python | permanent link
Tue, 04 Aug 2009
Something I'm working on...
gui.label('Hello, world!')
category: Python | permanent link