Creative Code at Brilliant Summer

Links and Resources

OpenProcessing - A free on-line space where you can upload/view/share your own Processing programs, and see ones by others.

Brilliant Summer on OpenProcessing - Our on-line "classroom". We can collect all of our programs here to share on Parent Night.

Download Processing - Processing is free, and works on Macs, PCs, and Linux computers. You can download it here to keep working on things after camp is over.

Processing Language Reference - All of the commands in Processing, explained. Go here if you forget how to use a command, or if there's a new thing you want to try.

Examples of Digital Artworks

Text Rain - Camille Utterback & Romy Achituv
New Year's Cards - Golan Levin (made in Processing)
MIT Media Lab Logo - L Roon Kang & The Gren Eyl (made in Processing)
Anymails - Carolin Horn
Dreamlines - Leonardo Solaas (made in Processing)
We Feel Fine - Jonathan Harris and Sep Kamvar (made in Processing)
Messa Di Voce - Golan Levin (made in Processing)
Exploding Bodies - Eric Tse (made in Processing)
Processing Monsters - Various (made in Processing)

Project 1: Make a Portrait Using Code

Reference for code for drawing different shapes in Processing:
http://cmuems.com/2013/b/static-drawing/
Code template:
size(500, 400); //sets the size for the window
rect(150, 300, 200, 100); //draws a rectangle
ellipse(250, 200, 150, 200); //draws an ellipse
Examples:

Click to view code

Click to view code

Click to view code

Click to view code

Project 2: Make a Weird 'Drawing' Program

Part I: Playing with Interactivity
Code template:
void setup() {
  size(500, 400);
  background(10, 80, 100);
}

void draw() {
  stroke(255, 255, 255);
  fill(160, 220, 90);
  ellipse(mouseX, 200, 300, 300);

  fill(160, 210, 230);
  rect(245, mouseY, 10, 240);

  fill(255, 255, 255);
  ellipse(mouseX, mouseY, 70, 70);
}
Example:

Click to view code
Part II: Make a Painting Program
Code template:
void setup()
{
  size(500, 500);
  background(255);
  smooth();
}

  
void draw()
{
  if (mousePressed) {
    fill(0);
    noStroke();
    ellipse(mouseX, mouseY, 15, 15);
  }
}
 
Examples:

Click to view code

Click to view code
Use the numbers 1-6 to create awesome pictures and fun!
1: Beads
2: Lumber
3: Random-color balls
4: "Yo-yo" balls
5: ???
6: Fun with a yo-yo!
Space: Clear screen

Click to view code

Click to view code

Project 3: Make a Picture that Responds to Sound

These won't work online due to web security, but are really cool. Use your face from assignment 1 as the basis. If you finish early with it, try making a new, different image that uses sound in a different way.
Code template (non-moving face):
void setup() {
  size(500, 400); //sets the size for the window
  background(0, 200, 100);
}

void draw()
{
  background(0, 200, 100);
  rect(150, 300, 200, 100); //shoulders
  ellipse(250, 200, 150, 200); //face
  ellipse(300, 200, 20, 20); //eye
  ellipse(200, 200, 20, 20); //eye
  ellipse(250, 230, 20, 40); //nose
  line(200, 260, 250, 255);//mouth part 1
  line(250, 255, 300, 260);//mouth part 2
}
Code for 'helper file' MyAudioHandler.pde:
// Don't worry about understanding the stuff below!
import ddf.minim.*;
  
Minim minim;
AudioInput in;
float volume = 0;
float volumeF = 0;
  
//-------------------------------------
void setupAudio(){
  minim = new Minim(this);
  in = minim.getLineIn(Minim.MONO, 512);
}
  
//-------------------------------------
void getVolume(){
  volumeF = in.right.level()*1000;
  volume = 0.8*volume + 0.2*volumeF;
}
  
//-------------------------------------
void stop(){
  in.close();
  minim.stop();
  super.stop();
}

Project 4: Flocks of Objects

Examples:

     

Creating our Own Objects

Step 1 - Making a basic 'bouncer' object class:


// declare a new "Mover" object named "m1"
Mover m1 = new Mover(100, 100, 10); 

void setup(){ // Runs once at start
  size(640, 480); // Set screen size
  background(0); // Make background black
}


void draw(){ // Runs every frame
  background(0); // Cover all with black background
  m1.display(); // This calls the function in "m1" to draw it on the screen 
}

// Here is the code that sets up what a "Mover" is,
// what values (variables) it has, and what
// behaviors (functions) it has
class Mover {  
  //DATA: Here are the values we want every Mover to have 
  int x; // x position of the Mover
  int y; // y position of the Mover
  int speed; // Speed of the Mover

  //CONSTRUCTOR: This is the "constructor." It's a special function
  //that is used to make a new Mover. We called it at the top
  //of this program. You can put "arguments" in the cosntructor
  //to set variables when each new object is made.
  //So "new Mover(100, 100, 10);" sets x to 100, y to 100, speed to 10.
  Mover(int _x, int _y, int _speed) {
    x = _x;
    y = _y;
    speed = _speed;
  }

  //This is a function for actually drawing the mover on the screen.
  //It uses the x, y , and speed values to draw the mover in the right position.
  //It also includes code for the "bouncing" behavior  
  void display() {
    if(x<0 || x>width){ // If the Mover goes off the screen...
      speed = -1*speed; // Reverse the speed (multiply it by -1)
    }
    x = x+speed; // Add the 'speed' to the x value to make it move to another position.
    stroke(100, 50, 0); //Stroke color
    fill(200, 100, 0); //Fill color
    ellipse(x,y,13,13); //Draw the circle
  }

}

