EHatneyITEC3450-01InteractionSketch

From GGCWiki
Jump to: navigation, search


Description

Goes here.... 2-3 Sentences

Demonstration

  • link to running code -or-
  • video of app running (likely a link to video sharing or cloud storage site)

Source Code

  • code listing (readable)
float w = 5;          // weight /pull of the curve
int mouseStartX = 0;  // remember where the mouse is whenever it is pressed
int decay = 10;       // coefficient for decay, 0 = max at each frame, 255 = no decay

void setup() {
  size(500, 500);
  background(0, 0, 0, 255);
}

void draw() {
  fill(0, 0, 0, decay);
  rect(0, 0, width, height);
  float d = random(20, 60);
  fill(random(255), random(255), random(255));
  yinyang(random(width), random(height), d);
}

void yinyang(float x, float y, float d) {

  ellipse(x, y, d, d);

  //bottom of yinyang S curve
  float x1=x,    y1=y;
  float x2=x,    y2=y+d/2;
  float cx1=x+w, cy1=y1;
  float cx2=x+w, cy2=y2;
  stroke(0);
  bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2);

  //top of yinyang S curve
  //x1,y1,x2,cy1 left unchanged
  y2=y-d/2;
  cx1=x-w; 
  cx2=x-w; cy2=y2;
  stroke(0);
  bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
}

void mousePressed() {
  mouseStartX = mouseX;
}

void mouseReleased() {
  float adjustment = map(mouseX-mouseStartX, 0, width, 0, 10);
  w += adjustment;
  println("w set to: " + w);
}

void mouseDragged() {
  float adjustment = map(mouseX-mouseStartX, 0, width, 0, 10);
  text(w+adjustment, mouseX, mouseY-10);
}

void keyPressed() {
  if (keyCode == UP) 
    decay++;
  else if (keyCode == DOWN) 
    decay--;
  println("decay:"  + decay);
}

Notes and Instructions

  • optional
  • or N/A

References

  1. Ref 1
  2. Ref 2
  3. etc.
  4. N/A

Interaction Sketch

Description

My picture is of a basketball court in the background with a basketball "white rectangle" bouncing in all different directions. the top scale changes the x speed and the bottom changes the y speed. The button stops and starts the basketball.

Demonstration

  • link to running code -or-
  • video of app running (likely a link to video sharing or cloud storage site)

Source Code

  • code listing (readable)
class Ball {
  
  private PImage img; 
  private final static String Ball = "bball.JPEG";
  
  private float x,y; // location
  private float xspeed,yspeed; // speed
  
  // Constructor
  Ball() {
   img = loadImage(Ball);
   x = random(width);
   y = random(height);
   xspeed = random(-5,5);
   yspeed = random(-5,5);
  }
  
  void setXspeed(float _f) {
   xspeed = _f; 
  }

  void setYspeed(float _f) {
   yspeed = _f; 
  }
  
    void move() {
    x += xspeed; // Increment x
    y += yspeed; // Increment y
    
    // Check horizontal edges
    if (x > (width-img.width) || x < 0) {
      xspeed *= - 1;
    }
    //Check vertical edges
    if (y > height-img.height || y < 0) {
      yspeed *= - 1;
    }
  }
  
  // Draw the ball
  void display() {
      image(img, x, y);
  }
    
}


}

Notes and Instructions

  • optional
  • or N/A

References

  1. Ref 1
  2. Ref 2
  3. etc.
  4. N/A


Cut Cards

Description

Sketch which simulates a deck of cards. It enables the user to select a random card from a 52 card deck as many times as they want, while keeping track of the number of decks created. Also features the ability for users to choose between 52 cards, or 52 cards + jokers.

Authors:

  • Jordan Smith
  • David Anderson
  • Brian Abbott
  • Ernest Hatney

Demonstration

http://www.openprocessing.org/sketch/111130/check

UML

Card

-String suit

-String value


+Card(String suit, String value)

+display (int w, int h): void


Deck

-static int numDecks

-boolean jokers


+Deck(boolean jokers)

+cutForCard(): Card

Code

Button button;
Button toggleJokerButton;
Card card;

boolean jokers = true;
static int numDecks;

void setup() {
  size(600, 400);
  button = new Button(100, 325, 150, 75, "Select");
  toggleJokerButton = new Button(100, 100, 60, 70, "Jokers");
  card = null;
}

void draw() {
  background(0);
  button.display();
  toggleJokerButton.display();
  if (card != null) 
    card.display(int(0.6*width), int(0.5*height));
  fill(255);
  text("Decks created: " + numDecks, width-100, 20);
}

void mouseClicked() {
  if (toggleJokerButton.contains(mouseX, mouseY)) {
    if (toggleJokerButton.says("Jokers")) {
      toggleJokerButton.setText("No Jokers");
      jokers = !jokers;
    } 
    else {   
      toggleJokerButton.setText("Jokers");
      jokers = !jokers;
    }
  }
  if (button.contains(mouseX, mouseY)) {
    if (button.says("Select")) {
      Deck deck = new Deck(jokers);
      card = deck.cutForCard();
      button.setText("Reset");
    } 
    else {
      card = null;
      button.setText("Select");
    }
  }
}
class Card {
  String suit, value;
  
