Classes & Instances of Dogs

To illustrate the difference between a class and an instance let’s take a look at applying the concept to dogs.

Class
A class is a definition for a collection of objects. For example, if we define a class for Dogs it would include all the characteristics common to all dogs.
The class is a template: it defines only the parameters these objects share, functions they can perform, and logic for how an object can be constructed. A class becomes an object only when you make an instance of it.

Let’s try to make a Dog Class

All Dogs have:

  • name
  • breed
  • hair
  • legs (usually 4)
  • head
  • tail (most of them)

All Dogs can:

  • bark
  • run
  • eat

Now let’s make a few instances of dogs
Instance 1: Pluto

  • name = Pluto
  • breed = Bloodhound
  • hair = short and light brown
  • legs = 4
  • head = large
  • tail = yes
  • bark = a lot
  • run = fast
  • eat = cheeseburgers

Object-Oriented Programming

In order to create Generative Art through the medium of code, we first need several new
tools. You will need to learn the basics of object-oriented programming (OOP). If you’re a seasoned programmer, you’re probably already familiar with this concept — very few languages above a certain power and sophistication don’t accommodate object-oriented structures.

OOP is just a small conceptual leap in how you think about coding. Rather than giving the machine the task of dealing with a linear progression of instructions, which is what you’ve done so far, you think in terms of creating objects in memory: self-contained data boxes that you can then use within the familiar linear programming style.

Generative Art

The term originated in a paper by Philip Galanter, artist and professor at Texas A&M University, he wrote “Generative art refers to any art practice where the artist uses a system, such as a set of natural language rules, a computer program, a machine, or other procedural invention, which is set into motion with some degree of autonomy contributing to or resulting in a completed work of art”.

To be even more specific, as Matt Pearson, author of the fabulous book “Generative Art” said “With generative art, the autonomous system does all the heavy lifting; the artist only provides the instructions to the system and the initial conditions. The artist’s role in the production process may be closer to that of a curator than a creator. You create a system, model it, nurture it, and refine it, but ultimately your ownership of the work produced may be no more than a parent’s pride in the work of their offspring.”

Additionally Clive Thompson outlines in his book “Smarter Than You Think” that there is a new hybrid model of collaboration where human and machine work together. Thompson describes how a new generation of chess players have emerged in the past decade that use simple laptop to do the difficult predictive analysis but use their human intuition to be far more effective than their human or computer opponents.

It is this hybrid approach that we’re aiming for in this Generative Art course, where an artist creates a set of instructions (a program) that will by itself or with some human interaction generate a number of different art pieces and the artist can choose the best that have been output.

Finally, as Pearson puts it “The artist creates ground rules and formulae, usually including random or semi-random elements, and then kicks off an autonomous process to create the artwork. The system can’t be entirely under the control of the artist, or the only generative element is the artist herself. The second hard-and-fast rule therefore is there must be a degree of unpredictability. It must be possible for the artist to be as surprised by the outcome as anyone else.”

To achieve Generative Art we’ll need to learn about Object Oriented Programming (OOP).

The While Loop

The ‘While’ structure is similar to an if statement, but there is an important difference. With an if statement, the code inside the curly braces will run 0 or 1 times (0 times if the condition is false, 1 time if the condition is true).

But with the while loop code can run many times, not only 0 or 1. It will keep running while the test condition is true. It is ideal to repeat some code many times.

In our example we use it to draw many circles. Just changing one value we can decide if we want 10 circles or 100. It’s important that something inside the while loop will make the condition false, otherwise the loop runs forever and can make our computer slow. Always check that the loop will run only as many times as you expect, not forever!

Review 1

The color() function is used to create a variable of the type color. This is handy if you need to create colors you can use anywhere in your sketch. In this example, I’ve declared a color variable named c, before the setup() function.

The fill() function is used to set the fill color of the shape you’re about to draw. It can be used with one to four parameters. You can also use a color variable for this.

The noFill() function is used to disable the fill before you draw a shape to the screen.

The stroke() is similar to the fill() function, but sets the color for the stroke of the shape you want to draw.

The noStroke() function is used to disable the stroke before you draw a shape to the screen.

The background() function is used to set the background color. This will usually be the first function you’ll use inside the draw() function, as it will clear the screen. You can’t use transparent colors with this function. If you do, the alpha value will be ignored.

The first parameter in colorMode() is used to set the color mode. This can be either RGB or HSB. The default color mode is RGB, with values between 0 and 255.

You can use colorMode( RGB, 1.0 ) to use values between 0 and 1 for the color
components. If you want to use HSB colors, you’ll usually use colorMode( HSB,
360, 100, 100 ), as these numbers are used in most graphics applications.

Introduction to Processing

Processing is a popular, very-high-level programming language that began at MIT in 2001. Originally developed by MIT Media Lab alums Casey Reas and Benjamin Fry—both artists and technology thinkers, Processing was intended to be a learning language, a tool to get non-programmers, particularly artists, hooked on code via the promise and delivery of immediate visual feedback.

If you’re interested in learning more about the history of Processing, here’s an interesting article about it.

Workshop Goals:

Explore the concepts and skills of creative coding

Throughout the workshop we’ll help you develop practical programming concepts and skills by exploring creative ideas and challenges. We’ll be looking at the history and philosophy behind artistic uses of technology, so you can gain a greater understanding of how best to express your own creative vision using the software you write.

The aim is to teach you “algorithmic thinking” – ways to conceptualize and model the world so you can express creative ideas using computer programs.