ICM_4_PatchBallsFlies

Here’s the combination of what I’ve learned so far from Learning Processing and The Nature of Code. I call it “Patch. Balls. and Flies”. It’s kind of messy but I’m glad all the interactions with each others work! Yah! Check it out(click click )!

Functions:
1) move patch to stop bouncing balls
2) press mouse to drag balls with patch
3) long-press keyboard to see flies clubbing!! B-)   (surprisingly fit this perfectly, the most EXCITING part, DANCING time!!)
4) let go keyboard(== keyReleased) to calm down the flies, and gather all the balls within the patch

(Forgive me the awful screen pics, can’t screenshot since this one involve functions of KEY.)

bouncing

clubbing_flies

reset

Here’s some struggles I’ve been through:

  1. when dragging balls, I calculated the distance with patch and ball, and then planed to add this fixed distance to the position of patch and set it as the position of balls. But since I wrote this code in void mouseDragged(), I recalculated the distance every time I dragged and that caused flickering. Thanks to the office hour w/ Daniel Shiffman, this calculation codes were moved into void mousePressed() and it worked!!! (tearing)
  2. same stupid things happened when I want to bump flies with balls: I forgot to set conditions and thus make flies be affected by every balls!
  3. Things getting complicated when I want to make the music band. In the end I successfully saved the original color, and changed the color once it’s been hit(hitGround == true &&  cubes.x < ball.x <cubes.x+w  && ball.y < (height-h)), and then restored the colors back later.

And codes time!

Continue reading

PComp_4_MusicInstrument

In PComp class Billy and I make a Music Instrument that can adjust the pitch by pressing and tapping. Check this out!

 

#include "pitches.h"

int lastButtonState = LOW;
boolean switchIsOn = false;

const int threshold = 10;
const int speakerPinNum = 8;
const int noteDuration = 20;

const int potenPinNum = 5;
int volumeAnalogValue = 0;
int volume = 0;

const int potPinNum = 2;
float saveNote;

int note[] = {
  NOTE_C4, NOTE_E4};

void setup() {
  Serial.begin(9600);
  saveNote = note[1];

}

void loop() {

  int buttonState = digitalRead(2);

  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      switchIsOn = !switchIsOn;
    }
  }

  lastButtonState = buttonState;

  if (switchIsOn == true) {

    int pitchRead = analogRead(0);
    int noteRead = analogRead(1);

    float pitch = map(pitchRead, 0, 950, 0, 100);

    if (pitch > 0) {
      note[1] += pitch;
    } 
    else {
      note[1] = saveNote;
    }

    Serial.print(pitch);
    Serial.print(" ");
    Serial.println(noteRead);

    if(noteRead > threshold) {
      tone(speakerPinNum, note[1], noteDuration);
    } 
  }
}

As for my review for this on Sunday, I made a basic music kit that you can control on/off, volumes, pitches(higher/lower), and tempo. But since it’s a single-note playing machine instead of templates/clip of music triggered one, it makes no difference with the changes of tempo.

MusicPractive

And thanks to almighty Moon! I got the idea of setting button-“released” as the command to adjust pitches, so that pitches won’t go crazy because of the unmeasurable amount/time of button-“pressed” when you press the button. Thank you Moon 😀

What I want to do next–

  1. make chords (office hour w/ resident booked!)
  2. play continuous clips instead of single notes
  3. be creative! not just pressing buttons… not interesting at all… go go go!

And here’s the code.

#include "pitches.h"

int lastButtonState = LOW;
boolean switchIsOn = false;

const int threshold = 600;
const int speakerPinNum = 8;
const int switchPinNum = 2;
const int higherPitchPinNum = 4;
const int lowerPitchPinNum = 3;

int pre_higherPitchRead = 0;
int pre_lowerPitchRead = 0;

const int tempoPinNum = 0;
const int noteGPinNum = 1;
const int noteEPinNum = 2;
const int noteCPinNum = 3;

const int noteDuration = 20;

int saveNote[3];
int note[] = {NOTE_C4, NOTE_E4, NOTE_G4};

