Recitation 10: Object Oriented Programming Workshop —— Leah Bian

 For this recitation, we first had a quick workshop about the map() function. I reviewed when to use this function, and what the formats are. After this workshop finished, we were asked to choose a workshop to attend. The choices included media manipulation, serial communication, and object oriented programming. In our final project, we will focus on how to send data between Arduino and Processing, and how to draw and control the image of the marionette in Processing. Therefore, my partner attended the workshop about serial communication, and I chose the workshop about object oriented programming.

   In the workshop, Tristan gave us a detailed explanation about what “object” means, and what the parts of it are, which include class and instance. We thus went over the process of writing codes of object oriented programming from bigger parts (class, instance) to the smaller ones (variables, constructor, functions). Using the emoji faces as example, we started to work on the code together. Based on the code that we wrote during recitation, I started to create my own animation as exercise.

We needed to use classes and objects, and the animation should include some level of interactivity. As requirements, we needed to use the map() function and an ArrayList. I decided to use the mousePressed function as way of interaction. The shapes would be created at the mouse’s position. After searching a basic function for a star online, I modified the code to meet the requirement of using arrays. Creating a star needs to use the vertex() function for ten times. I let the stars to fall down to the bottom of the screen by setting the yspeed to random(3,7). I wrote a bounce function, so that if the stars hit the boundaries on the left and the right they will turn to the opposite direction. Finally, I used the map() function to limit the area where the stars can be created.

These are my codes in Processing ( 2 parts):

ArrayList<Stars> stars = new ArrayList<Stars>();

void setup() {
  size(800, 600);
  noStroke();
}

void draw() {
  background(130,80,180);
  for (int i=0; i<stars.size(); i++) {
    Stars s = stars.get(i); 
    s.move();
    s.bounce();
    s.display();
  }
  float x=map(mouseX,0,width,width/6,width-width/6);
  float y=map(mouseY,0,height,height/6,height-height/6);
  if (mousePressed==true) {
    stars.add( new Stars(x,y));
  }
}

class Stars {
  float x, y, size;
  color clr;
  float xspeed, yspeed;

  Stars(float tempX, float tempY) {
    x = tempX;
    y = tempY;
    size = random(10, 100);
    clr = color(255, random(180,255), random(50,255));
    xspeed = random(-3, 3);
    yspeed = random(3, 7);
  }

  void display() {
    fill(clr);
   beginShape();
   vertex(x,y);
   vertex(x+14,y+30);
   vertex(x+47,y+35);
   vertex(x+23,y+57);
   vertex(x+29,y+90);
   vertex(x,y+75);
   vertex(x-29,y+90);
   vertex(x-23,y+57);
   vertex(x-47,y+35);
   vertex(x-14,y+30);
    endShape(CLOSE);
  }

  void move() {
    x += xspeed;
    y += yspeed;
  }

  void bounce() {
    if (x < 0) {
      xspeed = -xspeed;
    } else if (x > width) {
      xspeed = -xspeed;
    }
}
}

Recitation 10 by Christina Bowllan

For this week’s recitation class, we were tasked with creating a “knock-off” music video using images and videos, so I decided to create Rebecca Black’s “Friday” music video! First, I uploaded an image of a few girls riding around in a car. In order to do this, I used the variable “PImage” and put the photo code into void setup because I wanted the image to play one time. Next, I downloaded a video from the internet of a girl riding around in a car. In order to put this in processing, I imported the movie from my library and then put the movie processing code into void draw to to play the video. Then, since I wanted to play the image and then the video, I put in this code “if (millis()/1000 > 5)” which allowed me to telling processing that after 5 seconds, I wanted the image to end and start the video. Lastly, I talked to Marcela and she helped me insert music as well. I downloaded a simple sound code, and then downloaded the “Friday” song. I used boolean so that when the song plays, it will not be affected by the image and video changing as well; At first, when we didn’t have boolean, the song would repeat itself after 5 seconds because of the “millis” or time code.

import processing.video.*;
import processing.sound.*;
Movie myMovie;
SoundFile soundfile;
PImage photo;
boolean isPlaying=false;//this helps us so that the song won't restart with the millis starting over



void setup () {
  size (550, 380);
  background(255);
  photo =  loadImage ("download.jpg");
  //Rebecca Black - Friday.mp3
  image (photo, 100, 100);
  myMovie = new Movie (this, "friday.mp4");
  soundfile = new SoundFile(this, "Friday3.mp3");
}

void draw () {

  if (myMovie.available ()) {
    myMovie.read ();
  }

  if (millis()/1000 > 5) {
    //println(millis()/1000);
    background(255);
    myMovie.loop();
    myMovie.volume(0);
    image (myMovie, 0, 0);
    if (isPlaying ==  false) {
      playSong();//if it's not playing, then it'll play
    }
  }
}

void playSong() {
  isPlaying=true;  //this will make it play through one time 
  soundfile.play();
}