  Card(String suit, String value) {
    this.suit = suit;
    this.value = value;
  }

  void display(float h, float w) {
    fill(255);
    rect(h, w, 150, 250);
    textAlign(CENTER);
    fill(0);
    text(value, 360, 150);
    text(suit, 360, 250);
  }
}
class Deck {
  private boolean jokers;
  
  Deck()
  {
  }
  
  Deck(boolean jokers) {
    this.jokers = jokers;
  }
  
  Card cutForCard() {
    numDecks++;
    int numSuit;
    if (jokers)
      numSuit = (int) random(1,54);
    else
      numSuit = (int) random(1,52);
    int numValue;
    if (numSuit <=13 )
    {
      numValue = numSuit % 13;
      return new Card("Hearts", cardValue(numValue));
    }
    else if (numSuit >=14 && numSuit <= 26)
    {
      numValue = numSuit % 13;
      return new Card("Diamonds", cardValue(numValue));
    }
    else if (numSuit >=27 && numSuit <= 39)
    {
      numValue = numSuit % 13;
      return new Card("Spades", cardValue(numValue));
    }
    else if (numSuit >=40 && numSuit <= 52)
    {
      numValue = numSuit % 13;
      return new Card("Clovers", cardValue(numValue));
    }
    else
    {
      return new Card("Joker", "");
    }
  }
  
  String cardValue (float _f) {
    if ( _f == 1 )
      return "Ace";
    else if (_f >= 2 && _f <= 10)
      return (int) _f + "";
    else if (_f == 11)
      return "Jack";
    else if (_f == 12)
      return "Queen";
    else
      return "King";
  }
}
class Button {

  private int x, y, w, h;
  private String textB;

  Button(int _x, int _y, int _w, int _h, String _text) {
    x = _x;
    y = _y;
    w = _w;
    h = _h;
    textB = _text;
  }

  void display() {
    fill(255);
    rectMode(CENTER);
    rect(x, y, w, h);
    stroke(0);
    fill(0);
    textAlign(CENTER, CENTER);
    text(textB, x, y);
  }

  boolean contains(int _x, int _y) {
    if ( (_x >= x-w/2) && (_x <= x+w/2) && (_y >= y-h/2) && (_y <= y+h/2) )
      return true;
    else
      return false;
  }

  boolean says(String s) {
    return textB.equals(s) ? true : false;
  }

  void setText(String _t) {
    textB = _t;
  }
}

Archive: File:CutForCard.zip


Ant Colony Sketch

Description