Step 2 - Making multiple 'Movers' (new code highlighted in yellow):

// declare 4 "Mover" objects
Mover m1 = new Mover(100, 100, 10);
Mover m2 = new Mover(110, 110, 5);
Mover m3 = new Mover(120, 120, 1);
Mover m4 = new Mover(130, 130, 7);

void setup(){ // Runs once at start
  size(640, 480); // Set screen size
  background(0); // Make background black
}

void draw(){// Runs every frame
  background(0); // Cover all with black background
  //Call the "display()" function in all the movers to draw them on screen
  m1.display();
  m2.display();
  m3.display();
  m4.display();
}

// Here is the code that sets up what a "Mover" is,
// what values (variables) it has, and what
// behaviors (functions) it has
class Mover {
  //DATA: Here are the values we want every Mover to have
  int x; // x position of the Mover
  int y; // y position of the Mover
  int speed; // Speed of the Mover

  //CONSTRUCTOR: This is the "constructor." It's a special function
  //that is used to make a new Mover. We called it at the top
  //of this program. You can put "arguments" in the cosntructor
  //to set variables when each new object is made.
  //So "new Mover(100, 100, 10);" sets x to 100, y to 100, speed to 10.
  Mover(int _x, int _y, int _speed) {
    x = _x;
    y = _y;
    speed = _speed;
  }

  //This is a function for actually drawing the mover on the screen.
  //It uses the x, y , and speed values to draw the mover in the right position.
  //It also includes code for the "bouncing" behavior  
  void display() {
    if(x<0 || x>width){ // If the Mover goes off the screen...
      speed = -1*speed; // Reverse the speed (multiply it by -1)
    }
    x = x+speed; // Add the 'speed' to the x value to make it move to another position.
    stroke(100, 50, 0); //Stroke color
    fill(200, 100, 0); //Fill color
    ellipse(x,y,13,13); //Draw the circle
  }

}

Step 3 - Using arrays and loops to make hundreds of objects (new code highlighted in yellow):


Mover[] m = new Mover[100]; // Creates an ARRAY of 100 Mover objects

void setup(){ // Runs once at start
  size(640, 480); // Set screen size
  background(0); // Make background black
  
  //This is a 'for' loop, which we can use to repeat code without typing it all
  //You give it variable with a starting value, a limit, and a change in
  //value which will happen each time it loops.
  //This 'for' loop starts when i=0, continues while i<100, and adds 1 to i each loop.
  //So it will run 100 times
  for (int i = 0; i < 100; i++)
  {
    //Every time this code loops, it creates a new 'Mover' in a slot in the array
    //In initialized the 'Mover' with random values for x, y ,and speed
    m[i] = new Mover(int(random(width)), int(random(height)), int(random(7)+1));
  }
}

void draw(){ //Runs every frame
  background(0); // Cover all with black background 
  
  //Another 'for' loop. This one calls 'display' for all the 'Movers' in
  //the array we made.
  for (int i = 0; i < 100; i++)
  {
    m[i].display();
  }
}

//The 'Mover' class is mostly the same, however we've added some new behaviors
//in the 'display' function
class Mover {

  int x;
  int y;
  int speed;

  Mover(int _x, int _y, int _speed) {
    x = _x;
    y = _y;
    speed = _speed;
  }

  void display() {
    if(x<0 || x>width){ //If Mover goes off screen, reverse direction
      speed *= -1;
    }
    
    if (abs(y-mouseY)<100 && abs(x-mouseX)<100) // If Mover is close to mouse, jump down
    {
      y += 10;
      if (y >= height){ //If object jumps off of bottom of screen, jump back to top
        y=1;
      }
    }
    
    x = x+speed;
    stroke(100, 50, 0);
    fill(200, 100, 0);
    ellipse(x,y,13,13);
  }

}

Step 4 - Adding different behaviors and variables to objects (new code highlighted in yellow):

//This code is mostly the same as the previous, but we've added
//other behaviors to the Mover class's display() function

Mover[] m1 = new Mover[100];

void setup(){
  size(640, 480);
  background(0);
  for (int i = 0; i < 100; i++)
  {
    m1[i] = new Mover(int(random(width)), int(random(height)), int(random(7)+1));
  }
}

void draw(){
  background(0);
  for (int i = 0; i < 100; i++)
  {
    m1[i].display();
  }
}

class Mover {

  int x;
  int y;
  int speed;
  int diameter = 13; // Added a new variable, 'diameter' to change size

  Mover(int _x, int _y, int _speed) {
    x = _x;
    y = _y;
    speed = _speed;
  }

  void display() {
    if(x<0 || x>width){ //If Mover goes off screen, reverse direction
      speed *= -1;
    }
    
    // If Mover is close to mouse, make its diameter increase
    if (abs(y-mouseY)<100 && abs(x-mouseX)<100)  
    {
      diameter +=1;
    }
    else{
      diameter = 13;
    }
    
    x = x + speed;
    stroke(100, 50, 0);
    // Random flicker fill
    fill(random(50, 255), random(50, 255), random(50, 255));
    ellipse(x,y,diameter,diameter);
  }

}