VIDEO:IMG_0299 2

Recitation 10: Object Oriented Programming workshop Cathy Wang

In our final project, we plan to create a moving object which will be controlled by the movement of the balance board. Therefore, we choose the object workshop to better know how to create an object in processing. We managed to control where objects appear and when to remove them by using “mousePressed” and “keyPressed”. Based on this, we will try to control the object with the sensor and a specific tool we make.

//float x;
//Emoji e;
//Emoji f;
ArrayList<Emoji> emojiList;

void setup() {
  size(1600, 900);
  emojiList=new ArrayList<Emoji>();
  //for (int i=0; i<10; i++) {
  //  emojiList.add(new Emoji(random(width/2), random(height/2), color(random(255), random(255), random(255))));
  //}
  //e= new Emoji(width/2,height/2,color(random(255),random(255),random(255)));
  //f=new Emoji(width/3,height/3,color(random(255),random(255),random(255)));
}

void draw() {
  background(255);
  fill(200);
  for (int i=0; i< emojiList.size(); i++) {
    Emoji e = emojiList.get(i);
    e.display();// same as emojiList[i]
    e.move();
  }
  //e.display();
  // f.display();
}



void mousePressed() {
  float x= map(mouseX, 0, width, width/8, width/2);
  float y= map(mouseX, 0, width, width/8, width/2);
  
  emojiList.add(new Emoji(x, y, color(random(255), random(255), random(255))));
}

void keyPressed() {

    emojiList.remove(emojiList.size()-1);
  
  
}

class Emoji {
  float x, y;
  float size;
  color clr;
  String type;
  float spdX;
  float spdY;
  //type="simley-face";
  //  if(type == "")//never give things value at the top.  
  Emoji(float startingX, float startingY, color startingColor) {
    x=startingX;
    y=startingY;
    size=random(50, 100);
    clr=startingColor;
    spdX= random(-5,5);
    spdY= random(-5,5);
}
  void display() {
    fill(clr);
    ellipse(x, y, size, size);
    fill(255);
    //size=random(50,100);
    ellipse(x-size/4, y-size/6, size/4, size/2);
    ellipse(x+size/4, y-size/6, size/4, size/2);
  }
  void move(){
    x= x+spdX;
    y= y+spdY;
  }
}

Recitation 10: Workshops – Sagar Risal

Materials: 

Arduino Kit 

Processing

Documentation: 

I chose to do the serial communication workshop in this recitation, where we reviewed serial communication between Arduino and Processing as well as learned how to use maps in our code, and what are some of the benefits of it. Serial communication will be a big part of my project, since I need to be able to have Arduino speak to Processing, as well as have Processing speak to Arduino, which is why I thought it would be a good idea to review this information. Map seemed to be a very useful function, but I don’t think it would be that useful for my specific project, we went over how it could be used in different ways but none of them matched up in the way in which I could use it for my own project, but it was still a good way to see how maybe I could put into my project and test out different elements in what I want to do. 

Recitation 10: Workshops by Kat Van Sligtenhorst

For this recitation, we were instructed to pick a TV show or music video and recreate it in Processing by manipulating images and clips we found online. I chose The Office theme song. First, I needed to download it as an mp4, load it into the sketch, and set it to play on a loop. Then, to make it a little more fun, I changed the speed of the video so it would play three times as fast. I also used the pixel manipulation techniques that we learned in order to pixelate the video. Lastly, because we had to incorporate the map() function, I added three ellipses along the left-hand side that responded to the movements of the mouse. They are meant to give the video the impression of having been cut out with a three-hole punch, since the TV show is about a paper company.

Here is my code for Processing:

import processing.video.*;

Movie myMovie;
void setup() {
size(480, 480);
myMovie = new Movie(this, “officeIntro.mp4”);
myMovie.play();
myMovie.speed(3.0);
myMovie.loop();
}
void draw() {
if (myMovie.available()) {
myMovie.read();
}

if ( myMovie.available() ) {
myMovie.read();
myMovie.loadPixels();
}
int rectSize = 5;
int w = myMovie.width;
int h = myMovie.height;
for (int y = 0; y < h; y+=rectSize) {
for (int x = 0; x < w; x+=rectSize) {
int i = x + y * w;
fill( myMovie.pixels[i] );
rect(x, y, rectSize, rectSize);
}
}
myMovie.updatePixels();

tint(255, 50);
image(myMovie, 0, 0);

float x1 = map(mouseX, 0, width, 50, 150);
ellipse(x1, 30, 50, 50);

float x2 = map(mouseX, 0, width, 50, 150);
ellipse(x2, 130, 50, 50);

float x3 = map(mouseX, 0, width, 50, 150);
ellipse(x3, 230, 50, 50);
}

Here is the finished product:

theOffice (1)

Credits:

https://www.youtube.com/watch?v=0GXjAMnv1zs