I took the original assignment and the color of the ants have been randomized. Also I have a butto that toggles from Blur(Which blurs the trail), Feed (which provides food to the ants), and Transport (which if you click and hold you can transport the ants wherever you want.

Demonstration

Source Code

  • code listing (readable)

/* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/15109*@* */ 


/* !do not delete the line above, required for linking your tweak if you re-upload */ 


/* 


  (CC) 2010 Forrest Oliphant, http://sembiki.com/ 


 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License 


 http://creativecommons.org/licenses/by-sa/3.0/ 


 */ 


  


color ANT_COLOR = color(68, 0, 8); 


int DIRT_R = 217; 


int DIRT_G = 165; 


int DIRT_B = 78; 


color DIRT_COLOR = color(DIRT_R, DIRT_G, DIRT_B); 


color foodColor; 


int HOME_R = 96; 


int HOME_G = 85; 


int HOME_B = 33; 


color PHER_HOME_COLOR = color(255,0,0); 


int FOOD_R = 255; 


int FOOD_G = 255; 


int FOOD_B = 255; 


color PHER_FOOD_COLOR = color(255, 0, 0); 


int switchCounter; 


  


int w = 50; 


//float[][] matrix = { { .111, .111, .111 }, 


                     //{ .111,  .111, .111 }, 


                    // { .111, .111, .111} };  


Colony col; 


Food food; 


Map pherHome; 


Map pherFood; 


Button switchToggle; 


Trap myTrap; 


  


void setup()  


{ 


  size(900, 506); 


  background(DIRT_COLOR); 


  noStroke(); 


  //smooth(); 


  


  pherHome = new Map(width, height); 


  pherFood = new Map(width, height); 


    


  col = new Colony(100, 100, 50, pherHome, pherFood); 


  foodColor = color(158, 55, 17); 


  food = new Food(width, height);   


  switchToggle = new Button(785, 120, 100, 50, "Set Food"); 


  


  


  // Sprinkle some crumbs around 


  for (int i=0; i<10; i++) { 


    food.addFood(400+int(random(-50, 50)), 300+int(random(-50, 50))); 


  } 


} 


  


void draw()  


{ 


  // Clear bg 


  //background(DIRT_COLOR); 


  


  myTrap = new Trap(mouseX, mouseY, 20, 20);  


  


  // Add food 


  if (mousePressed && switchToggle.says("Set Food")) 


  { 


    food.addFood(mouseX, mouseY); 


  }        


  


  loadPixels(); 


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


  { 


    color pixelColor; 


    if (food.getValue(i)) { 


      // Draw food 


      pixelColor = foodColor; 


    }  


  


    else 


    { 


      // Draw pheromones 


      // I found the direct math to be faster than blendColor() 


      float pixelAlpha = pherHome.getPercentage(i);      


      int pixel_r = int(HOME_R * pixelAlpha + DIRT_R * (1-pixelAlpha)); 


      int pixel_g = int(HOME_G * pixelAlpha + DIRT_G * (1-pixelAlpha)); 


      int pixel_b = int(HOME_B * pixelAlpha + DIRT_B * (1-pixelAlpha)); 


  


      pixelAlpha = pherFood.getPercentage(i); 


      pixel_r = int(FOOD_R * pixelAlpha + pixel_r * (1-pixelAlpha)); 


      pixel_g = int(FOOD_G * pixelAlpha + pixel_g * (1-pixelAlpha)); 


      pixel_b = int(FOOD_B * pixelAlpha + pixel_b * (1-pixelAlpha)); 


  


      // Using bitwise color math instead of color() on the following line 


      // upped the framerate from 43 to 58 on my computer 


      //pixelColor = color(pixel_r, pixel_g, pixel_b); 


      pixelColor = pixel_r << 16 | pixel_g << 8 | pixel_b; 


    } 


    // Set 


    pixels[i] = pixelColor;     


  } 


  updatePixels(); 


     


   // Draw ants 


  for (int i = 0; i < col.ants.length; i++)  


  {  


    Ant thisAnt = col.ants[i]; 


  


    thisAnt.step();  


  


    int thisXi = thisAnt.intX; 


    int thisYi = thisAnt.intY; 


    float thisXf = thisAnt.x; 


    float thisYf = thisAnt.y; 


    color thisColor = thisAnt.antColor; 


  


    fill(thisColor);  


  


    if (mousePressed && myTrap.contains(thisAnt.intX, thisAnt.intY) && switchToggle.says("Transport Ants")) 


    {          


      thisAnt.x = mouseX; 


      thisAnt.y = mouseY; 


    } 


  


    // Kills all ants that eat the food, including those carrying food 


    if (thisAnt.hasFood && foodColor == color(0, 255, 0)) 


    {     


      thisAnt.x = 9999; 


      thisAnt.y = 9999; 


  


      if (thisXi>col.x-10 && thisXi<col.x+10 && thisYi>col.y-10 && thisYi<col.y+10) { 


        // Close enough to home 


        thisAnt.hasFood = false; 


        thisAnt.homePher = 0; 


      } 


    } 


  


    else if (thisAnt.hasFood) 


    {      


      fill(foodColor);   


  


      if (thisXi>col.x-10 && thisXi<col.x+10 && thisYi>col.y-10 && thisYi<col.y+10) { 


        // Close enough to home 


        thisAnt.hasFood = false; 


        thisAnt.homePher = 100; 


      } 


    } 


  


    else if (food.getValue(thisXi, thisYi))  


    { 


      thisAnt.hasFood = true; 


      thisAnt.foodPher = 100; 


      food.bite(thisXi, thisYi); 


    } 


  


    if (abs(thisAnt.dx) > abs(thisAnt.dy)) { 


      // Horizontal ant 


      rect(thisXf, thisYf, 3, 2); 


    }  


    else { 


      // Vertical ant 


      rect(thisXf, thisYf, 2, 3); 


    } 


  }  


  // Transport 


  pherHome.step(); 


  pherFood.step(); 


  


  // Debug 


  //println(frameRate); 


  //println(mouseX + " " + mouseY); 


  


  switchToggle.display(); 


  


  // Transport ants 


  if (switchToggle.says("Transport Ants")) 


  { 


    // fill(255,0,0);   


    myTrap.cursorTrap(mouseX, mouseY, 20, 20); 


  } 


   


} 


  


void mouseClicked() 


{     


  if (switchToggle.contains(mouseX, mouseY)) 


  { 


    switchCounter++; 


  


    if (switchCounter == 1) 


    {    


      switchToggle.setText("Transport Ants"); 


    } 


  


    else if (switchCounter == 2) 


    { 


      switchToggle.setText("Blur Trail"); 


    } 


  


    else if (switchCounter > 2) 


    { 


      switchToggle.setText("Set Food");   


      switchCounter = 0; 


    } 


  } 


} 


    


  


  


void mouseDragged() { 


    


   // Blur Trail 


  if (switchToggle.says("Blur Trail")) 


  { 


     pherHome.blur(mouseX,mouseY); 


    pherFood.blur(mouseX,mouseY); // white 


    //new Map (mouseX,mouseY).step(); 


 } 


 if (switchToggle.says("Transport Ants")) 


 { 


       


    //pherFood.step();  


 } 


}     


    


  


class Ant { 


  float dx = random(-1, 1); 


  float dy = random(-1, 1); 


  float x; 


  float y; 


  int intX; 


  int intY; 


  int lastX; 


  int lastY; 


  int homeX; 


  int homeY; 


  


  boolean hasFood = false; 


  


  float homePher = 100; 


  float foodPher = 100; 


  private float USE_RATE = .995; 


  private float WANDER_CHANCE = .92; 


  


  int bored = 0; 


  


  Map homeMap; 


  Map foodMap; 


    


  color antColor; 


  


  Ant(int _x, int _y, Map _homePher, Map _foodMap, color _antColor) { 


    intX = homeX = _x; 


    intY = homeY = _y; 


    x = float(_x); 


    y = float(_y); 


    homeMap = _homePher; 


    foodMap = _foodMap; 


    antColor = _antColor; 


  } 


  


  void step() {     


      


    // Wander chance .1  


    if (random(1) > WANDER_CHANCE) dx += random(-1, 1); 


    if (random(1) > WANDER_CHANCE) dy += random(-1, 1); 


    if (random(1) > .99) bored += floor(random(15)); 


      


    if (bored>0) { 


      // Ignore pheromones 


      bored--; 


    } else { 


      // Sniff trails 


      if (hasFood) { 


        // Look for home  


        int[] direction = homeMap.getStrongest(intX, intY); 


        dx += direction[0] * random(1.5); 


        dy += direction[1] * random(1.5); 


      } 


      else 


      { 


        // Look for food  


        int[] direction = foodMap.getStrongest(intX, intY); 


        dx += direction[0] * random(1.5); 


        dy += direction[1] * random(1.5); 


      } 


    } 


    // Bounding limits, bounce off of edge 


    if (x<2) dx = 1; 


    if (x>width-2) dx = -1; 


    if (y<2) dy = 1; 


    if (y>height-2) dy = -1; 


    // Speed limit 


    dx = Math.min(dx, 1); 


    dx = Math.max(dx, -1); 


    dy = Math.min(dy, 1); 


    dy = Math.max(dy, -1); 


    // Move 


    x += dx; 


    y += dy; 


    intX = floor(x); 


    intY = floor(y); 


  


    // Only if ant has moved enough (to another pixel) 


    if (lastX!=intX || lastY!=intY) { 


      // Leave trails 


      if (hasFood) { 


        // Leave food pheromone trail 


        foodPher = foodPher * USE_RATE; 


        foodMap.setValue(intX, intY, foodPher); 


      } 


      else 


      { 


        // Leave home pheromone trail 


        homePher = homePher * USE_RATE; 


        homeMap.setValue(intX, intY, homePher); 


      } 


    } 


  


    lastX = intX; 


    lastY = intY; 


  } 


    


  


  


} 


  


  


class Button { 


  


  private int x, y, w, h; 


  private String textB; 


  


  Button(int _x, int _y, int _w, int _h, String _text) { 


    x = _x; 


    y = _y; 


    w = _w; 


    h = _h; 


    textB = _text; 


  } 


  


  void display() { 


    fill(255); 


    rectMode(CENTER); 


    rect(x, y, w, h); 


    stroke(0); 


    fill(0); 


    textAlign(CENTER, CENTER); 


    text(textB, x, y); 


  } 


  


  boolean contains(int _x, int _y) { 


    if ( (_x >= x-w/2) && (_x <= x+w/2) && (_y >= y-h/2) && (_y <= y+h/2) ) 


      return true; 


    else 


      return false; 


  } 


  


  boolean says(String s) { 


    return textB.equals(s) ? true : false; 


  } 


  


  void setText(String _t) { 


    textB = _t; 


  } 


} 


  


class Colony { 


  


  Ant[] ants; 


  color antColor; 


  int x; 


  int y; 


    


  Colony (int _x, int _y, int count, Map _pherHome, Map _pherFood) { 


    ants = new Ant[count]; 


    x = _x; 


    y = _y; 


     


    for (int i = 0; i < count; i++)  


    {  


      antColor = color(random(0,255), random(0,255), random(0,255)); 


      ants[i] = new Ant(x, y, _pherHome, _pherFood, antColor); 


    } 


  } 


} 


  


class Food  


{ 


  private boolean[] mapVals; 


  public int length; 


  private int mapW; 


  private int mapH; 


  color foodColor; 


    


  // A boolean map 


  Food (int w, int h) 


  { 


    mapW = w;  


    mapH = h;  


    length = mapW*mapH; 


    mapVals = new boolean[length]; 


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


      mapVals[i] = false; 


    } 


  } 


  


  void addFood(int x, int y) { 


    try { 


      // 10x10 bit of food 


      for (int i=x; i<mapW && i<x+10; i++) { 


        for (int j=y; j<mapH && j<y+10; j++) { 


          setValue(i, j, true); 


        } 


      } 


    }  


    catch (Throwable t) { 


    } 


  } 


  


  void setValue(int x, int y, boolean val) { 


    try { 


      mapVals[y * mapW + x] = val; 


    }  


    catch (Throwable t) { 


    } 


  } 


  


  void bite(int x, int y) { 


    setValue(x-1, y-1, false); 


    setValue(x-1, y, false); 


    setValue(x-1, y+1, false); 


    setValue(x, y-1, false); 


    setValue(x, y, false); 


    setValue(x, y+1, false); 


    setValue(x+1, y-1, false); 


    setValue(x+1, y, false); 


    setValue(x+1, y+1, false); 


  } 


    


  boolean getValue(int index) { 


    return mapVals[index]; 


  } 


    


  boolean getValue(int x, int y) { 


    try { 


      return mapVals[y * mapW + x]; 


    }  


    catch (Throwable t) { 


      // Off the map 


      return false; 


    } 


  } 


  


} 


  


