All posts by Nicole Kim

CaramellDansen Shake!

super fun girls time presents:

shake-your-booty-fun! (abi, emily, ieva, and nicole)

press ‘1’ to start player 1’s round. press ‘2’ to start player 2’s round. press ‘w’ to see who won. press ‘q’ to restart and play again!

Screenshot of gameplay
Screenshot of gameplay
Winner's screen!
Winner’s screen!

 

link to all the media files-

https://drive.google.com/folderview?id=0B-scoLsJ5PclSy1ZYmJtQ1lPQ2c&usp=sharing

import processing.video.*;
import ddf.minim.*;

Capture video;
PImage prevFrame;

Movie instructionsScreen;
Movie player1_screen;
Movie player2_screen;
Movie scoreBar1;
Movie scoreBar2;
Movie player1_wins;
Movie player2_wins;
Movie stop1;
Movie stop2;

Minim minim;
AudioPlayer player;

float threshold = 50;
int counter = 0;
int counter2 = 0;
boolean round1 = false;
boolean round2 = false;

float ypos1, ypos2; //location of score bar

Timer theStartTimer1;
Timer theGameTimer1;
Timer theStartTimer2;
Timer theGameTimer2;
boolean gameStart1 = false;
boolean gameStart2 = false;

void setup() {
  size(1280, 720);
  smooth();
  noStroke();
  video = new Capture(this, width, height);
  video.start();
  prevFrame = createImage(video.width, video.height, RGB);

  instructionsScreen = new Movie(this, "instructions.mov");
  player1_screen = new Movie(this, "player1_screen.mov");
  player2_screen = new Movie(this, "player2_screen.mov");
  scoreBar1 = new Movie(this, "score_bar.mov");
  scoreBar2 = new Movie(this, "score_bar.mov");
  player1_wins = new Movie(this, "player1_wins.mov");
  player2_wins = new Movie(this, "player2_wins.mov");
  stop1 = new Movie(this, "stop1.mov");
  stop2 = new Movie(this, "stop2.mov");

  minim = new Minim(this);
  player = minim.loadFile("Caramelldansen.wav");

  theStartTimer1 = new Timer(6000); 
  theGameTimer1 = new Timer (26000); //actual gameplay is 20sec
  theStartTimer2 = new Timer(6000);
  theGameTimer2 = new Timer (26000);
}

void draw() {
  image(instructionsScreen, 0, 0);
  instructionsScreen.play();

  if (gameStart1 == true) {
    instructionsScreen.stop();
    player.play();

    //round 1
    if (theStartTimer1.timeOver()) {
      if (theGameTimer1.timeOver()) {
        image(stop1, 0, 0);
        stop1.play();
        round1 = true;
      }
      else {
        image(player1_screen, 0, 0);
        player1_screen.play();
        theGameTimer1.countDown();

        textSize(height/10);
        fill(255, 0, 255);
        text (counter, width/30, height/10);
        textSize(height/10);
        fill(0, 255, 255);
        text (counter2, width-width/7.5, height/10);

        // Capture video
        if (video.available()) {
          // Save previous frame for motion detection
          prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
          prevFrame.updatePixels();
          video.read();
        }

        loadPixels();
        video.loadPixels();
        prevFrame.loadPixels();

        float totalMotion = 0;

        // Sum the brightness of each pixel
        for (int i = 0; i < video.pixels.length; i ++ ) {
          // Step 2, what is the current color
          color current = video.pixels[i];

          // Step 3, what is the previous color
          color previous = prevFrame.pixels[i];

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current);
          float g1 = green(current);
          float b1 = blue(current);
          float r2 = red(previous);
          float g2 = green(previous);
          float b2 = blue(previous);

          // Motion for an individual pixel is the difference between the previous color and current color.
          float diff = dist(r1, g1, b1, r2, g2, b2);
          // totalMotion is the sum of all color differences.
          totalMotion += diff;
        }

        // averageMotion is total motion divided by the number of pixels analyzed.
        float avgMotion = totalMotion / video.pixels.length;

        // average motion
        smooth();
        noStroke();
        fill(0);
        counter += avgMotion/20;

        float ypos = map (counter, 0, 1200, 0, height);
        image(scoreBar1, width/32, height-ypos);
        ypos1 = height-ypos;
        scoreBar1.loop();
      }
    } 
    else
    {
      image(player1_screen, 0, 0);
      player1_screen.play();
    }
  }

  //round 2
  if (gameStart2 == true) {
    player1_screen.stop();

    if (theStartTimer2.timeOver()) {
      if (theGameTimer2.timeOver()) {
        image(stop2, 0, 0);
        stop2.play();
      }
      else {
        image(player2_screen, 0, 0);
        player2_screen.play();
        theGameTimer2.countDown();
        textSize(height/10);
        fill(255, 0, 255);
        text (counter, width/30, height/10);
        textSize(height/10);
        fill(0, 255, 255);
        text (counter2, width-width/7.5, height/10);
        image(scoreBar1, width/32, ypos1);

        // Capture video
        if (video.available()) {
          // Save previous frame for motion detection
          prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
          prevFrame.updatePixels();
          video.read();
        }

        loadPixels();
        video.loadPixels();
        prevFrame.loadPixels();

        float totalMotion = 0;

        // Sum the brightness of each pixel
        for (int i = 0; i < video.pixels.length; i ++ ) {
          // Step 2, what is the current color
          color current = video.pixels[i];

          // Step 3, what is the previous color
          color previous = prevFrame.pixels[i];

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current);
          float g1 = green(current);
          float b1 = blue(current);
          float r2 = red(previous);
          float g2 = green(previous);
          float b2 = blue(previous);

          // Motion for an individual pixel is the difference between the previous color and current color.
          float diff = dist(r1, g1, b1, r2, g2, b2);
          // totalMotion is the sum of all color differences.
          totalMotion += diff;
        }

        // averageMotion is total motion divided by the number of pixels analyzed.
        float avgMotion = totalMotion / video.pixels.length;

        // average motion
        smooth();
        noStroke();
        fill(0);
        counter2 += avgMotion/20;

        float ypos2A = map (counter2, 0, 1200, 0, height);
        image(scoreBar2, width- width/7, height-ypos2A);
        ypos2 = height-ypos2A;
        scoreBar2.loop();
      }
    } 
    else
    {
      image(player2_screen, 0, 0);
      player2_screen.play();
    }
  }

  if (round1 == true && round2 == true) {
    //instructionsScreen.stop();
    player1_screen.stop();
    player2_screen.stop();
    //image(scoreBar1, width/32, ypos1);
    image(scoreBar2, width - width/7, ypos2);

    //if player2 wins
    if (counter2 > counter) {
      image(player2_wins, 0, 0);
      player2_wins.play();
    }
    //if player1 wins
    if (counter > counter2) {
      image(player1_wins, 0, 0);
      player1_wins.play();
    }
  }
}

