COLL 142 - Week 01

User Interfaces in Processing

Salvatore "Sal" Testa /@saltesta14

What is Processing?

How do basic sketches work?

Two main parts


void setup() 
{
  // called at the beginning
}

void draw() 
{
  // run every refresh
  // default 60 frames per second
}
					

Set screen size


void setup() 
{
  size(400, 600); // width, height (pixels)
}
					

Draw something


void setup() 
{
  size(400, 600);
}

void draw() 
{
  fill(255, 0, 0); // make fill color red
  // centered at x, y and width, height
  ellipse(200, 200, 300, 300);
}
					

Draw order


void setup() 
{
  size(400, 600);
}

void draw() 
{
  fill(255, 0, 0);
  ellipse(200, 200, 300, 300);
  fill(0, 255, 0);
  // top left x,y and width, height
  rect(50, 250, 300, 300);
}
					

How can I animate this?

Draw a bunch!


void setup() 
{
  size(400, 600);
}

int y = 0;
void draw() 
{
  fill(255, 0, 0);
  ellipse(200, y, 300, 300);
  y = y + 1; // update the y component
}
					

Draw a bunch better!


void setup() 
{
  size(400, 600);
}

int y = 0;
void draw() 
{
  background(255); // white background
  fill(255, 0, 0);
  ellipse(200, y, 300, 300);
  y = y + 1;
}
					

How can I click things?

Click


void setup() {
  size(512, 512);  
}

void draw() {  
}

// special method, every mouse click
void mousePressed() {
  println("Mouse pressed at ("+mouseX+","+mouseY+")");
}
					

Click better


void setup() {
  size(512, 512);  
}

void draw() {
  fill(255, 0, 0);
  ellipse(256, 256, 100, 100);  
}

void mousePressed() {
  if (sq(mouseX-256)+sq(mouseY-256) < sq(50)) {
    println("Circle! :)");
  } else {
    println("Not circle! :(");
  }
}
					

How can I share this with my mom?

Export it!

Why am I having trouble with serial communication?

You didn't read the serial communication configuration documentation!

I don't blame you.

Without serial communication

With serial communication

Catch it?!

Try it out with "Dimmer"

What are we doing today?

Goal

Make a UI with at least 4 click-able events/objects. Examples:

  • the cow goes...
  • body anatomy
  • this is a circle

Bonus Goal

Make an LED light switch with a UI using serial communication.

Begin!