class Map { 


  


  private float[] mapVals; 


  public int length; 


  private int mapW; 


  private int mapH; 


  


  private float MAX_VAL = 100; 


  private float EVAPORATION_RATE = .999; 


  


float[][] matrix = {  


    {  


      .111, .111, .111 


    } 


    ,  


    {  


      .111, .111, .111 


    } 


    ,  


    {  


      .111, .111, .111 


    } 


  };  


    


    


  // A float map 


  Map (int w, int h) { 


    mapW = w;  


    mapH = h; 


    length = mapW*mapH; 


    mapVals = new float[length]; 


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


      mapVals[i] = 0.0; 


    } 


  } 


  


  // Evaporate 


  void step() { 


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


      mapVals[i] = mapVals[i]*EVAPORATION_RATE; 


    } 


  } 


  


  void setValue(int x, int y, float val) { 


    try { 


      int index = y * mapW + x; 


      float oldVal = mapVals[index]; 


//      mapVals[index] = (oldVal + val)/2; 


      if (val>oldVal) { 


        mapVals[index] = val; 


      } 


    }  


    catch (Throwable t) { 


    } 


  } 


  


  float getPercentage(int index) { 


    return mapVals[index]/MAX_VAL; 


  } 


  


  float getValue(int index) { 


    return mapVals[index]; 


  } 


  


  float getValue(int x, int y) { 


    try { 


      return mapVals[y * mapW + x]; 


    }  


    catch (Throwable t) { 


      // Off the map 


      return -1; 


    } 


  } 


  


  /** 


   Returns a 2D vector of the strongest direction 


   */ 


  int[] getStrongest(int x, int y) { 


    float compare = 0; 


    float strongestVal = 0; 


    int[] strongest = { 


      0, 0 


    }; 


  


    compare = getValue(x-1, y-1); // up left 


    if (compare > strongestVal) { 


      strongest[0] = -1; 


      strongest[1] = -1; 


      strongestVal = compare; 


    } 


    compare = getValue(x, y-1); // up 


    if (compare > strongestVal) { 


      strongest[0] = 0; 


      strongest[1] = -1; 


      strongestVal = compare; 


    } 


    compare = getValue(x+1, y-1); // up right 


    if (compare > strongestVal) { 


      strongest[0] = 1; 


      strongest[1] = -1; 


      strongestVal = compare; 


    } 


    compare = getValue(x-1, y); // left 


    if (compare > strongestVal) { 


      strongest[0] = -1; 


      strongest[1] = 0; 


      strongestVal = compare; 


    } 


    compare = getValue(x+1, y); // right 


    if (compare > strongestVal) { 


      strongest[0] = 1; 


      strongest[1] = 0; 


      strongestVal = compare; 


    } 


    compare = getValue(x-1, y+1); // down left 


    if (compare > strongestVal) { 


      strongest[0] = -1; 


      strongest[1] = 1; 


      strongestVal = compare; 


    } 


    compare = getValue(x, y+1); // down 


    if (compare > strongestVal) { 


      strongest[0] = 0; 


      strongest[1] = 1; 


      strongestVal = compare; 


    } 


    compare = getValue(x+1, y+1); // down right 


    if (compare > strongestVal) { 


      strongest[0] = 1; 


      strongest[1] = 1; 


      strongestVal = compare; 


    } 


  


    return strongest; 


  } 


    


  void blur(int _x, int _y) { 


    int w = 50; 


    int xstart = constrain(_x - w/2, 0, width); 


    int ystart = constrain(_y - w/2, 0, height); 


    int xend = constrain(_x + w/2, 0, width); 


    int yend = constrain(_y + w/2, 0, height); 


    int matrixsize = 3; 


    ////loadPixels(); 


  


    // Begin our loop for every pixel in the smaller image 


    for (int x = xstart; x < xend; x++)  


      for (int y = ystart; y < yend; y++ )  


        setValue(x,y, convolve(x, y, matrix, matrixsize)); 


    ////updatePixels(); 


  } 


  


  float convolve(int x, int y, float[][] matrix, int matrixsize) 


  { 


    float atotal = 0.0; 


    for (int i = 0; i < matrixsize; i++) 


      for (int j= 0; j < matrixsize; j++) 


        atotal += (getValue(x-1+i, y-1+i) * matrix[i][j]); 


    return atotal; 


  } 


} 


  


