As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Wednesday, April 10, 2013

Dan | Stephen _ Processing Sketch




 An exploration of a modifed version of the CharacterStrings example from Processing 2.0b8. This program accepts keyboard inputs and changes the background based off of the char value. The string shown on screen appends the key pressed to the end of it and displays the length of the string. 



/**
 * Characters Strings. 
 * This is a modifed version of the CharacterStrings example from Processing 2.0b8
 * This program accepts keyboard inputs and changes the background based off of the
 * char value. The string shown on screen appends the key pressed to the end of it 
 * and displays the length of the string. 
 */

char letter;
String words = "Begin...";
int[] rgbColor;
int counter;

void setup() {
  int counter = 0;
  size(720, 360);
  rgbColor = new int[3];

  // Create the font
  textFont(createFont("Helvetica", 40));
}

void draw() {
  colorMode(RGB);
  background(rgbColor[0], rgbColor[1], rgbColor[2]); // Background colors change based on char values of keyboard inputs.

  // Draw the letter to the center of the screen
  textSize(14);
  text("Click on the program, then type to add to the String", 50, 50);
  text("As you type, the background will change colors (loosely) based on the value of the key you press.", 50, 70);
  text("Current key: " + letter, 50, 90);
  text("Key value: " + letter*1, 50, 110);
  text("Current background color is: (" + rgbColor[0] + " , " + rgbColor[1] + " , " + rgbColor[2]+ ")" , 50, 130);
  text("The String is " + words.length() +  " characters long", 50, 150);
  
  textSize(36);
  text(words, 50, 180, 540, 300);
}

void keyPressed() {
  // The variable "key" always contains the value 
  // of the most recent key pressed.

  if ((key >= 32 && key <= 255)) {
    letter = key;
    
    //counter is used to indicate R, G, or B for the color of the background.
    
    if (counter == 3) {
      counter = 0;
    }
    
    rgbColor[counter] = (key * words.length()) % 255; //This equation is used to create a more drastic color change
    words = words + key;
    
    // Write the letter to the console
    println(key);
   counter++;
  }





An exploration of the Hue example in processing to make the color blocks shorter, and shift in a gradient of the same hue as the background color.


/**
 * Hue. 
 * 
 * Hue is the color reflected from or transmitted through an object 
 * and is typically referred to as the name of the color (red, blue, yellow, etc.) 
 * Move the cursor vertically over each bar to alter its hue. 
 */
 
int barWidth = 91;
int lastBar = 100;

void setup() 
{
  size(640, 360);
  colorMode(RGB, height, height, height);  
  //noStroke();
  background(700);
}

void draw() 
{
  int whichBar = mouseX / barWidth;
  if (whichBar != lastBar) {
    int barX = whichBar * barWidth;
    fill(mouseX, height, height);
    rect(barX, 200, barWidth, height);
    lastBar = whichBar;
  }
}



No comments:

Post a Comment