Recitation 10: Media Controller by Kaycee

For this recitation, I intended to utilize the camera and pixel function that I learned in class and the infrared distance sensor to make a device, which can change the resolution of the camera by changing the distance that the infrared sensor senses.

I met some challenges in coding this program. The range of the infrared distance sensor that I used was 20 cm to 150 cm. In the first trial, I set the beginning number of the mapped range as 0 and it turned out that there was an error in the code. When I pressed the run button, only black canvas showed on my screen. Therefore, I changed the beginning range from 0 to 1 and this made the camera interface appeared on the canvas. The interface of the camera appeared unclear at first, after strengthening each connecting part,  the device finally produced the effect I wanted. When the user came close to the infrared sensor, the ellipse on the interface would become smaller, producing the effect that the camera became clearer. And when the distance that the sensor got became larger, the radius of the ellipse would increase which made the camera vague again.

After finish reading “Computer Vision for Artist and Designers”, I contemplated more about the “algorithm communication”. This is exactly how those brilliant works that made by computers come from. I also used this technology in my project. In fact, the code that I have written until now can all be concluded as algorithm communication, since they all rely on simple codes to produce complicated effects.

Code:

Processing

// IMA NYU Shanghai
// Interaction Lab
// This code receives one value from Arduino to Processing

import processing.serial.*;
import processing.video.*;
Capture cam;
int Size = 10;

Serial myPort;
int valueFromArduino;
int PORT_INDEX=5;

void setup() {
size(640, 480);
cam = new Capture (this, 640, 480);
cam.start();

printArray(Serial.list());
// this prints out the list of all available serial ports on your computer.

myPort = new Serial(this, Serial.list()[ PORT_INDEX ], 9600);
// WARNING!
// You will definitely get an error here.
// Change the PORT_INDEX to 0 and try running it again.
// And then, check the list of the ports,
// find the port “/dev/cu.usbmodem—-” or “/dev/tty.usbmodem—-”
// and replace PORT_INDEX above with the index number of the port.
}

void draw() {
if (cam.available()) {
cam.read();
cam.loadPixels();
}
while ( myPort.available() > 0) {
valueFromArduino = myPort.read();
}
int a = int(map (valueFromArduino,200,1500,1,10));
for (int y=0; y<cam.height; y+=a) {
for (int x=0; x<cam.width; x+=a) {
int i= y*cam.width+x;
fill( cam.pixels[i] );
noStroke();
ellipse(x, y, a, a);
}
}
//image(cam,0,0,width,height);
cam.updatePixels();

// to read the value from the Arduino

println(valueFromArduino);//This prints out the values from Arduino
}

Arduino

// IMA NYU Shanghai
// Interaction Lab
// This code sends one value from Arduino to Processing

void setup() {
Serial.begin(9600);
pinMode(pin, INPUT);
}

