Don Havey

Sustainably harvested information

Archive for the introduction tag

Building blocks  

I’ve written a very brief introduction to Processing. Hopefully people found it so tantalizingly uninformative that they resolved to visit the Processing website and learn the basics of the language via the tutorials there.

Today, I introduce my generic classes: the building blocks on which I’ll be creating some exciting applets for your viewing pleasure. This will be a little boring. You can skip it if you want, but in order to understand the code in future examples, you’ll eventually need to understand what’s happening in these core classes.

Wait!

I need to define the word class for those not accustomed to object-oriented programming and who haven’t read the tutorials yet. A class defines a type of object that can replicated within an applet. As an example, if you were creating a digital garden of sorts, you might define a “flower” class. Each class has a constructor function, which, when called, creates a new instance of that class. So for your pretty flower garden, you would write:
class Flower{
  //initialize all variables that belong to the flower class
  int npetals;
  //the flower class constructor function
  //is called whenever you write "new Flower()"
  Flower(int $npetals){
    //assign values to this instance's variables
    petals = $petals;
  }
  //some other function of the flower class
  void look_pretty(){
    //do something to look pretty
  }
}
//somewhere else in our code, we can now create flowers:
//initiate an array to contain some flowers
int nflowers = 50;
Flower[] flowers = new Flower[nflowers];
//loop through the array and initiate that many new flowers
for(int i=0;i<nflowers;i++){
  flower[i] = new Flower(floor(random(5,12)));
}

Additionally, classes can be extended so that one class may inherit all of the methods and variables of another, and add some methods and variables of its own. More on that later.

Wait again!

Before I continue, I should admit that my coding style is a little nonconformist. I tend to write denser code than is recommended… less whitespace… and sometimes I’ll make two related statements share a line. This will make my code a little awkward to read for people who come from stricter programming backgrounds. Too bad. I like density. Less scrolling, less eye movement, less space. It’s an unbreakable habit! Sorry.

Proceed!

Getting back to the point….

This is an unintentional set of core classes. I did not sit down and think “I need core classes, maybe I’ll write some.” That would be a silly thing to think. You can already find many great pre-built classes on the Processing website. Rather, this set of classes evolved from many many projects, each of which required some addition to the classes I created for a simpler (previous) project… until I had a pretty comprehensive set of core classes, which I now reuse compulsively.

I am making these classes (and all the source code files I upload to this site) freely available. They can be modified and distributed at will, as long as the credits and statement at the top of each file remain intact. If you love them, you can use them for your own projects, but I’d recommend taking a look at the libraries available on the Processing website first. You can probably find a better set of classes available there.

If you really love these classes and are planning on using them in your own work, you could buy me a drink or something.

Download the classes

Click here to get the files.

You’ll need to open the files in Processing to take a look; I won’t be posting the entire source here. The Processing editor’s syntax highlighting makes the code much more legible than what I could offer you on this page. I’ll only be describing the classes and posting snippets of the supporting code here.

Read more…

The article has

no responses yet

Written by Don

April 5th, 2008 at 8:31 pm

Introduction to Processing  

It’s time to get the real content started.

Processing is an open source programming language and environment for people who want to program images, animation, and interactions.

The Processing website states it pretty clearly. Processing is a tool used primarily for visualizing data. It is based on Java, but uses a much simpler syntax, and adds a very powerful set of graphic output tools. I would call it a fourth-generation language (others might say fifth- or sixth-generation): Java is based upon C/C++, which in turn is the offspring of the most ancient and revered ALGOL. My rule of thumb? The more generations the better. Unless you hate sunlight.

The tutorials that you’ll find on this site assume that you have some experience writing code… or at least that you aren’t daunted by the jargon. If you need a primer, the Processing website is the place to look. They have a number of tutorials and a helpful forum.

Let me start by describing Processing in relation to other languages.

Object-Oriented and Procedural