void setup() {
  Serial.begin(9600);

  // save the original notes
  for (int i=0; i<3; i++) {
    saveNote[i] = note[i];
  }
}

void loop() {

  // on-off switch setting
  int buttonState = digitalRead(switchPinNum);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      switchIsOn = !switchIsOn;
    }
  }
  lastButtonState = buttonState;

  // read different notes
  int noteCRead = analogRead(noteCPinNum);
  int noteERead = analogRead(noteEPinNum);
  int noteGRead = analogRead(noteGPinNum);

  // set up duration of notes
  int tempoRead = analogRead(tempoPinNum);
  int tempo = map(tempoRead, 0, 1023, 5, 100);

  // press buttons to make notes go higher/lower 
  int higherPitchRead = digitalRead(higherPitchPinNum);
  int lowerPitchRead = digitalRead(lowerPitchPinNum);

  // when switch is on
  if (switchIsOn == true) {

    Serial.print(tempo);
    Serial.print("  ");

    // make notes go higher or lower
    for (int i=0; i<3; i++) {
      if (higherPitchRead == LOW && pre_higherPitchRead == HIGH) {
        note[i] *= 2;
      }
     if (lowerPitchRead == LOW && pre_lowerPitchRead == HIGH) {
        note[i] /= 2;
      }
      note[0] = constrain(note[0], 32, 4192);
      note[1] = constrain(note[1], 41, 5280);
      note[2] = constrain(note[2], 49, 6272);
    }

    // make sounds!
    if(noteCRead < threshold && noteERead < threshold && noteGRead < threshold) {
      for (int i=0; i<3; i++) {
        tone(speakerPinNum, note[i], tempo);
      }
    } else if(noteCRead < threshold && noteERead < threshold) {
      tone(speakerPinNum, note[0], tempo);
      tone(speakerPinNum, note[1], tempo);
    } else if(noteCRead < threshold && noteGRead < threshold) {
      tone(speakerPinNum, note[0], tempo);
      tone(speakerPinNum, note[2], tempo);
    } else if(noteGRead < threshold && noteERead < threshold) {
      tone(speakerPinNum, note[2], tempo);
      tone(speakerPinNum, note[3], tempo);
    } else if(noteCRead < threshold) {
      tone(speakerPinNum, note[0], tempo);
    } else if(noteERead < threshold) {
      tone(speakerPinNum, note[1], tempo);
    } else if(noteGRead < threshold) {
      tone(speakerPinNum, note[2], tempo);
    }

    Serial.print(note[0]);
    Serial.print(" ");
    Serial.print(note[1]);
    Serial.print(" ");
    Serial.print(note[2]);
    Serial.print(" ");
    Serial.println(" ");

  } else {
    for (int i=0; i<3; i++) {      // when swtich-off
      note[i] = saveNote[i];       // restore the original notes
    }
  }

  // remember the previouse higher/lower pitch buttons status
  pre_higherPitchRead = higherPitchRead;
  pre_lowerPitchRead = lowerPitchRead;
}

V&S_3_Reading_TheMachineStops

There’s an old Chinese saying– “Water can carry a boat; it can sink a boat”, and I think it can also describes technology perfectly. There’s no black-and-white judgement for technology, and in my opinion any innovation is neutral. It is human that makes the difference. For example, text message can be an excuse to avoid talking to someone(causing isolation), but at the same time it’s efficient to send quick and clear information(saving time). It all depends on how human use it.

But, I don’t mean that inventors don’t need to be aware of their doings. At least not in the vicious way. Inventors cannot control the usage of their invention by others, but at least they should, or try, to hold an intention to make this world better. Villains are not welcome to this world, sorry.

inspiration_Nick Yulamn

Acoustic Drum Machine_Nick Yulman(( click me to see magic ))

Reading through the reading of PComp and found this ITP alum guy doing amazing stuff with servomotor and solenoid to make an elegant drum set! So artistic done with small drum from Borneo and snail shells! That’s exactly what I want to do, delicate stuff with low-fi appearing. Simply blown my mind. And this work was done in ITP during 2010 I guess.