class Trap  


{ 


  float x; 


  float y; 


  int w; 


  int h; 


  


  Trap(float _x, float _y, int _w, int _h) 


  { 


    x = _x; 


    y = _y; 


    w = _w; 


    h = _h; 


  } 


  


  void cursorTrap(float x, float y, int w, int h) 


  {     


    fill(255, 255, 0, 100);    


    ellipse(x, y, w, h); 


  } 


  


  boolean contains(float _x, float _y)  


  { 


    if ( (_x >= x-w/2) && (_x <= x+w/2) && (_y >= y-h/2) && (_y <= y+h/2) ) 


      return true; 


    else 


      return false; 


  } 


} 

Archive: File:Ant Colony.zip




__BrainGraph__

Description

I took the original assignment and added Instantaneous Display of Delta/Theta/Low Alpha/High Alpha/Low Beta/High Beta/Low Gamma/High Gamma. Then we made the instantaneous display rawEeg, attention, and meditation. Also we made time series display of Delta/Theta/Low Alpha/High Alpha/Low Beta/High Beta/Low Gamma/High Gamma, rawEeg, attention and meditation. My team members did an overall great job it took a lot of calibrator team work.

Demonstration

Source Code

  • code listing (readable)
 

String neurosky[]; 


ArrayList <JSONObject> reports; 