One of the unique characteristics of Processing is that it can be used in an object-oriented or procedural manner. Object-oriented code is generally more flexible and deployable, but procedural code can be much simpler to implement for small scale or calculation-heavy projects. I’m going to assume that you’re ready for object-oriented (abbreviated OO or OOP) solutions, as most of the tutorials I have lined up are fairly complex, and therefore require an object-oriented, class-based approach.

For the sake of comparison, Java is a strict object-oriented language. Actionscript is technically an object-oriented language, but you can think of Flash’s timeline as a way of using Actionscript procedurally. VBScript, Perl, and Fortran are examples of procedural languages.

Strictly Typed

Processing is a strictly typed language. Not “typed” as in keyboard. “Typed” as in “defined as a specific type of variable.” Variables are defined by their type. For example, a number would be defined using either the floating point type (for decimal numbers) or integer type (for integers). Once a variable’s type is set, it cannot be changed. However, values can be cast to a variable of a different type. For example:
int i = 6;  //i is defined as an integer, it must always remain an integer
float f = (float) i;  //the <u>value</u> of i is cast to a float
print("i = "+i+"   f = "+f);  //outputs "i = 6   f = 6.0" (notice the decimal!)

This strict typing system helps avoid compiling errors, but does limit Processing’s ability to deal with objects and arrays. If you’re used to programming with Javascript (not typed at all) or Actionscript (flexibly typed), this will be the hardest thing to get used to.

Inherent 3D Rendering

This is huge. There are two built-in 3D renderers available for use in the Processing environment: OpenGL and P3D. OpenGL tends to be the faster of two, and has more rendering options available. I use P3D only when I need to render lots of 2D text in 3D… which looks better than in OpenGL.

If you’ve ever written your own 3D rendering scripts in Actionscript (or similar), you’ll appreciate the ease with which Processing renders and transforms 3D objects and coordinates. It includes built-in matrix transformation tools for rotating and moving the camera. This aspect of Processing currently has no equal in any other programming language.

Okay. That’s it for the introduction. Next on the agenda is a look at some of the generic classes of mine that I’ll be using in the tutorials to come. Until then…

The article has

no responses yet

Written by Don

March 25th, 2008 at 1:18 pm

Getting started  

Let me begin with the theme of this blog:

Sustainably harvested information.

I’m interested in the idea of conserving bits. I’m not sure exactly why, but I have a feeling that it stems from my opinion that physical matter and information are nearly one and the same. Therefore, an extension of general (physical) conservation and efficiency would be the conservation of information. The smallest unit of information is the bit.

The early stages of the internet promoted the efficient, sustainable use of information due to the extremely low bandwidths available at the time. Content was succinct. Every bit mattered.

As connection speeds increased, however, so did the spread of redundant, unnecessary information. Examples: mash-ups, mash-ups, mash-ups, via trees, domain parking, hack writing, fluff, spin-offs. There is a theme here. The incredible number of internet users supports redundancy. And to some extent, redundancy is necessary. Imagine every person who ever viewed the Dancing Baby video (remember that?) loading it from the same server. The more adaptive model that has evolved is this: once a particular destination (page, article, media object) reaches a critical number of hits, other sites naturally want to share the traffic; this process repeats until the trend fades.

Some types of redundancy are necessary strictly for structural reasons, like in a power grid. Other types of redundancy improve the original source by appending information or displaying it in a unique context, like in a curated gallery. But some types of redundancy detract from the original source - as in the parasitic examples above - and eventually dissuade that type of source from being generated. The goal of this blog, which will feature my work, thoughts, and tutorials, is to provide only the sustainable type of information.

I’m interested in the fields of interactive media arts, design, architecture, and to some extent, web design and development. The tutorials on this site will mostly revolve around my work in Processing, because it is the least documented of all the languages I program in, and is an easy and addictive way to get interested in electronic art.

Coming soon: Processing introduction, Primary classes, Voronoi diagrams, Icosahedral globe, The Game of Life, Trees made of letters…

Until then!

The article has

no responses yet

Written by Don

March 20th, 2008 at 1:03 pm