Week 6: Sharing Functions

This week, we play with other people’s functions, and we write functions that other people will play with.

In so doing, you will become acquainted with one of the most powerful aspects of Computational Media: the ease with which instructions can be bundled up and sent elsewhere… or, the ease with which you can incorporate other people’s instructions into your own code.

This characteristic has broad political, social and economic implications.



Think about the implications of

  1. Parts of your code being used in other people’s code
  2. Your code using other people’s code

Spend 15 minutes researching on the Internet, and establish what might be the political, social, economical implications of shared sets of instructions?

Step 1: Use someone else’s function

Start with a basic sketch such as the one below. In this sketch, a grid of 10 by 10 circles is drawn.

void setup(){

void draw(){
 for (int i = 20 ; i < 400 ; i = i + 40){
  for (int j = 20 ; j < 400 ; j = j + 40){
   ellipse(i,j, 30,30);

Now, copy and paste the below ‘function’ and call it instead of calling the ‘ellipse’ command above.

 * This function draws a target.
 * It takes 2 parameters (x and y) which define
 * the position of the target that is drawn.
 * x: the distance in pixels from the top left
 * y: the distance in pixels from the top right 
void drawTarget(float x, float y) {
  for (int i = 0; i < 50; i = i + 5) {
    if (i%2 == 0) { // this line says "if i is an even number then..." 
      fill(255);    // fill in white
    } else {        // otherwise
      fill(0);      // fill in black
    ellipse(x, y, 50 - i, 50 - i);

At first try to make something interesting with that function without changing it. Then, allow yourself to change it.

What do you notice about using someone else’s function?

  • is it easier / more difficult than writing your own?
  • what are the advantages?
  • what are the limitations?
  • would it be acceptable to you change the function and call it your own?
  • do you think it would be right to reference the original author of this function?

Step 2: Now roll your own.

Now, spend some time playing exploring what kinds of patterns might make an interesting function for others to use. You might want to go back and have a little bit of an explore of the early computer artists work.

Invent / design a function that results in the drawing of graphic primitives on the screen. Make sure that your function encapsulates some kind of visual idea.

Make sure that:

  1. You offer some parameters to the end user. You might offer:
    1. x and y locations (or i and j in the above example),
    2. colour choices,
    3. size choices,
    4. size of random variation,
    5. etc.
  2. You document what the code does (in clearly written english) what the function does,
  3. Your function encompasses a clear visual idea.

Step 3: Upload your code to a code-sharing website

  1. Upload your code to https://gist.github.com/
    1. make sure that you choose the right syntax highlighting (by giving a filename that ends with .java)
  2. Copy the URL of your code
  3. Post the URL of your code as a comment on this webpage.

Step 4: Grab two other people’s code

  1. Go to the medadada function sharing blog post
  2. Grab 2 other people’s functions (copy paste into your own Processing sketch)

Step 5: Make an artwork (using other people’s functions), and post it to your blog.

Now that you have all the code in your sketch, you can explore the functions. Make an artwork that uses these functions in your own way. Try to avoid changing the function (just for the sake of this exercise).

Step 6: Modify downloaded code, then make another artwork, and post it to your blog.

Step 7: Analysis

Analyse how others have used your work, and comment on the following:

  1. Was your ‘visual idea’ used as you had anticipated?
  2. Do you think the user has improved or reduced your graphic vision?
  3. etc.

One thought on “Week 6: Sharing Functions

Leave a Reply

Your email address will not be published. Required fields are marked *