UNBELIEVABLE.

Inspired at the same time. Thank you(who?) so much to let me become part of ITP. Thank you(who?).

PComp_3_SuperMarioTime

During the PComp Lab_03, although as struggling as usual, I found it very enjoyable to make the speaker speak! Such a lovely moment, probably as exciting as finding the existence of fire. And I even made a short Super Mario music, sweet!

PComp_Lab_MarioTime! from JHCLaura on Vimeo.

But I found it really difficult, when me and Billy tried to adjust the volume of speaker and also to make chords(two tunes speak at the same time).

For the volume

#include "pitches.h"

int lastButtonState = LOW;
boolean switchIsOn = false;

const int threshold = 10;
const int speakerPinNum = 8;
const int noteDuration = 20;

const int potenPinNum = 5;
int volumeAnalogValue = 0;
int volume = 0;

int note[] = {NOTE_C4, NOTE_E4, NOTE_G4};

void setup() {
  Serial.begin(9600);
}

void loop() {

  int buttonState = digitalRead(2);
  volumeAnalogValue = analogRead(potenPinNum);

  volume = map(volumeAnalogValue, 0, 1023, 0, 490);
  Serial.println(volume);

  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      switchIsOn = !switchIsOn;
    }
  }

  lastButtonState = buttonState;

  if (switchIsOn == true) {

    analogWrite(speakerPinNum, volume);
    Serial.println(volume);

    for (int i=0; i<2; i++) {
      int noteRead = analogRead(i);

      if(noteRead > threshold) {
        tone(speakerPinNum, note[i], noteDuration);
      }
    }
  }
}

My original idea was

  1. connecting speaker to digital pin #8, and potentiometer to analog pin #A5
  2. mapping the analogInput from  0~1023 to 0~490, setting it as volume
  3. analogWrite it into pin #8

But it failed  :/

Luckily, I bumped into my 2nd year buddy Andy and bothered him a couple of minutes and his advice simply blown my mind. He suggested using the potentiometer directly between digital pin #8 and the speaker, and adjust it directly without writing any codes! Wow. How I’ve never thought about this? And it worked! It simply proved that I’ve not thought it through totally. Hmmmm so much work to do, fighting 🙂

VolumeAdjust

New codes!

#include "pitches.h"

int lastButtonState = LOW;
boolean switchIsOn = false;

const int threshold = 10;
const int speakerPinNum = 8;
const int noteDuration = 20;

const int potenPinNum = 5;
int volumeAnalogValue = 0;
int volume = 0;

int note[] = {
  NOTE_C4, NOTE_E4, NOTE_G4};

void setup() {
  Serial.begin(9600);

}

void loop() {

  int buttonState = digitalRead(2);
  volumeAnalogValue = analogRead(potenPinNum);

  volume = map(volumeAnalogValue, 0, 1023, 0, 490);
  Serial.println(volume);

  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      switchIsOn = !switchIsOn;
    }
  }

  lastButtonState = buttonState;

  if (switchIsOn == true) {

    for (int i=0; i<2; i++) {
      int noteRead = analogRead(i);
      Serial.println(noteRead);
      if(noteRead > threshold) {
        tone(speakerPinNum, note[i], noteDuration);
      }
    }
  }
}

ICM_3_RainMan & Triangles

Time flies and here I am sweet ICM homework #3. It’s a collaboration work by Karam and I, and basically we just used each other’s class and try to make some interaction! I got the triangle class from Karam and background idea from Gladys, and this work was inspired by reading The Nature of Code of Daniel Shiffman. Just finished chapter 1. Super good/tough stuff!!

   

Here’s my new born baby(click me click me)! It’s about a person who loves being rained, just enjoys the feeling of being miserable. When rain stops, the smile stops and background went blue. You can click your mouse and make this guy happy again.

