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.

Sunday, October 7, 2018

Processing Experiment: Seeing Stars

We were tasked with choosing an example code within Processor to experiment with and manipulate. I chose the Star example to work with. When you run the code, three stars appear on the screen each with a different number of points.  My goal with this experiment is to change around the variables to see if I can manipulate the number of points on the stars, the rotation pattern of each individual star as well as the background color.

Original Effect:



My results:




my code:

/**
 * Star
 *
 * The star() function created for this example is capable of drawing a
 * wide range of different forms. Try placing different numbers into the
 * star() function calls within draw() to explore.
 */

void setup() {
  size(640, 360);
}

void draw() {
  background(20, 8, 900);

  pushMatrix();
  translate(width*0.2, height*0.5);
  rotate(frameCount / 200.0);
  star(100, 3, 5, 70, 11);
  popMatrix();

  pushMatrix();
  translate(width*0.5, height*0.5);
  rotate(frameCount / 500.0);
  star(100, 0, 30, 100, 4);
  popMatrix();

  pushMatrix();
  translate(width*0.8, height*0.5);
  rotate(frameCount / -100.0);
  star(100, 0, 30, 250, 100);
  popMatrix();
}

void star(float x, float y, float radius1, float radius2, int npoints) {
  float angle = TWO_PI / npoints;
  float halfAngle = angle/2.0;
  beginShape();
  for (float a = 0; a < TWO_PI; a += angle) {
    float sx = x + cos(a) * radius2;
    float sy = y + sin(a) * radius2;
    vertex(sx, sy);
    sx = x + cos(a+halfAngle) * radius1;
    sy = y + sin(a+halfAngle) * radius1;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}

No comments:

Post a Comment