int x; 


float h; 


  


int val=0; 


int low=0; 


int attentionInt=0; 


int meditationInt=0; 


int deltaInt=0; 


int thetaInt=0; 


int lowAlphaInt=0; 


int highAlphaInt=0; 


int lowBetaInt=0; 


int highBetaInt=0; 


int lowGammaInt=0; 


int highGammaInt=0; 


  


float at=0; 


float med=0; 


float del=0; 


float the=0; 


float lalp=0; 


float halp=0; 


float lbet=0; 


float hbet=0; 


float lgam=0; 


float hgam=0; 


  


IntList valArray; 


IntList atArray; 


IntList medArray; 


IntList delArray; 


IntList theArray; 


IntList lalpArray; 


IntList halpArray; 


IntList lbetArray; 


IntList hbetArray; 


IntList lgamArray; 


IntList hgamArray; 


  


FloatList valMapArray; 


FloatList atMapArray; 


FloatList medMapArray; 


FloatList delMapArray; 


FloatList theMapArray; 


FloatList lalpMapArray; 


FloatList halpMapArray; 


FloatList lbetMapArray; 


FloatList hbetMapArray; 


FloatList lgamMapArray; 


FloatList hgamMapArray; 


  


  


void setup() { 


  size(1200, 600); 


  background(255); 


  neurosky = loadStrings("data/neurosky.json"); 


  reports = new ArrayList<JSONObject> (); 


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


    reports.add(parseJSON(neurosky[i])); 


  } 


  valArray = new IntList(); 


  atArray = new IntList(); 


  medArray = new IntList(); 


  delArray = new IntList(); 


  theArray = new IntList(); 


  lalpArray = new IntList(); 


  halpArray = new IntList(); 


  lbetArray = new IntList(); 


  hbetArray = new IntList(); 


  lgamArray = new IntList(); 


  hgamArray = new IntList(); 


  


  valMapArray = new FloatList(); 


  atMapArray = new FloatList(); 


  medMapArray = new FloatList(); 


  delMapArray = new FloatList(); 


  theMapArray = new FloatList(); 


  lalpMapArray = new FloatList(); 


  halpMapArray = new FloatList(); 


  lbetMapArray = new FloatList(); 


  hbetMapArray = new FloatList(); 


  lgamMapArray = new FloatList(); 


  hgamMapArray = new FloatList(); 


  


  for (int i=0; i < reports.size(); i++) { 


    try { 


      val = reports.get(i).getInt("rawEeg"); 


      valArray.append(val); 


      h = map(val, -200, 200, height/2-50, height/2+50); 


      valMapArray.append(h); 


    } 


    catch(RuntimeException re) { 


      valArray.append(val); 


      valMapArray.append(h); 


    } 


  } 


  strokeWeight(5); 


  for (int i=0; i < reports.size(); i++) { 


    try { 


      JSONObject esense = reports.get(i).getJSONObject("eSense"); 


      JSONObject eegpower = reports.get(i).getJSONObject("eegPower"); 


  


      attentionInt = esense.getInt("attention"); 


      atArray.append(attentionInt); 


      meditationInt = esense.getInt("meditation"); 


      medArray.append(meditationInt); 


  


      deltaInt = eegpower.getInt("delta"); 


      delArray.append(deltaInt); 


      thetaInt = eegpower.getInt("theta"); 


      theArray.append(thetaInt); 


      lowAlphaInt = eegpower.getInt("lowAlpha"); 


      lalpArray.append(lowAlphaInt); 


      highAlphaInt = eegpower.getInt("highAlpha"); 


      halpArray.append(highAlphaInt); 


      lowBetaInt = eegpower.getInt("lowBeta"); 


      lbetArray.append(lowBetaInt); 


      highBetaInt = eegpower.getInt("highBeta"); 


      hbetArray.append(highBetaInt); 


      lowGammaInt = eegpower.getInt("lowGamma"); 


      lgamArray.append(lowGammaInt); 


      highGammaInt = eegpower.getInt("highGamma"); 


      hgamArray.append(highGammaInt); 


  


      at = map(attentionInt, 0, 100, 0, height); 


      atMapArray.append(at); 


      med = map(meditationInt, 0, 100, 0, height); 


      medMapArray.append(med); 


      del = map(deltaInt, 0, 100, 0, height); 


      delMapArray.append(deltaInt); 


      the = map(thetaInt, 0, 100, 0, height); 


      theMapArray.append(the); 


      lalp = map(lowAlphaInt, 0, 100, 0, height); 


      lalpMapArray.append(lalp); 


      halp = map(highAlphaInt, 0, 100, 0, height); 


      halpMapArray.append(halp); 


      lbet = map(lowBetaInt, 0, 100, 0, height); 


      lbetMapArray.append(lbet); 


      hbet = map(highBetaInt, 0, 100, 0, height); 


      hbetMapArray.append(hbet); 


      lgam = map(lowGammaInt, 0, 100, 0, height); 


      lgamMapArray.append(lgam); 


      hgam = map(highGammaInt, 0, 100, 0, height); 


      hgamMapArray.append(hgam); 


    } 


    catch(RuntimeException re) { 


      atArray.append(attentionInt); 


      medArray.append(meditationInt); 


  


      delArray.append(deltaInt); 


      theArray.append(thetaInt); 


      lalpArray.append(lowAlphaInt); 


      halpArray.append(highAlphaInt); 


      lbetArray.append(lowBetaInt); 


      hbetArray.append(highBetaInt); 


      lgamArray.append(lowGammaInt); 


      hgamArray.append(highGammaInt); 


  


      atMapArray.append(at); 


      medMapArray.append(med); 


      delMapArray.append(deltaInt); 


      theMapArray.append(the); 


      lalpMapArray.append(lalp); 


      halpMapArray.append(halp); 


      lbetMapArray.append(lbet); 


      hbetMapArray.append(hbet); 


      lgamMapArray.append(lgam); 


      hgamMapArray.append(hgam); 


    } 


    x = int(map(i, 0, neurosky.length, 0, 1000)); 


  


    //raweeg 


    strokeWeight(1); 


    stroke(211, 211, 211); 


    line(x, valMapArray.get(i), x, height/2); 


  


    //at 


    strokeWeight(3); 


    stroke(255, 100, 100); 


    point(x, atMapArray.get(i)); 


  


    //med 


    stroke(0, 255, 0); 


    point(x, medMapArray.get(i)); 


  


    //del 


    stroke(0, 0, 255); 


    point(x, height-(delMapArray.get(i)/1000)); 


  


    //the 


    stroke(255, 255, 0); 


    point(x, height-(theMapArray.get(i)/1000)); 


  


    //lalp 


    stroke(255, 0, 255); 


    point(x, height-(lalpMapArray.get(i)/100)); 


  


    //halp 


    stroke(0, 255, 255); 


    point(x, height-(halpMapArray.get(i)/100)); 


  


    //lbet 


    stroke(255, 128, 128); 


    point(x, height-(lbetMapArray.get(i)/100)); 


  


    //hbet 


    stroke(100, 100, 100); 


    point(x, height-(hbetMapArray.get(i)/100)); 


  


    //lgam 


    stroke(50, 50, 50); 


    point(x, height-(lgamMapArray.get(i)/100)); 


  


    //hgam 


    stroke(25, 50, 100); 


    point(x, height-(hgamMapArray.get(i)/100)); 


  } 


  for (int i=0; i < reports.size(); i++) { 


    try { 


      low = reports.get(i).getInt("poorSignalLevel"); 


      x = int(map(i, 0, neurosky.length, 0, 1000)); 


      if (low==200) { 


        stroke(255, 0, 0); 


        line(x, 0, x, height); 


      } 


    } 


    catch(RuntimeException re) { 


    } 


  } 


} 


  


