processing

back to processing

I’ve been creating some rudimentary experiments in Processing, to get back into the way of coding.

First, there was my attempt to create a portrait from short, straight lines. The sketch is given a high-key, close-up photograph of a face. It picks random points below a certain level of brightness then draws short lines between them:

There are three main variables: the cut-off level of brightness, the number of random points picked, and the maximum length of line allowed. It would be possible to add sliders to the sketch, so that these variables could be controlled by the viewer. I looked at the ControlP5 library for use in the Erasure exhibition (which incidentally ended yesterday), but decided against using it for the interactive elements. I might try it for this exercise though.

Tags:

Tuesday, May 3rd, 2011 coding No Comments

cracked it

Another good Skype session with Ollie on Monday. We started to develop the previous session’s particle system into a smoke simulation.

I couldn’t get to sleep that night, and lay in bed wondering about using Perlin noise in the smoke simulation when I suddenly realised I’d found a solution to some code I’d been struggling with a few weeks ago. (OK, it took a while, but I got there in the end). I’d been trying to write code to simulate cracks, and had used Perlin noise to give them a natural look. It worked, but what I’d been unable to do (until my belated Eureka moment) was specify exactly where the crack should start.

Now I can do precisely that, so the way is open to write the code as a function that accepts parameters, which means I could call the function from within itself to get smaller, branching cracks. Yay, me.

Still got a long way to go with the smoke simulation, though.

Tags:

Thursday, October 21st, 2010 coding No Comments

useful particle system

Another fascinating Skype session with Ollie on Monday evening when we set up a basic particle system. I’ve explored these before, but what was different was the creation of a Force class as well as the particle class. Instances of the class can be created as many times as you like within each particle. By passing different parameters during the creation of each force, you can specify how they act. It’s so simple, but very useful.

I’ve since created lots of different types of particles just by changing a few parameters: fireworks, fountains, sparks, and balls, with forces of momentum, gravity, wind and air resistance.

I’ve still to get the rebound right when particles bounce off the floor, but after that, my goals are to explore mass and smoke.

Tags:

Wednesday, October 6th, 2010 coding No Comments

variations on a theme

I’ve been spending a lot of time coding recently, which has been great. Mostly I’ve been writing short sketches that take an image and do different things. In doing this, I’ve learned a few new techniques.

They’re designed to be flexible, so that they’ll work with any image. but really, in their current form, they would work best with images that have large areas of well-defined darks. I could add an interactive control for the user to select the cut-off level, so that it can be adjusted to a more appropriate setting for each image they’re applied to.

In the meantime, here are a few examples. Some are stills from animated sequences.

Tags:

Sunday, October 3rd, 2010 coding No Comments

mighty biomorphin’ power rangers

It’s been a while since my last post, mainly because I’ve seen a lot of impressive work in various places and I’ve felt very small and insignificant in comparison. I also went on a training course recently which claimed that 80% of people achieve only 20% of their potential. As someone who likes to potter about and explore different things, I know that I fit into this category. Perhaps I ought to buckle down and concentrate on one particular thing. But the use of the word ‘ought’ is enough to put me off. Like most people, I’m not good at persevering at something I’m not been interested in.

I’d been feeling this despondency to such an extent that I was beginning to wonder whether I’d reached the end of my little experiment in genetic algorithms. For various reasons I’d not had a session with Ollie on Skype for several weeks until tonight , and I was starting to wonder whether it was worth chasing down every little aspect of code. I know now how to implement these algorithms, so perhaps it was time to move onto something else.

Well, how foolish was that thought? Very.

Tonight’s session was stimulating. Ollie suggested a technique to overcome a particular coding problem (showing me that I needed to convert in one place from an Integer object to a primitive int), as well as getting me to think of a way to speed up the routine that checks whether each fly has been trapped by a web. Those are both very useful for the sketch, but what really got me interested was the discussion afterwards about where we could take this next.

I was getting bogged down in the appearance of the sketch and in the limited number of characteristics included in the coding. So far I’ve been using ellipses as a quick and dirty representation of webs. These are both boring and limited, but because the webs are a class, it would be easy to replace the ellipses with something else, such as Richard Dawkins’ biomorphs. Rather than use human intervention to select which creatures breed, they could be ranked on their success in trapping flies. This opens up a lot of possibilities. If a fly successfully moves past the outer edge of the biomorph, then an inner arrangement would be useful to add another layer to trap it. This means that sheer size isn’t the only aspect of a successful predator.