void keyPressed() {
  if (key == '2') {
    gameStart2 = true;
    theStartTimer2.start();
    theGameTimer2.start();
  }
  else {
    gameStart2 = false;
  }

  if (key == '1') {
    gameStart1 =  true;
    theStartTimer1.start();
    theGameTimer1.start();
  } 

  if (key == 'w') {
    round2 = true;
  }

  if (key == 'q') {
    gameStart1 = false;
    gameStart2 = false;
    round1 = false;
    round2 = false;
    counter2 = 0;
    counter = 0;
    ypos1 = height;
    ypos2 = height;
    scoreBar1.stop();
    scoreBar2.stop();
  }
}

void movieEvent(Movie m) {
  m.read();
}
//New Class

PFont font;

class Timer {
  int savedTime;
  int totalTime;
  int countDown;
  int passedTime;
  int screenSeconds;

  Timer(int temp_totalTime) {
    totalTime = temp_totalTime;

  }

  void start() {
    savedTime = millis();
  }

  void countDown(){
    screenSeconds = passedTime / 1000;
     countDown = 26 - screenSeconds;
    font = loadFont("KarmaSuture.vlw");
    fill(50, 255, 0);
    textFont(font, 100);
    text(countDown, width/2.2, height/7); 
  }

  boolean timeOver() {
  passedTime = millis() - savedTime;
    if (passedTime > totalTime) {
      return true;
    }    
    else {
      return false;
    }
  }
}

 

Computer Machines

hello earth people

I am a huge Luddite. I am generally skeptical towards all things of new ‘technology’, and as a good rule of thumb, I like to keep my communication, and my ideas, analog and on paper. 

When I explain to people that I am interested in New Media art and interactive design, my apparent distaste for technology seems to directly conflict with my stated interests. How is it that I want to work with a medium that I openly object to? Honestly, this question appeared to be a paradox, even to myself. However, the more I thought about different elements of what I liked and disliked about new technology, the incongruity cleared.

Computers utilized for communication create a virtual prison for users. By communication, I mean the mundane dialogue between person x and person y; scheduling dates to meet, things to do, talking about whose dog at which homework- all of these discussions that we have to fulfill our innate desire for social interaction are poisonous when combined with new technology. Because computers allow users to always be available for communication, people are able to hold tens, or hundreds, of these benign conversations every day.  As we are desensitized to the practice of multiple conversations, this becomes the norm in our social habits. We grow the number of dialogs we have at a singular moment in time, because we can. We build webs of conversations, which serves as a constant reminder of how not alone we are in this world. Always online, always connected. The idea that people are always on social media is a terrifying and saddening reality; noses buried into smartphones, unable to stop dancing thumbs, and instead, experience the world outside of this imaginary bubble-society. This bubble of virtual reality serves as a perpetual distraction to the life in the real world. Maybe moderation is the key to both better communication and greater happiness, but from what I’ve seen, there is no moderation with social media. Moderation would juxtapose the foundation of social media, which is to be connected at all times, any hour of the day. Sometimes it’s nice to be off the grid, you know? No expectations, no communication. Virtual prison is not such a nice place.

The reason why I love New Media art and interactivity is that it utilizes computers for communication in a way that isn’t petty and trivial. These designs create experiences that allow viewers to experience the surreal, which seem to break away from the stupid-shit-for-brains web of mundane communication. The brain becomes dull when it relies too much on computers.  Minds lose the ability to think organically, which is an integral part to creativity and innovation (arguably the driving force of an upwards-growing society (Brynjolfsson and McAfee, The Second Machine Age)). Computers have usurped their role as ancillary tools and instead, have become the creative force instead. Sadly, that is the once function computers cannot do, which is generate new ideas from nothing. When people interact with this new technology art and experience the illusion of the 4th dimension, they actually put their damn phones away for a minute, crane their necks back, and focus on the physical world around them. Computers are not the enemy; they have been nothing but good since their creation. However, people’s insane abuse of the computer machine’s  abilities has consequently created a mutation in social habits that is essentially making us all more apathetic, less intelligent, and  generally a lot less interesting (although I like the cats. We can keep the cats).

</communication>

Space Shooter (in the works)

hello friends

this week started working on a game that includes computer vision as the controller. this is still in the works, but i’ll post the most recent code i have. basically it’s a derivative of the oldschool game ‘pong’, where the player is a red space ship trying to destroy the black enemy spacecraft (the death star?) by catching the balls and throwing them back at the enemy. The balls shoot randomly from the enemy every half second. If the player can catch a ball by pressing a button when a ball hits them. However, if the ball hits the player when they are not pressing the button, then the player will lose a life.

so far, i have parts of this game working, but the video tracking is a bit off. i’m trying to have the video load only for the beginning of the game so the user can click a tracking marker, and then once the game starts, remove the video so it won’t be distracting during the game. (maybe kinect would work better for this? and/or ‘hand’ tracking)

Screen Shot 2014-04-14 at 1.56.03 PM

 

//tracking the average pixel makes it shake less
import processing.video.Capture;
Capture cam;// regular processing libary
int threshold = 20; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR =255;
float objectG = 0;
float objectB = 0;

Ship theShip;
Enemy theEnemy;
Timer theTimer;
Timer theVideoTimer;
ArrayList theBall;

void setup() {
  size(640, 480);
  println(Capture.list());
  cam = new Capture(this, width, height);
  cam.start();
  theTimer = new Timer(500);
  theVideoTimer = new Timer (5000);
  theTimer.start();
  theBall = new ArrayList();
  theShip = new Ship();
  theEnemy = new Enemy(200);
}

void draw() {

  if (theTimer.timeOver()) {
    theBall.add(new Ball (20));
    theTimer.start();
  }

  for (int i = 0; i < theBall.size(); i++) {
    Ball b = (Ball) theBall.get(i);
    if (theShip.intersect(b)) {
      println("hey");
      b.change();
    }
    //b.Print();
    b.move();
    b.display();
  }

  if (cam.available()) {
    cam.read();
    int totalFoundPixels= 0;  
    int sumX = 0; 
    int sumY = 0;

    for (int row = 0; row < cam.height; row++) {
      for (int col = 0; col < cam.width; col++) {

        int offset = row * cam.width + col;
        int thisColor = cam.pixels[offset];

        float r = red(thisColor);
        float g = green(thisColor);
        float b = blue(thisColor);

        float diff = dist(r, g, b, objectR, objectG, objectB);

        if (diff < threshold) { 
          sumX = sumX + col;
          sumY= sumY + row;
          totalFoundPixels++;
        }
      }
    }

    //allows user to click tracking color, then supposed to remove video
       if (theVideoTimer.timeOver()) {
        background(157, 247, 239);

  } else
  {
      image(cam, 0, 0);
  }

    if (totalFoundPixels > 0) {
      aveX = sumX/totalFoundPixels;
      aveY = sumY/totalFoundPixels;

      for (int i = 0; i < theBall.size(); i++) {
        Ball b = (Ball) theBall.get(i);
        if (theShip.intersect(b)) {
        }
      }
    }
  }
   theShip.display();
   theEnemy.display();
}