void loop() {
Serial.write(sensorValue);
uint16_t sensorValue = analogRead (pin);
double distance = get_IR (sensorValue);
Serial.println (sensorValue);
Serial.println (” cm”);
Serial.println ();
delay (500);
delay(10);
double get_IR (uint16_t sensorValue) {
if (sensorValue < 16) sensorValue = 16;
return 2076.0 / (sensorValue – 11.0);
}

Recitation 11: Workshops on Object Oriented Programming by Kaycee

For this recitation, I chose Object-Oriented Programming workshop because I will do a game as my final project and this workshop could benefit me the most in my opinion.

Based on what I learned in the class on Thursday, I made some improvements and interaction function to the code.

I changed the interaction form with the mouse from producing more balls to make the balls disappear. Since two kinds of interaction were impossible to perform at the same time, so I deleted the original code and set the number of the balls in the setup loop as 20. In my first trial, I directly put an “if” function, saying that the ball which the mouse clicked on would disappear. However, my alternation didn’t work since the program couldn’t recognize the radius of each different ball. And I realized that to eventually achieve my purpose, another attribute was also needed in the Balls function to represent its radius. And when the position where the mouse clicks falls in the area that is within the radius of that circle, the circle would disappear.

I added the interaction with the keyboard in order to make it more interactive. Since I kept the part of the code of bounce, the balls would still move in the adverse direction when touching the rim of the canvas. Addition to that, users could also control the movement of the balls by clicking on the direction keys. However, when I pressed one of the direction keys, although all the balls will generally move in the intended direction, some balls will ignore the bounce code and disappear at the rim of the canvas. And I wondered why this would happen.

Code:

ArrayList<Ball> balls = new ArrayList<Ball>();

void setup() {
size(500, 600);
noStroke();
balls = new ArrayList<Ball>();
for (int i=0; i<20; i++) {
balls.add(new Ball(width/2, height/2, random(30,75)));
}

}
void draw() {
background(255);
for (int i=0; i<balls.size(); i++) {
Ball b = balls.get(i);
b.move();
b.bounce();
b.display();
if (key==CODED) {
if (keyCode==UP) {
b.y–;
}
if (keyCode==DOWN) {
b.y++;
}
if (keyCode==LEFT) {
b.x–;
}
if (keyCode==DOWN) {
b.x++;
}
}
}
if (mousePressed) {
for (int i=0; i<balls.size(); i++) {
Ball b = balls.get(i);
float diameter=b.w;
float dx = abs(mouseX-b.x);
float dy = abs(mouseX-b.y);
float distance= sqrt(sq(dx)+sq(dy));
if (distance<= diameter) {
balls.remove(i);
}
}
}
}

ArrayList<Ball> balls = new ArrayList<Ball>();

void setup() {
size(500, 600);
noStroke();
balls = new ArrayList<Ball>();
for (int i=0; i<20; i++) {
balls.add(new Ball(width/2, height/2, random(30,75)));
}

}
void draw() {
background(255);
for (int i=0; i<balls.size(); i++) {
Ball b = balls.get(i);
b.move();
b.bounce();
b.display();
if (key==CODED) {
if (keyCode==UP) {
b.y–;
}
if (keyCode==DOWN) {
b.y++;
}
if (keyCode==LEFT) {
b.x–;
}
if (keyCode==DOWN) {
b.x++;
}
}
}
if (mousePressed) {
for (int i=0; i<balls.size(); i++) {
Ball b = balls.get(i);
float diameter=b.w;
float dx = abs(mouseX-b.x);
float dy = abs(mouseX-b.y);
float distance= sqrt(sq(dx)+sq(dy));
if (distance<= diameter) {
balls.remove(i);
}
}
}
}

Recitation 11: Workshops by Jennifer Cheung

In this recitation, I attended the Object Oriented Programming workshop taught by Tristan. We learned how to organize our code to better control many objects. We followed his code to create a couple of “people” made of ellipses and strokes to move when their head was clicked. By using OOP, we were able to create many different versions of the people with a few lines of code. 

I altered the example code by having the people interchange between moving horizontally and vertically when their heads were clicked. Katie helped me achieve this by showing me how to use the % syntax, so that when the divided remainder was even, the people would move vertically, and when the remainder was odd, they would move horizontally. 

Overall code

Object Code

Recitation 11: Workshop on Media Manipulation by Malika Wang

During this week’s recitation, I focused on realizing the design for my final project with Nathan. We want to create an effect of revealing a photo by rolling the ball across certain paths. To do that, we need to create a PGraphics that layers upon the camera image. Eric taught me how to draw a PGraphics. 

However, when I tried it on my own later during the weekend, I found that once a PGraphics is drawn, it cannot be modified. I still can’t make happen the effect that Nathan and I wanted. So we decided to use a static photo as background. But what I learnt from this recitation was exciting. Even though I probably won’t use it for my final project, I believe it may come of use someday.

Below is my code.

 

Recitation 11: Workshops (Media Manipulation) by Jonathan Lin

My partner, Jennifer Cheung, and I went to two different workshops. She went to Object-Oriented Programming with Tristian, while I learned Media Manipulation with Leon. This workshop was very informational on how to manipulate photos and videos and for my exercise, I decided to create a collision between two objects.  I did this by detecting the colors, so for example, if my red object touches a blue object the code tells it to move away. My final project is a maze so learning this will be very important in my final project.

Below I show what the collision looks like. There are still a few problems like the object does not collide from the other side, and that it moves up when you push into it. These are things that will be figured out for our final project.

Code: