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.
Showing posts with label Processing. Show all posts
Showing posts with label Processing. Show all posts

Friday, October 5, 2018

Changing schemes, a homage to Albers

After opening up processing and exploring the various examples provided, I stumbled upon one called “Color Variables”. It reminded me of my Albers project from last year and as I started to poke around the code I had an idea. I wanted to get a better grasp of event triggers with Processing—specifically using if statements and loops. At first, I couldn’t seem to get the code to work. Then I realized that I needed to use void draw() to run a constant loop, otherwise the if statement I wrote would never be checked after initialization. Below is my code, it uses a simple integer binary (see void mouseClicked) to check if the mouse has clicked or not, and changes the color variables accordingly. I also changed one of the shapes by changing 'rect' to 'ellipse'.

Before. This is what the original code did.


After! This is what edited my code does.

/**
 * Color Variables (Homage to Albers).
 *
 * This example creates variables for colors that may be referred to
 * in the program by a name, rather than a number.
 *
 * Edited by Jacob Elias as an exploration in Processing.
 */
int toggle = 0;
color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
color outside = color(153, 51, 0);


void setup(){
  size(640, 360);
  noStroke();
  background(51, 0, 0);
}
void draw(){
if (toggle == 1) {
    inside = color(#057DBA);
    middle = color(#009BE6);
    outside = color(#0057E8);
    background (#18639D);
} else {
    inside = color(204, 102, 0);
    middle = color(204, 153, 0);
    outside = color(153, 51, 0);
    background (51, 0, 0);
}
 
 //These statements are equivalent to the statements above.
 //Programmers may use the format they prefer.
pushMatrix();
translate(80, 80);
fill(outside);
ellipse(100, 100, 200, 200);
fill(middle);
ellipse(100, 100, 145, 145);
fill(inside);
ellipse(100, 100, 80, 80);
popMatrix();
pushMatrix();
translate(360, 80);
fill(inside);
rect(0, 0, 200, 200);
fill(outside);
rect(40, 60, 120, 120);
fill(middle);
rect(60, 90, 80, 80);
popMatrix();
  }
 
 void mouseClicked () {
  if (toggle == 0) {
    toggle = 1;
  } else {
  toggle = 0;}
  }

Sunday, April 3, 2016

Processing: Making MousePress, DirectionalLight More Magical

MousePress

Knowing that I wanted to experiment with interactions that involve visual feedback throughout the quarter, I chose the Processing example called MousePress. As the program runs, the user’s moving cursor leaves behind a trail of uniform, black crosses. However, as the mouse is pressed, the crosses left by the cursor are white.


In my experimentation for this assignment, I kept in mind the imagery of “fairy dust” as my goal for the new visual output. As the program runs, the cursor no longer leaves behind a constant stream of crosses unless the mouse is pressed. However, this does not mean that the draw() function is not running the entire time my mouse moves. Rather, the draw() function simply has noStroke() unless the mouse has been pressed. I also altered the code so that the visual output was no longer uniform. By randomizing the colors, stroke weight, stroke length, and opacity, the output becomes a series of diverse crosses that stream out of the cursor’s path. I accomplished this by defining the range of random RGB+Opacity values for stroke color between 0 and 255, and maintaining the cross shape by defining a random, but uniform width "int r" for each cross drawn.



I had hoped to complete the effect by making these crosses “twinkle,” or at least appear askew in different angles, but I was unsuccessful in my experimentation. I would be curious to learn how to randomly rotate the output of the draw() function without completely upsetting the canvas’s axis. Eventually, I would also like to be able to leave a stream of drawings that would continue to animate even after being drawn.

Original code of example is as follows:

/**
 * Mouse Press. 
 * 
 * Move the mouse to position the shape. 
 * Press the mouse button to invert the color. 
 */

void setup() {
  size(640, 360);
  noSmooth();
  fill(126);
  background(102);
}

void draw() {
  if (mousePressed) {
    stroke(255);
  } else {
    stroke(0);
  }
  line(mouseX-66, mouseY, mouseX+66, mouseY);
  line(mouseX, mouseY-66, mouseX, mouseY+66); 
}

My code for "fairy dust" is as follows:

void setup() {
  
  size(640, 640);
  smooth();
  frameRate(40);
  fill(126);
  background(40);
}

void draw() {

  if (mousePressed) {
    strokeWeight(random(0,20));
    stroke(random(0,255),random(0,255),random(0,255), random(0,200));
  
} else {
    noStroke();
  }
  int r = int(random(60));
  line(mouseX-r, mouseY, mouseX+r, mouseY);
  line(mouseX, mouseY-r, mouseX, mouseY+r); 

}

Directional Light

For my second experiment, I explored the lighting examples and borrowed elements from the Mixture example to use in the Directional code. 


This was mainly because I was fascinated by how light reflected off of the rotating surfaces present in Mixture, as opposed to the static spheres in Directional, but I still wanted to focus on one light source rather than the mix of colored lights. To accomplish this, I replaced one of the spheres in the Directional code with a box(), (which would reflect light differently,) and then pasted this bit of code from Mixture:

  rotateY(map(mouseX, 0, width, 0, PI));
  rotateX(map(mouseY, 0, height, 0, PI));

This makes the x-axis upon which both shapes rest (as well as the shapes themselves) rotate according to the position of the cursor. The unintentional (but pleasantly surprising) result ended up appearing as though the sphere was orbiting around a rotating cube. I also added some visual pizzazz by having the light change color according to the direction of the light, AKA the cursor’s X and Y position. This was achieved by defining directionalLight as follows:

directionalLight(255-mouseX, 200, 255-mouseY, -dirX, -dirY, -1); 


In future experimentation, I would like to see how I could use the directional light to cast shadows from one shape onto another. That way, the output would look even more like orbiting planets or moons. I recognize that a similar effect could have also been achieved by having the light source and direction stay constant, rather than following the cursor, but I still wanted to experiment with the moving directional light source for this example.

Original code:

/**
 * Directional. 
 * 
 * Move the mouse the change the direction of the light.
 * Directional light comes from one direction and is stronger 
 * when hitting a surface squarely and weaker if it hits at a 
 * a gentle angle. After hitting a surface, a directional lights 
 * scatters in all directions. 
 */

void setup() {
  size(640, 360, P3D);
  noStroke();
  fill(204);
}

void draw() {
  noStroke(); 
  background(0); 
  float dirY = (mouseY / float(height) - 0.5) * 2;
  float dirX = (mouseX / float(width) - 0.5) * 2;
  directionalLight(204, 204, 204, -dirX, -dirY, -1); 
  translate(width/2 - 100, height/2, 0); 
  sphere(80); 
  translate(200, 0, 0); 
  sphere(80); 
}

New Draw() of Directional Color Code:

void draw() {
  noStroke(); 
  background(0); 
  float dirY = (mouseY / float(height) - 0.5) * 2;
  float dirX = (mouseX / float(width) - 0.5) * 2;
  directionalLight(255-mouseX, 200, 255-mouseY, -dirX, -dirY, -1); 
  translate(width/2 - 100, height/2, 0); 
  rotateY(map(mouseX, 0, width, 0, PI));
  rotateX(map(mouseY, 0, height, 0, PI));
  box(80); 
  translate(200, 0, 0); 
  sphere(80); 
}

Thanks for reading!

Friday, April 25, 2014

Webcam Glitch Art Processing Sketch

I have been interested in glitch art for a while, and love experimenting with video. I used this sketch as an opportunity to explore both of those. But I wanted it to be interactive as well. Therefore, I decided to use the participant's mouse position as a way to make it more interactive. As the user moves their mouse, it changes the tint color of the video, as well as the size/position of the video. I am interested in discovering new ways to alter/distort video and create more interactivity with it.



import processing.video.*;
Capture cam;
void setup() {
  size(800, 800);
  cam = new Capture(this,300,300,15);
  background(255);
  String[] cameras = Capture.list();
   
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
     
    // Initialize Camera
    cam = new Capture(this, cameras[0]);
    cam.start();    
  }     
}
void draw() {
  if (cam.available() == true) {
    cam.read();
  }
   
   
    // Tinting using mouse location
  tint(255 - mouseY,255 - mouseX,255);
  // Multiple Cam
  image(cam,0,0,mouseX,mouseY);
  image(cam,20,20,mouseX,mouseY);
  image(cam,30,30,mouseX,mouseY);
  image(cam,200,200,mouseX,mouseY);
  image(cam,220,210,mouseX -50 ,mouseY - 100);
  image(cam,330,240,mouseX -50 ,mouseY - 100);
  image(cam,335,245,mouseX -10 ,mouseY - 90);
  image(cam,340,250,mouseX -10 ,mouseY - 100);
    image(cam,200,200,mouseX,mouseY);
  image(cam,620,510,mouseX -50 ,mouseY - 100);
  image(cam,630,540,mouseX -50 ,mouseY - 100);
  image(cam,635,545,mouseX -10 ,mouseY - 90);
  image(cam,640,550,mouseX -10 ,mouseY - 100);
   
  
}