void mousePressed() {
  //if they click, use that picture for the new thing to follow
  int offset = mouseY * cam.width + mouseX;
  //pull out the same pixel from the current frame 
  int thisColor = cam.pixels[offset];

  //pull out the individual colors for both pixels
  objectR = red(thisColor);
  objectG = green(thisColor);
  objectB = blue(thisColor);
  println("Chasing new color  " + objectR + " " + objectG + " " + objectB);
}
class Ball {
  float r; //radius of ball
  float theta; //degree of shot
  float xSpeed, ySpeed;                                                                      
  float x = width/2;
  float y = height/2;
  boolean change = false;

  Ball (float tempR) {
    r = tempR;
    xSpeed = 1;
    ySpeed = 1;
    theta = int (random(0, 360));
  }
  void move() {
    xSpeed = cos(radians(theta));
    ySpeed = sin(radians(theta));
    if (change == true){
      x -= xSpeed;
      y -= ySpeed;
    }else{

    x += xSpeed;
    y += ySpeed;
  }
  }

  void display() {
    if (change == true) {
      stroke(255, 0, 0);
    } 
    else {
      stroke(0, 0, 255);
    }

    fill(255);
    strokeWeight(3);
    //stroke(0, 0, 255);
    ellipse(x, y, r, r);
  }

  void Print() {
    println(theta);
  }

  void disappear() {
    if (x < 0 || x > width) {
      x = 2 * width;
    }
    if (y < 0 || y > height) {
      y = 2 * height;
    }
  }

  void change() {
    change = true;
  }
}

 

class Enemy {
  float e; //enemy radius

    Enemy(float tempE) {
    e = tempE;
  }

  void display() {
    noStroke();
    fill (0);
    ellipse(width/2, height/2.5, e, e);
  }
}

 

class Ship {
  float s; //length of triangle side
  float z; //distance away from enemy cener

  Ship() {
    z = 175;
    s = 25;
  }

  void display() {
    fill (255, 0, 0);
    noStroke();
    float rotation = -(width-aveX-10) *1.2;
    pushMatrix();
    translate(width/2, height/2.5);
    rotate (radians(rotation));
    shapeMode(CENTER);
    triangle (-s, z+s*sqrt(3), s, z+s*sqrt(3), 0, z);
    popMatrix();
  }

  boolean intersect(Ball b) {
    float rotation = radians(-mouseX * 1.2);
        float distance = dist(aveX-10, aveY-10, b.x, b.y);
    println (width-rotation);
    if (distance < 10) {
      return true;
    } 
    else
      return false;
  }
}

 

class Timer {
  int savedTime;
  int totalTime;

  Timer(int temp_totalTime) {
    totalTime = temp_totalTime;
  }

  void start() {
    savedTime = millis();
  }

  boolean timeOver() {
    int passedTime = millis() - savedTime;
    if (passedTime > totalTime) {
      return true;
    }    
    else {
      return false;
    }
  }
}

 

 

Popping Bubbles

hello earthlings

this week i decided to pop bubbles with video

//tracking the average pixel makes it shake less
import processing.video.Capture;
Capture cam;// regular processing libary
int threshold = 20; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR =255;
float objectG = 0;
float objectB = 0;
Bubble [] theBubbles = new Bubble[30];
Mouse theMouse;

void setup() {
  size(640, 480);
  println(Capture.list());
  cam = new Capture(this, width, height);
  cam.start();
  theMouse = new Mouse();
  for (int i=0; i<theBubbles.length; i++) {
    theBubbles[i] = new Bubble (50);
  }
}

void draw() {
  for (int i=0; i<theBubbles.length; i++) {
    theBubbles[i].move();
    theBubbles[i].display();
    theBubbles[i].boundary();
  }
  if (cam.available()) {
    cam.read();
    int totalFoundPixels= 0;  //we are going to find the average location of change pixes so
    int sumX = 0;  //we will need the sum of all the x find, the sum of all the y find and the total finds
    int sumY = 0;
    //enter into the classic nested for statements of computer vision
    for (int row = 0; row < cam.height; row++) {
      for (int col = 0; col < cam.width; col++) {
        //the pixels file into the room long line you use this simple formula to find what row and column the sit in 

        int offset = row * cam.width + col;
        //pull out the same pixel from the current frame 
        int thisColor = cam.pixels[offset];

        //pull out the individual colors for both pixels
        float r = red(thisColor);
        float g = green(thisColor);
        float b = blue(thisColor);

        //in a color "space" you find the distance between color the same whay you would in a cartesian space, phythag or dist in processing
        float diff = dist(r, g, b, objectR, objectG, objectB);

        if (diff < threshold) {  //if it is close enough in size, add it to the average
          sumX = sumX + col;
          sumY= sumY + row;
          totalFoundPixels++;
        }
      }
    }
    image(cam, 0, 0);
    if (totalFoundPixels > 0) {
      aveX = sumX/totalFoundPixels;
      aveY = sumY/totalFoundPixels;

      for (int i=0; i<theBubbles.length; i++) {

        if (theMouse.intersect(theBubbles[i])) {
          theBubbles[i].pop();
        }
      }
    }
  }
}
void mousePressed() {
  //if they click, use that picture for the new thing to follow
  int offset = mouseY * cam.width + mouseX;
  //pull out the same pixel from the current frame 
  int thisColor = cam.pixels[offset];

  //pull out the individual colors for both pixels
  objectR = red(thisColor);
  objectG = green(thisColor);
  objectB = blue(thisColor);
  println("Chasing new color  " + objectR + " " + objectG + " " + objectB);
}

}

 

class Bubble {
  float x;
  float y;
  float ySpeed;
  float d = 5;

  Bubble(float tempD) {
    x = random(0, width);
    y = height;
    ySpeed = random(0.5, 1.5);
    d = tempD;
  }

  void move() {
    x = x + random(-1, 1);
    y = y -ySpeed;
  }

  void display() {
    strokeWeight(5);
    stroke(0, 0, 255, 180);
   fill(0, 0, 255, 180);
    ellipse(x, y, d, d);
  }

void pop(){
  x = width * 2;
  y = height * 2;
  ySpeed = 0;
}
  void boundary() {
    if (y < d/2) {
      y = height;
    }
  }
}

 

class Mouse {
  float mousex, mousey;
  float r;
  float m;

  Mouse() {
    r = 5;
  }

  boolean intersect(Bubble b) {
    float distance = dist(aveX-10, (aveY-10), b.x, b.y);
    if (distance < r + b.d) {
      return true;
    } 
    else
    {
      return false;
    }
  }
}

 