For this, I wrote 5 classes… just couldn’t stop, and hit into wall sooo many time. I was like a small rooted tree in the corner of ITP floor on Monday. And here’s are some problems(all about using class in class) and answers(except the last one) from try-and-error process of myself.

  • Where to put the moving code?
    • make sure you can control the position in the { } in which the leading moving codes(e.g. x++) settle
  • If things moves in different way?
    • put moving codes separately in its own class
  • Wants rains start from cloud
    • don’t need to declare Cloud class in Rain class!! can use it directly(tearing)
  • How to make smile affected by rain????

Still can’t solve the last problem. I guess there must be something wrong about my rain drops. I use distance between each rain drop and the man’s head to write some condition codes. The rain drops may seem to be affected well by the man, but I bet it’s actually not what we think they are, and that’s why although I could affect rain drops with the man, I failed to affect the smile with the rain drops? Too complicated. So in the end, I compromised and made the man smile when it’s raining and sad when it’s not.

Maybe it’s time to book an office hour with Dan.

And as usual, below are my baby’s bloody organs(codes).

Continue reading

V&S_02_CookYouAll

Audio recording project of Neva and me!

Do you feel being cooked?

Neva and I wanted to play sound with space and left/right tracks to build up an environment in which the audience would feel being cooked, burned, sprayed on, drank etc..

CookYouAll

CookYouAll

Except the intro music and high heels sound, we recorded every pieces in Neva’s place. And then we used Pro Tool to edit.  Thanks to the advice from teacher Craig, we edited whole piece at first, and then decided which one goes to Ceiling or Floor, which one goes to right or left soundtrack. And for some of the sound pieces , like rolling, we cut one single sound into pieces, and assigned them one after one into the right and left soundtrack.

In the end, the effect is quite good! We did create a 3D sound effect and it’s really interesting to hear our work delivered by 4 stereos(Much better than listening through computer).

Below are our fun time documentation!

boilingSoundme_eatingSoundneva_recordingwe_recordingplum listens to appledraftproTool

PComp_03_Observation_DearElevator

Hi Elevator,

How you’re used_my assumption

  1. User walks to the elevator and stands in front of the door or waits in line.
  2. Pushes up/down button if it’s not been pushed.
  3. Walks inside when the door opens.
  4. Gentleman holds door-open button for incomers.
  5. Everyone checks if his/her destined-floor-button has been pushed or not, or he/she pushes the button or asks others to do so.
  6. The door closes.
  7. Unless it’s user’s destined-floor, user stays inside instead of stepping out.
  8. Gentleman holds door-open button for incomers and out-goers.
  9. Users says “Excuse me. Thank you.” and steps out when the elevator reaches his/her destined-floor.
  10. The End.

How you’re actually used_from observation

  • actual situation(observed in the lobby of Tisch)
    • because of the existence of smartphone, users have more patience to wait nowadays.
    • when waiting in line, users start making small chat, meeting people from different departments, and it’s a good moment to be social.
    • at 4th floor, ITP’s elevators have no signs showing where the elevators are at. Maybe because of this, users become less patient waiting and more attempting to use the stairs down.
  • different approaches
    • some stand motionlessly and wait the door to close; some keep pushing the door-close button
    • when lines get too long, some users at the back give up and choose the stair instead, and some just keep waiting.
  • difficulties
    • users have to tiptoe to see if their destined-floor button has been pushed or not.
    • users have to squeeze in to push the button if it’s crowded.
    • users have to be aware of the unpredictable closing door.
  • easy
    • just stands and goes up and down several meters effortlessly.
    • asks for help to push the buttons.
  • longest time
    • waits in line
  • shortest time
    • gives up and uses stairs instead(if users’ departments don’t reside higher than 5th floor)
  • time of whole transaction (this part is still under construction)
    • waiting:
    • duration of each floor:
    • pushing button:
    • stepping in/out:

What if… Then… Moment for you my dear Elevator

  • The display board inside the elevator shows which floor has already been chosen.
  • After being pushed, the door open/close button flashes on and off continuously to indicate that it does keep working/sending message(giving local feedback), so users won’t act crazy pushing it.
  • Set floor buttons
    1. outside the elevator, and users press the button before walking in.
    2. on the side of the door, and users press the button when walking by.
    3. hanging from the ceiling, and users pull the button(acting like pulling string).