The more successful webs could have more energy to use in the next generation, so some might evolve to require lots of energy but therefore need to trap a lot of flies, while others might need less, and therefore survive on very few flies. It would be possible to reach a point where some creatures have evolved so far from each other that they can’t breed with each other. The flies could evolve too. Very soon there could be enough complexity that it would be difficult to predict the results. Suddenly I’m very interested again in this exercise.

Tags: , ,

Monday, September 6th, 2010 coding No Comments

private functions

I’m on a roll now, with a second abstract class, this time to handle the breeding of creatures. I’ve kept it general, so it could be used for other genetic algorithm sketches.

One method, for the first generation, returns a string of random 1s and 0s, while another (still to be tested) accepts two ‘parents’ and breeds them, with an optional chance of mutation. I’ve also moved some functions, such as building the webs out of the DNA, into the web class and made them private so they can’t be accessed from outside. It’s all looking a lot more organised and controlled.

Tags: , ,

Thursday, August 19th, 2010 coding No Comments

class converters

Got it! Rather than think of classes as objects, think of them as containers for groups of related actions.

I now have my first abstract object: a function to convert four digits of zeroes and ones from Gray Code to Base 10. My genetic algorithm sketch doesn’t require conversion in the other direction or alternative class constructors to handle different quantities of digits, but it would be simple to add the required functions to the class. Next subject for a class: breeding new generations of webs.

Tags:

Thursday, August 12th, 2010 coding No Comments

apologies in advance for the geek talk

I spent most of the weekend struggling with the genetic algorithm sketch in Processing. I’d created a version that worked but was coded very inefficiently using strings, so I wanted to rewrite it using arrays. It was galling to find that my attempt at efficiency refused to work at all.

A few hours away from the computer, however, allowed me to think it through afresh, and I saw where I was making a mistake. I hurried home on Monday after work to rewrite the troublesome section in time for the Skype session with Ollie, and voila! It worked. I quickly added the ‘fly‘ class from previous versions, only to find, on calling one of the fly methods, that I received an error message I’ve never seen before: ‘Badly formed character constant’. All that the method does is draw a small rectangle to represent the current position of the fly object.

OK, so I’ve searched my Processing books and Google for an explanation of this, and found some oblique references, but what startled me was that during the Skype session, when I was demonstrating this problem, it worked fine, but as soon as the session was over and I tried again, I got the same error message. I must have changed something somewhere, but I have no idea what. Grrr.

Anyway, after discussing the latest version of the sketch, we agreed that I should refactor the code to use more classes and some ArrayLists. Neither step is completely new for me, but I’m taking tentative steps into unfamiliar territory, especially the idea of using abstract classes that have no real world counterparts like ‘fly‘ and ‘web’. The next week will be busy with other things, so it can be simmering at the back of my mind. If I appear distracted over the next few days, you’ll know why.

Tags:

Tuesday, August 10th, 2010 coding 4 Comments

gray matter

Last night’s session with Ollie Glass in developing a genetic algorithm for spiders’ webs led to discussion of Gray code in place of binary numbers to represent characteristics of the webs. I’d never come across the concept before, but I can see the benefits for genetic algorithms. Two successive numbers only ever differ by one bit, so an arbitrary mutation of one bit won’t lead to a massive change in value. (The rest of the discussion on Wikipedia left me cold though.)

There won’t be a session next Monday, but I’ve got a lot of work to do to follow up the material we covered last night. This is where the algorithm starts…

Tags: , ,

Tuesday, July 20th, 2010 coding 3 Comments

and then there was one…

I’ve completed the next step in my genetic algorithm project: collision detection between flies and webs, based on the colour of the pixels.

It’s slowed the code right down, so as a first step in improving its efficiency, I changed it so that it only checks flies that haven’t already been trapped. Without any other improvements, it means that the remaining flies appear to move faster and faster, as though they’re trying to escape, until the last fly, alone in a dangerous world and surrounded by the corpses of its fellow creatures, desperately searches for salvation until it too is inevitably trapped and killed.

Empathy for a few pixels? What a ridiculous idea!

Tags: , ,

Friday, July 16th, 2010 coding No Comments