Showing posts with label Processing. Show all posts
Showing posts with label Processing. Show all posts

Wednesday, 5 November 2008

Anti-aliasing in Processing

Over the last few days, I have started to play with Processing, primarily to get a feel for its capabilities.

On the whole, I am impressed by the simplicity. It took me less than a minute to produce some (albeit simple) graphics. The lack of the normal "clutter" associated with most programming languages is a big plus for those that just want to produce images.

What I am less impressed with are some of the idiosyncrasies. Two in particular revolve around the functions loop()/noLoop(), and smooth()/noSmooth().

The loop()/noLoop() functions control whether draw() should be called once, or continually. By default, Processing is set to loop(). This is fine for animated graphics, and applications with some user interaction (such as through keyboard or mouse events), but for simple static graphics it has two downsides.

The first is on machine performance. A quick look at a performance meter shows that the continual redrawing has its cost. For simple applications, this may hardly be noticeable, but an application that involves any disk access (e.g. image reading) or complicated calculations is likely to noticeably impact machine performance. It is therefore important to keep any operations that only need to be performed once in the setup() function.

The second downside is image quality, and this is where the smooth()/noSmooth() functions come in. The smooth()/noSmooth() functions control anti-aliasing. This is important in computer graphics. We have moved on from the primitive computer graphics of the early 1980s home computers such as the Sinclair ZX Spectrum, and yet the default in Processing is set to have the anti-aliasing switched off with an implied call to noSmooth().

To me, the default settings for these two functions are wrong. Anybody new to Processing is going to start with simple, static images. They will be looking at issues like ease of use, and image quality. Surely it would be better to default to noLoop() and smooth(), rather than loop() and noSmooth() as is currently the case?

This isn't just an academic argument either. As I will show below, these settings have a very visible effect of results.

Consider the following code. The intent is to draw a black circle on a white background:
void setup(){
size(140, 140);

background(255); // White
stroke(0); // Black

strokeWeight(10);
ellipseMode(CENTER);

smooth() or noSmooth();
loop() or noLoop();
}

void draw(){
ellipse(70, 70, 120, 120);
}
It will be noted that this code is not entirely syntactically correct. The smooth() or noSmooth() and loop() or noLoop() lines give 4 variations. The table below shows the result of these variations:



noSmooth()smooth()
noLoop()
Suggested default settings
loop()
Default settings

The visual differences in image quality are obvious. A check sum compare of both of the unsmoothed images shows that they are byte-for-byte identical. The same is not true for the smoothed images.

I don't understand why the developers of Processing choose these defaults, and nor do I understand why the smoothed image quality is reduced when looping, unless there is some deliberate throttling of the algorithm to reduce processor overhead.

So, to recap, if you are drawing static images, I recommend the following skeleton code:
void setup(){
size(x, y);
smooth();
noLoop();
}

void draw(){
}

Sunday, 26 October 2008

In the beginning ...

... I, along with many other Open University students, was sent an e-mail by Professor Darrel Ince seeking volunteers to join a mass writing project. The aim? Very simple! Take approximately 85 individuals, who prior to signing up for this project, in the main, are unknown to each other, and get them to write a book about Processing, a Java-based computer-art environment.

OK, so why am I doing this?

Well, a number of reasons:
  1. It is a good opportunity to explore new ways of working; collaborating with individuals mainly via the Internet has many potential advantages and disadvantages. This is an ideal opportunity to gain experience first hand.
  2. To get used to academic writing. I will (hopefully) be writing a dissertation for my MSc in a few years time, so any writing experience I can get in the mean time will be useful. I just need to finish the PGDip first!
  3. To attempt to explain technical and mathematical subject matter in manner that those with little or no technical or mathematical knowledge can understand. Techies are notoriously bad at being able to explain themselves in simple language, and I include myself in that.
  4. To learn a new technology; I had never even heard of Processing prior to this project.
  5. I am hoping to tie this project in to the next unit of my PGDip, which is Project management. I need to e-mail my course tutor to check if he deems this to be a suitable project, in terms of the course requirements and objectives.
  6. To have some fun!
So, what next?
  1. Download, install and play with the Processing environment. Done.
  2. Order Ira Greenberg's book that the OU is very kindly buying for each of us. Done.
  3. Choose a chunk to write. Done.
Obviously, there is loads of other stuff to do (like write some words and code), but the above will keep my busy for a while.