void draw() { 


  int arrayIndex = int(map(mouseX, 0, 1000, 0, neurosky.length)); 


  fill(255); 


  noStroke(); 


  rect(1000, 0, 1200, height); 


  text(int(frameRate), 1160, height-16); 


  if (mouseX < 1000) { 


    if (arrayIndex>28) { 


      fill(0); 


      text("Time: " + ((arrayIndex/512)+28) + "s", 1030, 20); 


      fill(255, 100, 100); 


      text("Attention: " + atArray.get(arrayIndex), 1030, 36); 


      fill(0, 255, 0); 


      text("Meditaton: " + medArray.get(arrayIndex), 1030, 52); 


      fill(0, 0, 255); 


      text("Delta: " + delArray.get(arrayIndex), 1030, 68); 


      fill(255, 255, 0); 


      text("Theta: " + theArray.get(arrayIndex), 1030, 84); 


      fill(255, 0, 255); 


      text("Low Alpha: " + lalpArray.get(arrayIndex), 1030, 100); 


      fill(0, 255, 255); 


      text("High Alpha: " + halpArray.get(arrayIndex), 1030, 116); 


      fill(255, 128, 128); 


      text("Low Beta: " + lbetArray.get(arrayIndex), 1030, 132); 


      fill(100, 100, 100); 


      text("High Beta: " + hbetArray.get(arrayIndex), 1030, 148); 


      fill(50, 50, 50); 


      text("Low Gamma: " + lgamArray.get(arrayIndex), 1030, 164); 


      fill(25, 50, 100); 


      text("High Gamma: " + hgamArray.get(arrayIndex), 1030, 178); 


      fill(211, 211, 211); 


      text("Raw Eeg: " + valArray.get(arrayIndex), 1030, 194); 


    } 


    else { 


      fill(0); 


      text("Time: " + arrayIndex + "s", 1030, 20); 


      fill(255, 0, 0); 


      text("Poor Signal Level", 1030, 36); 


    } 


  } 


  strokeWeight(1); 


} 


  


JSONObject parseJSON(String in) { 


  JSONObject neuroskyJSON = JSONObject.parse(in); 


  return neuroskyJSON; 


} 

Archive: File:JSONreader.zip

Description

Goes here.... 2-3 Sentences

