Context Free – Computer Generated Art

I’ve rediscovered the programmer friendly art ‘package’ known as Context Free, a system that allows pretty and often fractal images to be created from things known as context free grammars. I had a go with this before, but couldn’t quite work out what was going on. This time though, things make more sense.

After a few random pictures, I managed to create the image you see above.

It’s done using surprisingly few lines of code, the magic being in the recursive nature of both the pattern and the code generating it:

startshape trunk

rule trunk {
SQUARE {y 0.2 s 0.1 1}

rule fork {
branch {y 1 x -0.33 r 45}
branch {y 1 x 0.33 r -45}

rule branch {
fork {s 0.7}
SQUARE {s 0.1 1}

I’m going to have a bit of a play with this and see what I can come up with.

Something I should have done a long time ago

Wednesday afternoons are when I teach a really irritating group of year 7 students. They seem unable to sit quietly, can’t listen to instructions and will do anything to distract the people around them. Following last week’s threat, they did today’s lesson on paper.

… the whole lesson … They’re learning about computer control; so flowcharts, statements, structure and order. We have a program called Flowol which lets them make simple programs using basic flowchart shapes, then link the programs to animated pictures. It’s programming, but at a level so simple the kids don’t realise they’re doing anything important with the computer.

The lesson was based around a set of traffic lights. All they had to do was plan out how to make the lights change in the correct sequence. And with the assistance of another teacher dragging the disruptive ones outside for a stern word, and a surprise visit from their head of year, the lesson went well.

Next week we’ll go back on the computers and make a big wheel work. I’ve done it with my year 9 class and I could see some of them getting that little buzz from making something work. I set them challenges – “make the wheel stop when the gate opens” “ok, now make the lights flash” and they’d go off and do it.

Welcome to my world kiddies 🙂 It’s just a shame they only do it once each year and the stuff we do is so limited. I wonder if I could do Logo with them at some point. I saw a really good Logo lesson being taught at my first training school.

Learning LWJGL, Slick and Slickset

Printed out the example Space Invaders clone, scribbled all over it to make sense of it. Turns out the old method of learning how to program still works pretty well. I guess I’m a visual learner since the simple act of printing the code onto sheets of paper so I could draw on them caused the code to make sense. I sat on my settee and by cross-referencing the code to the Javadocs was able to work out the boilerplate code from the actual game logic.

I also found the possibly dead, but handy Pixen pixel art package for my Mac.

I’m experimenting with some woolly psychobabble ideas too. My PC is in my office and I do work on it. The work is quite interesting and motivating. I also have my Macbook which I could do work on, if I bought the VMWare Fusion key that I need. My Mac has Eclipse installed though, and the SlickSet stuff all set up. It’s turning into a portable devkit quite nicely, and is currently being my “fun” coding environment.

Sure, I could sit at my PC with its twin 19″ monitors, a mouse and a clacky IBM Model M keyboard and run Eclipse. But my Mac lets me sit in my bedroom and code, or do it downstairs in front of the telly. This portability lets me code when I want to, where I want to. Personal coding is supposed to be fun and amusing, rather than something rigid that you’re paid to do. So anything that makes it more fun is going to help with motivation.

I’ll install Eclipse on my PC at some point, just to check the code runs OK in Windows and Linux. I’ll also commandeer Amy’s PPC iBook to see what it’s like on that too 🙂 She doesn’t know this yet though 😉

LWJGL, Slick and Slickset – Java Game Development

Programming other people’s systems is hard. Programming your own apps is easy, you just make them do what you want. The only hard bit is stopping when they’re finished, or continuing when it gets slightly tedious.

I don’t like tedious coding. I’d rather go away and code a code generator, or use Excel and search-and-replace, or anything that’ll solve the problem with the least amount of effort. I’ve got SQL stored procedures that generate C# code from other SQL stored procedures.

I’ve got that urge to write some simple retro-styled games again. I keep getting this idea every so often, but then give up when it comes down to actually writing them. I either can’t decide what to do, or get bored hand crafting yet another sprite library and doing my own implementation of collision detection.

Fortunately them I’ve found three things that’ll make my life easier. LWJGL is the Lightweight Java Gaming Library, which is quite nice. Built on top of this is the Slick 2D game library that removes some of the tedium of moving sprites and handling their collisions. Then, to make it even simpler I found something called SlickSet which is a 2D game engine. It’s got premade collision detection, “actors” and ways of managing lists of things.

It comes with nothing but the Javadoc for documentation, but the examples are fairly simple to follow. I intend on working out my own little sets of documentation, then sticking them up here at some point.

Programming is hard

Not only do you have to work out how to make the thing, but you need to understand the business process too, and understand what the user really means. It’s not enough to simply join databases to forms and bash out lines of SQL; there’s a requirement to understand what’s going on in the user’s head. Why is it important that their “Sales Order Report” has a “Sales Line Reference” on it? What is a “Sales Order Report” anyway? Who makes them and what are they used for?

Without understanding the way the user works, you can’t write their software.

So beware the next time someone says “can you make me a new stock system” since it’s not just a bunch of databases joined to a form. That’s like saying a human body is simply a bag of goo that moves on its own. Writing software is easy, the problems have all been solved and are hiding in Google somewhere, ready for you to find. The hard part is working out what the users are going on about.

Just how, with rigorously tracked stock levels where everything is accounted for, down to the last widget, do you cope with “well sometimes people just walk in and buy stuff with cash, and we don’t run it through our books because it’s not worth the effort”? Business processes are what happen when groups of people come together and try to gain the upper hand on each other, it’s not a neat well-defined system you can pack into a box and label “selling widgets”.

It’s fun though. There’s comms hardware out there that communicates using port 6666 because I randomly chose it one night.

Designing out the confusion

Steve, who I used to work for, came over to visit this evening. For the past year I’ve been converting one of his pieces of software from C++/MFC to C#/Winforms. The program is a kind of stock management sytem with a database back end.

Following Steve’s design has been fairly straight-forward. It helps porting an application if you have not only the original source, but the person who wrote it to hand.

One part was being rather confusing, dealing with how items of stock are stored in the database and how they are related to each other. After about an hour of playing with the C++ version and Steve explaining what was going on, I managed to untangle my brain and write some notes that now make much more sense. What I thought was a hideously complex system is now somewhat simpler.

We also went up the road to a nice pub and had some nice food. I had a steak with a piece of roast chicken breast on the top, and a bowl of chips.

So much code!

I woke up 14 hours ago, and except for a few hours thoughout the day for mundane things like eating, having a bath and “watching TV to avoid going insane” I’ve spent the time sat at my PC churning out code as if my compiler had an expiry date. The program I’m working on now has stuff that can be demonstrated to the client, and I’ve not managed to crash it yet, which is good.

There’s a large hole in the software that I can’t quite fill correctly. This project is a rewrite of an older Visual C++  version of the software and initially I simply ported all the code and database across to C#. Now the database has been rearranged and redundant data stripped, big bits need rewriting. Somewhere along the rewrite a database table has either vanished or been folded into another table. I think I’ve found the definition for it in some notes I have, but I’ll need to sit down with a really hot cup of tea to go through things and sort them out.

My brain hurts though so that’s job for tomorrow before my parents come to visit.

More C# Coding

Those code generating stored procedures I wrote the other week work really well. I’ve just had to rearrange a database table, adding more fields to it. It took no time at all to get the new C# code created and running.

Coding database apps becomes that bit more fun when creating new database tables ceases to become an expensive time-consuming operation.

XCode and Objective-C from Visual Studio and C#

I’m a Windows developer in my spare time. I used to write MFC apps in C++ using Visual Studio 6. Then the world changed and now I write Winforms apps in C# using Visual Studio 2005. Windows has a certain way of doing things that I’ve become accustomed (brainwashed) into doing without thinking. Absorbing C# seemed to take about half an hour. I’m now attempting to learn how to write OSX applications.

This is my very first step at learning how to do all that Windows stuff on my Mac, but doing it the Mac way. Witness as I learn totally alien concepts and discover I’ve fatally broken my Mac’s devkit even before running it.

Continue reading XCode and Objective-C from Visual Studio and C#

More Coding

Managed to churn out a big chunk of functionality in the software I’m writing, in only two hours. This left me ample time to switch my brain off and watch telly.

Spend time writing little scripts and tools to automate tedious jobs. If it takes you an hour to write something that over time saves you two hours of mind numbing, motivation killing tedium, it was worth it.