Meeting 16: Week 8, Long day (Thursday April 2 2:40 – 5:20)

Introduction to Object Oriented Programming (OOP)

Work through this example

Arrays

An introduction to (or review of) arrays, and an example incorporating various concepts that you might run into as you study examples found on the web

float[] coswave; 

void setup() {
  size(180, 360);
  coswave = new float[width];
  for (int i = 0; i < width; i++) {
    float amount = map(i, 0, width, 0, 90);
    coswave[i] = abs(cos(radians(amount)));
    println("cosine of angle " + amount + " is " + coswave[i]);
  }
  background(255);
  noLoop();
}

void draw() {

  int y1 = 0;
  int y2 = height/3;
  for (int i = 0; i < width; i++) {
    //stroke(coswave[i]*255);
    float foo = map(coswave[i], 0, 1, 0, 255);
    stroke(foo);
    line(i, y1, i, y2);
  }
}

File -> Examples -> Basics -> Arrays

Time Permitting

Who wants me to review your assignment from Tuesday?

Text

PFont f;
color red;
float x, y;

String message= "Important message";

void setup() {
  size(640, 360);

  f = createFont("Monaco", 32);
  textFont(f, 32);
  red=color(255, 0, 0);

  x=width/2;
  y=height/2;

  fill(red);
  textAlign(LEFT);
  text(message, x, y);
}

PFont f;
color red;
float x,y;

String message= "Alternative FACTS...";

void setup(){
  size(640,360);
  f = createFont("Monaco", 32);
  textFont(f,32);
  red=color(255,0,0);
  x=width;
  y=height/2;
}

void draw(){
  background(255); 
  //color
  fill(red);
  textAlign(LEFT);
  text(message,x,y);
  x-=2;
  if (x<0-textWidth(message))
    x=width;
  //for (int i=0; i<message.length(); i++){
  //  char c = message.charAt(i);
  //  float letterX=x+textWidth(c)*(i-1);
  //  text(c,letterX+random(-3,3),y+random(-3,3));
  //}
}

Homework due Tuesday April 7

Create either an artwork or a game using Object Oriented Programming. Pay attention to the structure, clarity, and organization of your program. As always, document your project:

  • make up forCreate a new folder (April7) on your Github repository 
  • Your code should be excellent!
    • Functions to group things together 
    • Comments to explain what’s going on
    • Excellent names for variables and functions
    • etc.
  • Upload code and image
  • Create a README.md 
    • Overall concept of your game or artwork
    • Image or link to video
    • Any confusing or tricky parts of your code
    • Any problems you ran into

Announcements

  1. We have received updated directives which prevent us from distributing your kits to you, out of concern for your health. As a result, the rest of the semester, and the final project, will be based on Processing. I will add some new material to take place of the material we will not be able to cover.
  2. From now on, I will limit the student lead discussions to 20 minutes. You should plan on getting through the material that you have prepared for discussion in about 15 minutes, leaving the last 5 minutes for general questions and discussion.