Eat the Shapes Game

hello fellow earthlings

This week, I decided to continue working on the game I made during spring break. I added a force sensor through Arduino to replace the mousePressed() function, as well as some other small details for a more cohesive game.

The goal of this week’s game is to eat as many shapes as possible. To ‘eat’ an object, push the force sensor when your character (the black-outlined circle) is near a shape. A laser beam sound plays every time the force sensor is pressed.  The red number in the background shows how many shapes are currently on screen, and the large  blue number displays the number of shapes eaten. The smaller blue number in the center shows the number of shapes eaten in the previous round (kind of like a ‘high score’ record). If the red number reaches more than 25, the game is over. When a shape is eaten, one of three random sound bits plays (can you guess where I sampled from? http://www.youtube.com/watch?v=JtH68PJIQLE). Each shape comes on screen based on an independent timer. Every 10 seconds, a large black circle comes on screen. If you eat this shape, the game will automatically be over. Pressing ‘q’ resets the game.

I think I’m finally ready to label this game as ‘finished’. It’s pretty simple in gameplay, but I definitely used this project to explore how to make classes/objects, use the sound library, and connect Processing with Arduino. If I decide to come back and work on this game, I would definitely try to clean up the code so that there aren’t so many repetitive elements/the program will run faster.

goodbye fellow earthlings!

 

a better looking version of the game

 

Force Meter Set Up

//Main Body of Code
import processing.serial.*;
import ddf.minim.*;
Minim m;
AudioPlayer[] player;
Serial myPort;
int force;
Mouse theMouse;
ArrayList theSquares;
ArrayList theCircles;
ArrayList theTriangles;
ArrayList theDeath;
Timer theSquareTimer;
Timer theCircleTimer;
Timer theTriangleTimer;
Timer theDeathTimer;
int eatenShapes = 0;
int shapesOnScreen = 0;
int lastRound;
boolean gameOver = false;

void setup() {
  size (500, 500, P2D);
  printArray(Serial.list());
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
  myPort.readStringUntil('\n'); 
  m = new Minim(this);
  player = new AudioPlayer[4];
  player[0] = m.loadFile("Beep.wav");
  player[1] = m.loadFile("grimes_1.wav");
  player[2] = m.loadFile("grimes_2.wav");
  player[3] = m.loadFile("grimes_3.wav");
  theMouse = new Mouse();
  theSquares = new ArrayList();
  theCircles = new ArrayList();
  theTriangles = new ArrayList();
  theDeath = new ArrayList();
  theSquareTimer = new Timer (2000);
  theCircleTimer = new Timer (1000);
  theTriangleTimer = new Timer (1500);
  theDeathTimer = new Timer (10000);
  theSquareTimer.start();
  theCircleTimer.start();
  theTriangleTimer.start();
  theDeathTimer.start();
}

void draw() {
  background(255);
  grid();
  textAlign(CENTER);
  textSize(height/4);
  fill(0, 0, 255, 180);
  text(eatenShapes, 2*width/3, height/2);
  fill(255, 0, 0, 180);
  text(shapesOnScreen, width/3, height/2);
  textSize(height/7);
  fill (0, 0, 255, 180);
  text(lastRound, width/2, 2*height/3);

  if (theSquareTimer.timeOver()) {
    theSquares.add(new Square(40));
    shapesOnScreen ++;
    theSquareTimer.start();
  }
  if (theCircleTimer.timeOver()) {
    theCircles.add(new Circle(50));
    shapesOnScreen ++;
    theCircleTimer.start();
  }
  if (theTriangleTimer.timeOver()) {
    theTriangles.add(new Triangle(30));
    shapesOnScreen ++;
    theTriangleTimer.start();
  }
  if (theDeathTimer.timeOver()) {
    theDeath.add(new Death());
    theDeathTimer.start();
  }
  if (shapesOnScreen > 25 || gameOver == true) {
    background (255);
    textSize(50);
    textAlign(CENTER);
    text ("game over", width/2, height/2);
    theSquares.clear();
    theCircles.clear();
    theTriangles.clear();
    theDeath.clear();
    theMouse.disappear();
  }

if (force > 30) {
    for (int i = 0; i < theDeath.size(); i++) {
      Death d = (Death) theDeath.get(i);
      if (theMouse.intersectD(d)) {
        gameOver = true;
      }
    }
    player[0].play();
    player[0] = m.loadFile("Beep.wav");
    int sx = int((random(1, 4)));
    for (int j = 1; j < 4; j++) {
      for (int i = 0; i < theSquares.size(); i++) {
        Square q = (Square) theSquares.get(i);
        if (theMouse.intersectS(q)) {
          q.disappear();
          eatenShapes++;
          shapesOnScreen--;
          player[sx].play();
          player[0] = m.loadFile("grimes_1.wav");
          player[1] = m.loadFile("grimes_2.wav");
          player[2] = m.loadFile("grimes_3.wav");
        }
      }

      for (int i = 0; i < theCircles.size(); i++) {
        Circle c = (Circle) theCircles.get(i);
        if (theMouse.intersectC(c)) {
          c.disappear();
          eatenShapes++;
          shapesOnScreen--;
          player[sx].play();
          player[0] = m.loadFile("grimes_1.wav");
          player[1] = m.loadFile("grimes_2.wav");
          player[2] = m.loadFile("grimes_3.wav");
        }
      }
      for (int i = 0; i < theTriangles.size(); i++) {
        Triangle t = (Triangle) theTriangles.get(i);
        if (theMouse.intersectT(t)) {
          t.disappear();
          eatenShapes++;
          shapesOnScreen--;
          player[sx].play();
          player[0] = m.loadFile("grimes_1.wav");
          player[1] = m.loadFile("grimes_2.wav");
          player[2] = m.loadFile("grimes_3.wav");
        }
      }
    }
  }

  for (int i = 0; i < theSquares.size(); i++) {
    Square q = (Square) theSquares.get(i);
    q.move();
    q.display();
  }
  for (int i = 0; i < theCircles.size(); i++) {
    Circle c = (Circle) theCircles.get(i);
    c.move();
    c.display();
  }
  for (int i = 0; i < theTriangles.size(); i++) {
    Triangle t = (Triangle) theTriangles.get(i);
    t.move();
    t.display();
  }
  for (int i = 0; i < theDeath.size(); i++) {
    Death d = (Death) theDeath.get(i);
    d.move();
    d.display();
  }

  theMouse.bounce();
  theMouse.display();

  }

void serialEvent(Serial _port) { //this is a callback function
  if (myPort == null)return;
  String input = myPort.readStringUntil('\n');
  if (input != null) {  //if a '\n' character has in fact now arrived
    input = input.trim();  //Take off the '\n' character
    force = int(input);  //Turn it into number
  }
}

void keyPressed() {
  if (key == 'q') {
    gameOver = false;
    lastRound = eatenShapes;
    eatenShapes = 0;
    shapesOnScreen = 0;
    theSquareTimer.start();
    theCircleTimer.start();
    theTriangleTimer.start();
    theDeathTimer.start();
    theSquares.clear();
    theCircles.clear();
    theTriangles.clear();
    theDeath.clear();
  }
}

 //Circle Class
class Circle {
  float w; //radius of circle
  float circleX, circleY; //circle location
  float circleXspeed, circleYspeed;
  color cc = color(255,0,0, 180);

  Circle(float tempW) {
    w = tempW;
    circleX = random(w, 5*w);
    circleY = random(w, 5*w);
    circleXspeed = random(2, 5);
    circleYspeed = random(2, 5);
  }

  void move() {
    circleX = circleX + circleXspeed;
    circleY = circleY + circleYspeed;
    //boundary conditions
    if (circleX>width-w/2||circleX<w/2) {
      circleXspeed = -circleXspeed;
    }
    if (circleY>=height-w/2||circleY<w/2) {
      circleYspeed = -circleYspeed;
    }
  }

  void display() {
    fill (cc);
    noStroke();
    shapeMode(CENTER);
    ellipse(circleX, circleY, w, w);
  }

  void disappear() {
    circleXspeed = 0;
    circleYspeed = 0;
    circleX = width*2;
    circleY = height*2;
  }
}

//Death Ball Class
class Death {
  float d; //radius of circle
  float deathX, deathY; //circle location
  float deathXspeed, deathYspeed;
  color dc = color(0, 230);

  Death() {
    d = random(50, 100);
    deathX = random(d, 2*d);
    deathY = random(d, 2*d);
    deathXspeed = random(2, 4);
    deathYspeed = random(2, 4);
  }

  void move() {
    deathX = deathX + deathXspeed;
    deathY = deathY + deathYspeed;
    //boundary conditions
    if (deathX > width-d/2||deathX < d/2) {
      deathXspeed = -deathXspeed;
    }
    if (deathY > height - d/2 || deathY < d/2) {
      deathYspeed = -deathYspeed;
    }
  }

  void display() {
    fill (dc);
    noStroke();
    shapeMode(CENTER);
    ellipse(deathX, deathY, d, d);
  }
}

//Background Grid Class
float k=0;
float j=0;//gridlines
float l = 100; //length of square

void grid() {
  for (k=0; k<height/l; k++) {
    for (j=0;j<width/l;j++) {
      stroke(103, 227, 215);
      strokeWeight(1.2);
      line(j*l, 0, j*l, height); //use j*s if width>height
      line(0, j*l, width, j*l); //use k*s if height>width
    }
  }
}

//Mouse Class
class Mouse {
  float r; //radius
  float mousex, mousey; //position
  float mouseXspeed, mouseYspeed; //speed of mouse

  Mouse() {
    r = 18;
    mousex = random(r, width - 1.5*r);
    mousey = random(r, height - 1.5*r);
    mouseXspeed = random(3, 4);
    mouseYspeed = random(3, 4);
  }

  void grow() {
    r = r + 1;
  }

  void bounce() {
    mousex = mousex + mouseXspeed;
    mousey = mousey + mouseYspeed;

    //boundary conditions
    if (mousex>width-r||mousex< r) {
      mouseXspeed = -mouseXspeed;
    }
    if (mousey>=height-r||mousey <r) {
      mouseYspeed = -mouseYspeed;
    }
  }

  void display() {
    stroke(0);
    strokeWeight(3.5);
    noFill();
    shapeMode(CENTER);
    ellipse(mousex, mousey, r*2, r*2);
  }

  boolean intersectS(Square q) {
    float distanceS = dist(mousex, mousey, q.squareX, q.squareY);
    if (distanceS < r + q.s) {
      return true;
    }
    else {
      return false;
    }
  }

  boolean intersectC(Circle c) {
    float distanceC = dist(mousex, mousey, c.circleX, c.circleY);
    if (distanceC < r + c.w) {
      return true;
    }
    else {
      return false;
    }
  }
  boolean intersectT(Triangle t) {
    float distanceT = dist(mousex, mousey, t.triangleX, t.triangleY);
    if (distanceT < r + t.h) {
      return true;
    }
    else {
      return false;
    }
  }

  boolean intersectD(Death d) {
    float distanceD = dist(mousex, mousey, d.deathX, d.deathY);
    if (distanceD < r + d.d) {
      return true;
    } 
    else {
      return false;
    }
  } 
}

//Squares Class
class Square {
  float s; //square side
  float squareX, squareY; //square location
  float squareXspeed, squareYspeed;
  color qc = color(0,0,255, 200);
  float rotation;

  Square(float tempS) {
    s = tempS;
    squareX = random(2*s, width - 4*s);
    squareY = random(2*s, width - 4*s);
    squareXspeed = random(2, 4);
    squareYspeed = random(2, 4);
  }

  void move() {
    squareX = squareX + squareXspeed;
    squareY = squareY + squareYspeed;
    //boundary conditions
    if (squareX>width-s/2||squareX<s/2) {
      squareXspeed = -squareXspeed;
    }
    if (squareY>=height-s/2||squareY<s/2) {
      squareYspeed = -squareYspeed;
    }
  }

  void disappear() {
    squareXspeed = 0;
    squareYspeed = 0;
    squareX = width*2;
    squareY = height*2;
  }

  void display() {
    noStroke();
    fill(qc);
    rotation = rotation+0.08;
    pushMatrix();
    translate(squareX, squareY);
    rotate(rotation);
    rectMode(CENTER);
    rect(0, 0, s, s);
    popMatrix();
  }
}

//Timer Class
class Timer {
  int savedTime;
  int totalTime;

  Timer(int temp_totalTime) {
    totalTime = temp_totalTime;
  }

  void start() {
    savedTime = millis();
  }

  boolean timeOver() {
    int passedTime = millis() - savedTime;
    if (passedTime > totalTime) {
      return true;
    }    
    else {
      return false;
    }
  }
}

//Triangle Class
class Triangle {
  float h ; //half-side of tiangle
  float triangleX, triangleY; //location
  float triangleXspeed, triangleYspeed;
  color tc = color(0, 255, 0, 200);
  float rotation;

  Triangle(float tempH) {
    h = tempH;
    triangleX = random(4*h, width-4*h);
    triangleY = random(4*h, height-4*h);
    triangleXspeed = random(3, 5);
    triangleYspeed = random(2, 4);
  }

  void move() {
    triangleX = triangleX + triangleXspeed;
    triangleY = triangleY + triangleYspeed;

    if (triangleX > width -h || triangleX < h) {
      triangleXspeed *= -1;
    }

    if (triangleY > height -h || triangleY < h) {
      triangleYspeed *=-1;
    }
  }

  void disappear() {
    triangleXspeed = 0;
    triangleYspeed = 0;
    triangleX = width*2;
    triangleY = height*2;
  } 

  void display() {
    stroke(tc);
    strokeWeight(8);
    noFill();
    rotation = rotation+0.08;
    pushMatrix();
    translate(triangleX, triangleY);
    rotate(rotation);
    shapeMode(CENTER);
    triangle(-h, h, h, h, 0, -h/1.5);
    popMatrix();
  }
}

 

//The Arduino end of the code (also copy and pasted from class)
void setup(){
  Serial.begin(9600);
}

void loop(){
  int input = analogRead(0);
  Serial.print(input);  //notice I did not say println
  Serial.print('\n');  //instead I more explcitly send the linefeed character
}

 

 

Geometry Game

The purpose of the game is to move the mouse to move the circle and avoid the moving shapes. If the mouse hits one of the shapes, the circle’s radius gets larger until it grows to cover the whole screen. Some of the shapes change color if it touches the mouse-circle. Players can press ‘h’ to freeze the shapes for 0.5s and move the mouse around (as a helper), and press ‘q’ to restart the game. I want to add ‘levels’ to the game by increasing the number of shapes on the screen after a set amount of time by adding a boolean/timer buuuuuttttt…… uh I still have to figure that out!!

Preview

https://vimeo.com/89877903

Mouse theMouse;
Square [] theSquare = new Square[6];
Circle [] theCircle = new Circle [5];
Triangle [] theTriangle = new Triangle[3];
Star [] theStar = new Star[4];
float r = 12;
boolean startGame = false;

void setup() {
  size (900, 600); //P2D
  theMouse = new Mouse();
  for (int i=0; i<3; i++) {
    theSquare[i] = new Square (90);
  }
  for (int i=3; i<6; i++) {
    theSquare[i] = new Square (50);
  }
  for (int i=0; i<3; i++) {
    theCircle[i] = new Circle (80);
  }
  for (int i=3; i<5; i++) {
    theCircle[i] = new Circle (60);
  }
  for (int i = 0; i < theTriangle.length; i++) {
    theTriangle[i] = new Triangle (50);
  }
  for (int i = 0; i < theStar.length; i++) {
    theStar[i] = new Star ();
  }
}

void draw() {
  background (255);
  grid();

  theMouse.position(mouseX, mouseY);
  for (int i = 0; i < theSquare.length; i++) {
    theSquare[i].move();
    if (theMouse.intersectS(theSquare[i])) {
      theMouse.grow();
      theSquare[i].highlight();
    }
  }

  for (int i = 0; i < theCircle.length; i++) {
    theCircle[i].move();
    if (theMouse.intersectC(theCircle[i])) {
      theMouse.grow();
      theCircle[i].highlight();
    }
  }

  for (int i = 0; i < theTriangle.length; i++) {
    theTriangle[i].move();
    if (theMouse.intersectZ(theTriangle[i])) {
      theMouse.grow();
      theTriangle[i].highlight();
    }
  }

  for (int i = 0; i < theStar.length; i++) {
    theStar[i].move();
    if (theMouse.intersectD(theStar[i])) {
      theMouse.grow();
      theStar[i].highlight();
    }
  }

  theMouse.display();
  for (int i = 0; i < 5; i++) {
    theSquare[i].display();
  }

  for (int i = 0; i < 5; i++) {
    theCircle[i].display();
  }

  for (int i = 0; i < theTriangle.length; i++) {
    theTriangle[i].display();
  }

  for (int i = 0; i < theStar.length; i++) {
    theStar[i].display();
  }
}

void keyPressed() {
  if (key == 'q') {
    r = 12;
  }

  if (key == 'h') { //'help' button
    delay(500);
  }
}

//Circle
class Circle {
  float w; //radius of circle
  float circleX, circleY; //circle location
  float circleXspeed, circleYspeed;
  color cc = color(0, 0, 255, 200);
  boolean fill = false;

  Circle(float tempW) {
    w = tempW;
    circleX = random(w, 5*w);
    circleY = random(w, 5*w);
    circleXspeed = random(3, 5);
    circleYspeed = random(3, 5);
  }

  void move() {
    circleX = circleX + circleXspeed;
    circleY = circleY + circleYspeed;
    //boundary conditions
    if (circleX>width-w/2||circleX<w/2) {
      circleXspeed = -circleXspeed;
    }
    if (circleY>=height-w/2||circleY<w/2) {
      circleYspeed = -circleYspeed;
    }
  }

  void highlight() {
    fill = true;
  }

  void display() {
    if (fill = true) {
      noStroke();
      fill (255, 215, 10, 200);
    } 
    else {
      stroke(0, 0, 255);
      noFill();
    }
    shapeMode(CENTER);
    ellipse(circleX, circleY, w, w);
    cc = color(0, 0, 255, 200);
  }
}

//Grid
float k=0;
float j=0;//gridlines
float l = 100; //length of square

void grid() {
  for (k=0; k<height/l; k++) {
    for (j=0;j<width/l;j++) {
      stroke(103, 227, 215);
      strokeWeight(1.2);
      line(j*l, 0, j*l, height); //use j*s if width>height
      line(0, j*l, width, j*l); //use k*s if height>width
    }
  }
}

//Mouse
class Mouse {
  //float r; //radius
  float x, y; //position

  Mouse() {
    r = 12;
  }

  void grow() {
    r = r + 1;
  }

  void position(float tempX, float tempY) {
    x = tempX;
    y = tempY;
  }

  void display() {
    stroke(0);
    strokeWeight(3.5);
    noFill();
    ellipse(x, y, r*2, r*2);
  }

  boolean intersectS(Square q) {
    float distanceS = dist(x, y, q.squareX, q.squareY);
    if (distanceS < r + q.s) {
      return true;
    }
    else {
      return false;
    }
  }

  boolean intersectC(Circle t) {
    float distanceC = dist(x, y, t.circleX, t.circleY);
    if (distanceC < r + t.w) {
      return true;
    } 
    else {
      return false;
    }
  }

  boolean intersectZ(Triangle p) {
    float distanceZ = dist(x, y, p.triangleX, p.triangleY);
    if (distanceZ < r + p.h) {
      return true;
    } 
    else {
      return false;
    }
  }

  boolean intersectD(Star d) {
    float distanceD = dist(x, y, d.starX, d.starY);
    if (distanceD < r + 50) {
      return true;
    } 
    else {
      return false;
    }
  }
}

//Square
class Square {
  float s; //square side
  float squareX, squareY; //square location
  float squareXspeed, squareYspeed;
  color qc = color(255, 139, 242, 200);
  float rotation;

  Square(float tempS) {
    s = tempS;
    squareX = random(2*s, width - 4*s);
    squareY = random(2*s, width - 4*s);
    squareXspeed = random(4, 6);
    squareYspeed = random(4, 6);
  }

  void move() {
    squareX = squareX + squareXspeed;
    squareY = squareY + squareYspeed;
    //boundary conditions
    if (squareX>width-s/2||squareX<s/2) {
      squareXspeed = -squareXspeed;
    }
    if (squareY>=height-s/2||squareY<s/2) {
      squareYspeed = -squareYspeed;
    }
  }

  void highlight() {
    qc = color(0, 255, 0, 200);
  }

  void display() {
    noStroke();
    fill(qc);
    rotation = rotation+0.08;
    pushMatrix();
    translate(squareX, squareY);
    rotate(rotation);
    rectMode(CENTER);
    rect(0, 0, s, s);
    popMatrix();
    qc = color(255, 0, 0, 200);
  }
}

//Star
class Star {
  float starX, starY; //star location
  float starXspeed, starYspeed;
  color sc = color(0, 255, 0, 200);

  Star() {
    starX = random(150, width - 150);
    starY = random(150, 400);
    starXspeed = random(3, 5);
    starYspeed = random(2, 4);
  }

  void move() {
    starX = starX + starXspeed;
    starY = starY + starYspeed;
    //boundary conditions
    if (starX>width-50||starX<50) {
      starXspeed = -starXspeed;
    }
    if (starY>=height-50||starY<50) {
      starYspeed = -starYspeed;
    }
  }

  void highlight() {
    sc = color(255, 0, 0, 200);
  }

  void display() {
    noStroke();
    fill(sc);
    shapeMode(CENTER);
    beginShape();
    vertex(starX, starY-50);
    vertex(starX+14, starY-20);
    vertex(starX+47, starY-15);
    vertex(starX+23, starY+7);
    vertex(starX+29, starY+40);
    vertex(starX, starY+25);
    vertex(starX-29, starY+40);
    vertex(starX-23, starY+7);
    vertex(starX-47, starY-15);
    vertex(starX-14, starY-20);
    endShape(CLOSE);
    sc = color(0, 0, 255, 200);
  }
}

//Triangle
class Triangle {
  float h ; //half-side of tiangle
  float triangleX, triangleY; //location
  float triangleXspeed, triangleYspeed;
  float tc = (#C2CECD);
  float rotation;

  Triangle(float tempH) {
    h = tempH;
    triangleX = random(4*h, width-4*h);
    triangleY = random(4*h, height-4*h);
    triangleXspeed = random(3, 5);
    triangleYspeed = random(2, 4);
  }

  void move() {
    triangleX = triangleX + triangleXspeed;
    triangleY = triangleY + triangleYspeed;

    if (triangleX > width -h || triangleX < h) {
      triangleXspeed *= -1;
    }

    if (triangleY > height -h || triangleY < h) {
      triangleYspeed *=-1;
    }
  }

  void highlight(){
    tc = (#15FFE9);
  }

  void display() {
    stroke(0,255,0);
    strokeWeight(8);
    noFill();
    rotation = rotation+0.08;
    pushMatrix();
    translate(triangleX, triangleY);
    rotate(rotation);
    shapeMode(CENTER);
    triangle(-h, h, h, h, 0, -h/1.5);
    popMatrix();
    tc = color(255,0,0,200);
  }
}

 

… v a c a t i o n …

Exam on Thursday… I’ve already mentally check out.
A visual representation of my [mushy] brain.

https://vimeo.com/88618166

Ball [] ball = new Ball[50]; //number of balls in array
PImage pineapple; //background image

void setup() {
  size (700, 400);
  pineapple = loadImage("Pineapple.png");
  pineapple.resize(width, height); //rescale background image to fit screen size
  background (pineapple);
  for (int i=0; i<ball.length; i++) {
    ball[i] = new Ball (i*1.8); //determining size of ball by [i]
  }
}

void draw() {
  background(pineapple);
  for (int i=0; i<ball.length; i++) {
    ball[i].move();
    ball[i].display();
    ball[i].boundary();
  }
}

class Ball {
  float x;
  float y;
  float ySpeed;
  float d; //diameter of ball

  Ball(float _D) {
    x = random(0, width);
    y = height;
    ySpeed = random(0.1, 2);
    d = _D;
  }

  void move() {
    x = x + random(-1, 1);
    y = y -ySpeed;
  }

  void display() {
    float t = random(100, 130);
    stroke(0, 0, 255, t);
    fill(255, 255, 255, t);
    ellipse(x, y, d, d);
  }

  void boundary() {
    if (y < d/2) {
      y = height;
    }
  }
}

 

The Impossible Game!

A simple game where the player tries to stop the moving square inside one of the grid boxes. To stop the square, press ‘g’. Try to get the square to fit inside a box before it turns red green! The game is (almost) impossible because depending on the screen size the square and the box might not align, and the rotation of the square might also throw off the alignment! Muahaha…

Preview

 

float squareX=0;
float squareY=0;
float xspeed=2;
float yspeed=2;
float s=50;
float k=0;
float rotation;
float colour;

void setup() {
  size(600, 400);
  smooth();
  println("the impossible game");
}

void draw() {
  background(255);
  grid();

  squareX=squareX+xspeed;
  squareY=squareY+yspeed;
  rotation = rotation+0.1;
  colour = colour+squareX/100;

  if (squareX>width-s/2||squareX<0) {
    xspeed = -xspeed;
    colour = -colour;
  }
  if (squareY>height-s/2||squareY<0) {
    yspeed = -yspeed;
    colour = -colour;
  }
  translate(squareX, squareY);
  rotate(rotation);
  rectMode(CENTER);
  fill(0, colour, 0);
  rect(0, 0, s, s);
}

void keyPressed() {
  if (key =='g') {
    delay(300);
  }
}

void grid() {
  for (k=0;k<width/s;k++) {
    stroke(0);
    line(k*s, 0, k*s, height);
    line(0, k*s, width, k*s);
  }
}

 

Music to My Ears

Introducing the world’s most annoying instrument! I made an audio-visual musical instrument whose pitch changes depending on how hard to press the force sensor.

https://vimeo.com/87478117

int buzzer = 9;
int forceReading = A1;
int green = 11;
int yellow = 10;
int red = 8;
int green_ = 7;
int c= 261
int d= 294
int e= 329
int f= 349
int g= 392
int a=440
int b=493
int c_=523

void setup(){
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(green_, OUTPUT);
}

void loop(){
  int reading = analogRead(forceReading);
  Serial.println(reading);

  if (reading < 70){
    tone(buzzer, c);
    digitalWrite(green, HIGH);
  }
  else{
    digitalWrite(green, LOW);
  }
  if (reading > 69 && reading < 140){
    tone (buzzer, d);
  }
  if (reading > 139 && reading < 210){
    tone(buzzer, e);
    digitalWrite(yellow, HIGH);
  }
  else{
    digitalWrite(yellow, LOW);
  }
  if (reading > 209 && reading < 280){
    tone (buzzer, f);
  }
  if (reading >279 && reading < 350){
    tone (buzzer, g);
    digitalWrite(red, HIGH);
  }
  else{
    digitalWrite(red, LOW);
  }
  if (reading > 349 && reading < 420){
    tone (buzzer, a);
  }
  if (reading > 419 && reading < 490){
    tone (buzzer, b);
  }
  if (reading > 489 && reading < 560){
    tone (buzzer, c_);
    digitalWrite(green_, HIGH);
  }
  else{
    digitalWrite(green_, LOW);
  }
}

 

Albers Drawings

Some drawings inspired by Josef Albers cause he was a strange and awesome and strange color theorist.
1

size(300,300);
background(255);

stroke(10,199,220,50);
fill(10,199,220,50);//cirlce 1
ellipse(0,150,100,100);
stroke(255,0,205,50);//cirlc e8
fill(255,0,205,50);
arc(350,150,100,100,HALF_PI,PI+HALF_PI);
stroke(10,199,220,120);
fill(10,199,220,120);//circle 2
ellipse(50,150,100,100);
stroke(255,0,205,120);
fill(255,0,205,120);//circle 7
ellipse(300,150,100,100);
stroke(10,199,220,180);
fill(10,199,220,180);//circle 3
ellipse(100,150,100,100);
stroke(255,0,205,180);
fill(255,0,205,180);//circle 6
ellipse(250,150,100,100);
stroke(10,199,220,240);
fill(10,199,220,240);//circle 4
ellipse(150,150,100,100);
stroke(255,0,205,200);
fill(255,0,205,200);//circle 5
ellipse(200,150,100,100);

stroke(255,0,205,50);
fill(255,0,205,50);//cirlce 1
ellipse(0,50,100,100);
stroke(10,199,220,50);//cirlc e8
fill(10,199,220,50);
arc(350,50,100,100,HALF_PI,PI+HALF_PI);
stroke(10,199,220,120);
fill(10,199,220,120);//circle 7
ellipse(300,50,100,100);
stroke(255,0,205,120);
fill(255,0,205,120);//circle 2
ellipse(50,50,100,100);
stroke(10,199,220,180);
fill(10,199,220,180);//circle 6
ellipse(250,50,100,100);
stroke(255,0,205,180);
fill(255,0,205,180);//circle 3
ellipse(100,50,100,100);
stroke(10,199,220,240);
fill(10,199,220,240);//circle 5
ellipse(200,50,100,100);
stroke(255,0,205,200);
fill(255,0,205,200);//circle 4
ellipse(150,50,100,100);

stroke(255,0,205,50);
fill(255,0,205,50);//cirlce 1
ellipse(0,250,100,100);
stroke(10,199,220,50);//cirlc e8
fill(10,199,220,50);
arc(350,250,100,100,HALF_PI,PI+HALF_PI);
stroke(10,199,220,120);
fill(10,199,220,120);//circle 7
ellipse(300,250,100,100);
stroke(255,0,205,120);
fill(255,0,205,120);//circle 2
ellipse(50,250,100,100);
stroke(10,199,220,180);
fill(10,199,220,180);//circle 6
ellipse(250,250,100,100);
stroke(255,0,205,180);
fill(255,0,205,180);//circle 3
ellipse(100,250,100,100);
stroke(10,199,220,240);
fill(10,199,220,240);//circle 5
ellipse(200,250,100,100);
stroke(255,0,205,200);
fill(255,0,205,200);//circle 4
ellipse(150,250,100,100);

 

Albers Illusion

size(300,300);
background(255,205,0);

stroke(137,0,255);
fill(137,0,255);
rect(50,50,150,50);
rect(50,125,150,50);
rect(50,200,150,50);

stroke(255,85,0,150);
fill(255,85,0,150);
rect(150,25,100,250);

 

Big Red Button (PANIC)


FRUSTRATION!!
Assignment No. 2 Photo

ICM: Assignment No. 2 from Nicole Kim on Vimeo.

For my program, I had three switches and three LEDs. I wanted to have switch A turn on the red LED, switch B to turn on the green LED, and switches A and B when pressed simultaneously to turn on the yellow LED. The big red button on the third switch would make the LEDs blink sequentially (panic!!).

For some reason when I coded the yellow LED separately from the rest of the program, I got it to work when both switches were turned on. I even got the code to work with the whole system one time, but then I stupidly fidgeted with the wiring, so the only-yellow-LED code doesn’t work! Frustration!!

void setup(){
pinMode(8,INPUT);
pinMode(7,INPUT);
pinMode(6,INPUT);
pinMode(5,OUTPUT); //red light
pinMode(4,OUTPUT); //yellow light
pinMode(3,OUTPUT); //green light
}

void loop(){
if(digitalRead(8)==HIGH && digitalRead(7)==HIGH){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(3,LOW);
}else{
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(3,LOW);
}

(Code for the yellow LED- why do green and red LEDs turn on as well?!)

If anyone wants a little extra homework and wants to help me figure this out later….aaaarggg!! (But I’m still excited && proud of my code this week!)

 

``  
//assignment no. 2
void setup(){
  pinMode(8,INPUT);
  pinMode(7,INPUT);
  pinMode(6,INPUT);
  pinMode(5,OUTPUT); //red light
  pinMode(4,OUTPUT); //yellow light
  pinMode(3,OUTPUT);  //green light
}

void loop(){
  if(digitalRead(8)==HIGH){
    digitalWrite(5,HIGH);
  }else{digitalWrite(5,LOW);
  }
  if(digitalRead(7)==HIGH){
    digitalWrite(3,HIGH);
  }else{digitalWrite(3,LOW);
  }
  if(digitalRead(8)==HIGH && digitalRead(7)==HIGH){
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(3,LOW);
  }else{digitalWrite(4,LOW);
  digitalWrite(3,LOW);
  digitalWrite(5,LOW);
  }

  if(digitalRead(6)==HIGH){
   digitalWrite(5,HIGH);
   digitalWrite(3,LOW);
   delay(100);
   digitalWrite(4,HIGH);
   digitalWrite(5,LOW);
   delay(100);
   digitalWrite(3,HIGH);
   digitalWrite(4,LOW);
   delay(100);
  }else{
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
  }
}

NaCl (aq) Switch

image        photo (2)

These two switches use salt water to turn the LED on or off. Originally, I wanted the switch to be connected to an hourglass filled with salt water, so that every time a drop of water fell, the LED would light up. I tried to recreate this effect in two ways: one with a water bottle,  and the other with a overhead container of water. The idea of a water-hourglass seemed funny to me because, although it would look like it was keeping time, the rate flow would of the droplets would slow down (and the LED would blink at irregular intervals), thus making the hourglass a pretty inaccurate timepiece.

Original hourglass idea
Original hourglass idea