Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Processing Workshop

Processing Workshop

This is a quick introduction to Processing for the purpose of manipulating images.

Co-Presented with Kyle Oba

Kevin McCarthy

May 12, 2013
Tweet

More Decks by Kevin McCarthy

Other Decks in Programming

Transcript

  1. THANKS • Aaron Padilla - Curator of Education • Susan

    Lai Hipp - Chef • Christine Koroki • Rechung Fujihira / Tony Stanford Tuesday, July 16, 13
  2. Herman Miller's Coworking, Swarming, and the Agile Workplace http://www.hermanmiller.com/content/hermanmiller/english/research/research-summaries/coworking-swarming-and-the-agile-workplace.html Many

    speculate that, with people no longer needing to be in the same place at the same time to share information and ideas, the office building as we know it is destined for obsolescence. Tuesday, July 16, 13
  3. http://www.hermanmiller.com/content/hermanmiller/english/research/research-summaries/coworking-swarming-and-the-agile-workplace.html A recent report from Gartner, Inc., finds knowledge work

    becoming steadily less routine and increasingly characterized by “volatility,” “hyper-connectedness,” and “swarming — a work style characterized by a flurry of collective activity by anyone and everyone conceivably available and able to add value.” ALTERNATIVE Tuesday, July 16, 13
  4. http://www.hermanmiller.com/content/hermanmiller/english/research/research-summaries/coworking-swarming-and-the-agile-workplace.html In contrast to traditional corporate teams — composed of

    people who work together regularly, often in the same location and under the same manager — swarms typically encompass a diverse group of professionals and experts who may not have worked together before and probably won’t work as a team again in the future. SWARMS Tuesday, July 16, 13
  5. http://www.hermanmiller.com/content/hermanmiller/english/research/research-summaries/coworking-swarming-and-the-agile-workplace.html Swarms form quickly to attack a problem or opportunity,

    then dissipate as their members are pulled into other ad hoc groups addressing other issues. OPPORTUNITY Tuesday, July 16, 13
  6. ...a group’s successful performance was not strongly related to the

    average intelligence of its members, but rather to the way its members interacted and, in particular, to the even distribution of individual contributions to the group effort. CONTRIBUTION Tuesday, July 16, 13
  7. Groups that did well were those that considered ”multiple perspectives”...

    “In groups where the conversation was more evenly distributed, where you had better participation—and more equal participation among all of the group members—the groups were more collectively intelligent.” PARTICIPATION Tuesday, July 16, 13
  8. Same-time, same-place can spark a powerful source of collaborative innovation

    and meaning for people. SHARED MEANING Tuesday, July 16, 13
  9. Prerequisites • Processing downloaded & installed (2.0beta) • Images! •

    GitHub https://github.com/OutOfOffice https://github.com/OutOfOffice/ProcessingWorkshop Tuesday, July 16, 13
  10. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  11. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  12. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  13. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  14. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  15. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  16. Consider this rectangle void setup() { size(500, 300); background(255); fill(0);

    int x = 100; int y = 100; int rectWidth = 300; int rectHeight = 100; rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  17. draw() is a loop int rectWidth, rectHeight; int delta; void

    setup() { size(200, 200); fill(237, 33, 124); // Pink! rectWidth = 100; rectHeight = 100; delta = 1; } void draw() { int x = 0; int y = 50; if (rectWidth >= width) { delta = -1; } else if (rectWidth <= 0) { delta = 1; } rectWidth = rectWidth + delta; background(255); rect(x, y, rectWidth, rectHeight); } https://github.com/OutOfOffice/ProcessingWorkshop/tree/master/examples/Rectangle Tuesday, July 16, 13
  18. draw() is a loop int rectWidth, rectHeight; int delta; void

    setup() { size(200, 200); fill(237, 33, 124); // Pink! rectWidth = 100; rectHeight = 100; delta = 1; } void draw() { int x = 0; int y = 50; if (rectWidth >= width) { delta = -1; } else if (rectWidth <= 0) { delta = 1; } rectWidth = rectWidth + delta; background(255); rect(x, y, rectWidth, rectHeight); } https://github.com/OutOfOffice/ProcessingWorkshop/tree/master/examples/Rectangle Tuesday, July 16, 13
  19. draw() is a loop int rectWidth, rectHeight; int delta; void

    setup() { size(200, 200); fill(237, 33, 124); // Pink! rectWidth = 100; rectHeight = 100; delta = 1; } void draw() { int x = 0; int y = 50; if (rectWidth >= width) { delta = -1; } else if (rectWidth <= 0) { delta = 1; } rectWidth = rectWidth + delta; background(255); rect(x, y, rectWidth, rectHeight); } https://github.com/OutOfOffice/ProcessingWorkshop/tree/master/examples/Rectangle Tuesday, July 16, 13
  20. if-then-else int rectWidth, rectHeight; int delta; void setup() { size(200,

    200); fill(237, 33, 124); // Pink! rectWidth = 100; rectHeight = 100; delta = 1; } void draw() { int x = 0; int y = 50; if (rectWidth >= width) { delta = -1; } else if (rectWidth <= 0) { delta = 1; } rectWidth = rectWidth + delta; background(255); rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  21. if-then-else int rectWidth, rectHeight; int delta; void setup() { size(200,

    200); fill(237, 33, 124); // Pink! rectWidth = 100; rectHeight = 100; delta = 1; } void draw() { int x = 0; int y = 50; if (rectWidth >= width) { delta = -1; } else if (rectWidth <= 0) { delta = 1; } rectWidth = rectWidth + delta; background(255); rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  22. if-then-else int rectWidth, rectHeight; int delta; void setup() { size(200,

    200); fill(237, 33, 124); // Pink! rectWidth = 100; rectHeight = 100; delta = 1; } void draw() { int x = 0; int y = 50; if (rectWidth >= width) { delta = -1; } else if (rectWidth <= 0) { delta = 1; } rectWidth = rectWidth + delta; background(255); rect(x, y, rectWidth, rectHeight); } Tuesday, July 16, 13
  23. Variables void setup() { int pointCount = 80; float radiusRatio

    = 0.2; ... float radOut = height/2.3; float radIn = radOut*radiusRatio; star(pointCount, radIn, radOut); } Tuesday, July 16, 13
  24. Variables void setup() { int pointCount = 80; float radiusRatio

    = 0.2; ... float radOut = height/2.3; float radIn = radOut*radiusRatio; star(pointCount, radIn, radOut); } Tuesday, July 16, 13
  25. Variables void setup() { int pointCount = 80; float radiusRatio

    = 0.2; ... float radOut = height/2.3; float radIn = radOut*radiusRatio; star(pointCount, radIn, radOut); } Tuesday, July 16, 13
  26. Functions void setup() { int pointCount = 80; float radiusRatio

    = 0.2; ... float radOut = height/2.3; float radIn = radOut*radiusRatio; star(pointCount, radIn, radOut); } Tuesday, July 16, 13
  27. Functions void setup() { int pointCount = 80; float radiusRatio

    = 0.2; ... float radOut = height/2.3; float radIn = radOut*radiusRatio; star(pointCount, radIn, radOut); } Tuesday, July 16, 13
  28. Functions void setup() { int pointCount = 80; float radiusRatio

    = 0.2; ... float radOut = height/2.3; float radIn = radOut*radiusRatio; star(pointCount, radIn, radOut); } Tuesday, July 16, 13
  29. WTF!!!! void star(int pointCount, float innerRadius, float outerRadius) { float

    theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  30. sin, cos, radius, etc. x = radOut x = 0.81*radIn

    y = -0.58*radIn y = 0 x = cos(theta)*radIn y = sin(theta)*radIn Tuesday, July 16, 13
  31. Drawing a Star void star(int pointCount, float innerRadius, float outerRadius)

    { float theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } theta sin, cos nonsense Tuesday, July 16, 13
  32. Drawing a Star void star(int pointCount, float innerRadius, float outerRadius)

    { ... for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } ... } Tuesday, July 16, 13
  33. If Statement void star(int pointCount, float innerRadius, float outerRadius) {

    float theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  34. If Statement void star(int pointCount, float innerRadius, float outerRadius) {

    float theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  35. If Statement void star(int pointCount, float innerRadius, float outerRadius) {

    float theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  36. Looping void star(int pointCount, float innerRadius, float outerRadius) { float

    theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  37. Looping void star(int pointCount, float innerRadius, float outerRadius) { float

    theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  38. Looping void star(int pointCount, float innerRadius, float outerRadius) { float

    theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i<pointCount; i++) { for (int j=0; j<2; j++) { tempRadius = innerRadius; // true if j is even if (j%2==0) { tempRadius = outerRadius; } x = cos(theta)*tempRadius; y = sin(theta)*tempRadius; vertex(x, y); theta += thetaRot; } } endShape(CLOSE); } Tuesday, July 16, 13
  39. img.pixels = [ color(0, 0, 0), color(0, 0, 0), color(55,

    135, 214), color(253, 229, 155) ... ]; Tuesday, July 16, 13
  40. void setup() { PImage img = loadImage("macarons.jpg"); img.loadPixels(); size(img.width, img.height);

    int colWidth = 10; int rowHeight = 10; int numCols = int(width/colWidth); int numRows = int(height/rowHeight); for (int row=0; row<numRows; row++) { for(int col=0; col<numCols; col++) { int pixelIdx = row*rowHeight*width + col*colWidth; fill(img.pixels[pixelIdx]); rect(col*colWidth, row*rowHeight, colWidth, rowHeight); } } } Simple image input Tuesday, July 16, 13
  41. void setup() { ... int numMovers = numCols*numRows; startColors =

    new int[numMovers]; int pixelIdx, colorIdx; for (int row=0; row<numRows; row++) { for(int col=0; col<numCols; col++) { pixelIdx = row*rowHeight*width + col*colWidth; colorIdx = row*numCols + col; startColors[colorIdx] = img.pixels[pixelIdx]; } } ... // Draw naively sorted colors: sortedColors = sort(startColors); drawColors(sortedColors); } Sorted image input Tuesday, July 16, 13
  42. More Image Functions • color - the datatype • color()

    - creates a color • red(), green(), blue(), alpha() - returns it • lerpColor() - moves from one to another • PImage - use this for images • loadPixels() - for image or entire display • pixels[] - get at the pixels of image or display Tuesday, July 16, 13
  43. More Functions • map • lerp • mouse stuff •

    key press stuff • arc, ellipse, line, point, quad, rect, triangle • text, font stuff • noise, random Tuesday, July 16, 13
  44. Other • Colors File > Examples... > Basics > Color

    > ColorVariables • Images File > Examples... > Basics > Image > Pointilism • Text File > Examples... > Basics > Typography > Letters Tuesday, July 16, 13
  45. Other • Arrays File > Examples... > Basics > Arrays

    > Array • ArrayList File > Examples... > Topics > Advanced Data > ArrayListClass • HashMap File > Examples... > Topics > Advanced Data > HashMapClass Tuesday, July 16, 13
  46. Survey • pass it out • fill it out •

    return it Tuesday, July 16, 13