Demonstration

  • link to running code -or-
  • video of app running (likely a link to video sharing or cloud storage site)

Source Code

  • code listing (readable)
float w = 5;          // weight /pull of the curve
int mouseStartX = 0;  // remember where the mouse is whenever it is pressed
int decay = 10;       // coefficient for decay, 0 = max at each frame, 255 = no decay

void setup() {
  size(500, 500);
  background(0, 0, 0, 255);
}

void draw() {
  fill(0, 0, 0, decay);
  rect(0, 0, width, height);
  float d = random(20, 60);
  fill(random(255), random(255), random(255));
  yinyang(random(width), random(height), d);
}

void yinyang(float x, float y, float d) {

  ellipse(x, y, d, d);

  //bottom of yinyang S curve
  float x1=x,    y1=y;
  float x2=x,    y2=y+d/2;
  float cx1=x+w, cy1=y1;
  float cx2=x+w, cy2=y2;
  stroke(0);
  bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2);

  //top of yinyang S curve
  //x1,y1,x2,cy1 left unchanged
  y2=y-d/2;
  cx1=x-w; 
  cx2=x-w; cy2=y2;
  stroke(0);
  bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
}

void mousePressed() {
  mouseStartX = mouseX;
}

void mouseReleased() {
  float adjustment = map(mouseX-mouseStartX, 0, width, 0, 10);
  w += adjustment;
  println("w set to: " + w);
}

void mouseDragged() {
  float adjustment = map(mouseX-mouseStartX, 0, width, 0, 10);
  text(w+adjustment, mouseX, mouseY-10);
}

void keyPressed() {
  if (keyCode == UP) 
    decay++;
  else if (keyCode == DOWN) 
    decay--;
  println("decay:"  + decay);
}


Notes and Instructions

  • optional
  • or N/A

References

  1. Ref 1
  2. Ref 2
  3. etc.
  4. N/A


Final Project

Description

Our project was creating a logo and animation in blender. Using the blenderguru tutorial that you showed us at the begining of the semester. Then we uploading it into processing and adding an filter,some lines ,scratches and blur(fade) method to the running movie to make it look more old fashion.

Demonstration


Source Code

  • code listing (readable)
/**
 * Speed. 
 *
 * Use the Movie.speed() method to change
 * the playback speed.
 * 
 */

import processing.video.*;

Movie mov;
int w = 120;

float v = 1.0 / 9.0;
float[][] matrix = { {v, v, v }, 
                    { v, v, v }, 
                    { v, v, v } }; 
void setup() {
  size(960, 540);
  background(0);
  mov = new Movie(this, "SpaceVenture LogoConverted.mov");
  mov.loop();
}

void movieEvent(Movie movie) {
  mov.read();  
}

void draw() {    
  image(mov, 0, 0);
  float r=  random(960); 
  float rc=  random(960); 
  float r2 = random(540);
  float r3 = random(10);
  //float newSpeed = map(mouseX, 0, width, 0.1, 2);
  //mov.speed(newSpeed);
  
  stroke(255);
  line(r, 0, r, 540);
  ellipse(rc,r2,r3,r3);
  
  fill(255);
  //text(nfc(newSpeed, 2) + "X", 10, 30); 
 
  // Calculate the small rectangle we will process
 
  int xstart = constrain(mouseX - w/2, 0, mov.width);
  int ystart = constrain(mouseY - w/2, 0, mov.height);
  int xend = constrain(mouseX + w/2, 0, mov.width);
  int yend = constrain(mouseY + w/2, 0, mov.height);
  int matrixsize = 3;
  loadPixels();
  for (int x = xstart; x < xend; x++) {
    for (int y = ystart; y < yend; y++ ) {
      //color c = convolution(x, y, matrix, matrixsize, mov);
      int loc = x + y*mov.width;
      //pixels[loc] = c;
    }
  }
  updatePixels();
 //filter(BLUR,2);
  filter(GRAY); 
}

  
  color convolution(int x, int y, float[][] matrix, int matrixsize, Movie mov)
{
  float rtotal = 0.0;
  float gtotal = 0.0;
  float btotal = 0.0;
  int offset = matrixsize / 2;
  for (int i = 0; i < matrixsize; i++){
    for (int j= 0; j < matrixsize; j++){
      // What pixel are we testing
      int xloc = x+i-offset;
      int yloc = y+j-offset;
      int loc = xloc + mov.width*yloc;
      // Make sure we haven't walked off our image, we could do better here
      loc = constrain(loc,0,mov.pixels.length-1);
      // Calculate the convolution
      rtotal += (red(mov.pixels[loc]) * matrix[i][j]);
      gtotal += (green(mov.pixels[loc]) * matrix[i][j]);
      btotal += (blue(mov.pixels[loc]) * matrix[i][j]);
    }
  }
  // Make sure RGB is within range
  rtotal = constrain(rtotal, 0, 255);
  gtotal = constrain(gtotal, 0, 255);
  btotal = constrain(btotal, 0, 255);
  // Return the resulting color
  return color(rtotal, gtotal, btotal);
  
 
}

Notes and Instructions

  • N/A

References

  1. Ref 1
  2. Ref 2
  3. etc.
  4. N/A
Personal tools