User Tools

Site Tools


collages

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

collages [2007/08/30 13:53] (current)
Line 1: Line 1:
 +===== Collages =====
  
 +These can be a bit confusing becuase of the way that Processing stores and handles picture data. I learned a few new tricks, and they'​ll show up in the tutorial.
 +
 +Example code:
 +  void setup()
 +  {
 +    PImage original = loadImage("​flower.jpg"​); ​
 +    //Learned something new here: if you want to set your window size to fit a picture, you can't use that picture as a background afterward ​
 +    //​(Processing messes with window size during initialization). If you want to do that, make the window height picture.height-3 (I think).
 +    size(original.width,​original.height);​
 +  ​
 +    try{ wait(250); } catch(Exception e) { System.out.println(e);​ }
 +  ​
 +    System.out.println(width+"​x"​+height);​
 +  ​
 +    //To make a new image from the old one, you have to create an empy picture and use PImage.copy() to get part of the other picture.  ​
 +    PImage firstQuarter = createImage((int)(width/​2),​ (int)(height/​2),​ RGB);
 +    firstQuarter.copy(original,​ 0, 0, (int)(width/​2),​ (int)(height/​2),​ 0, 0, (int)(width/​2),​ (int)(height/​2));​
 +  ​
 +    PImage secondQuarter = createImage((int)(width/​2),​ (int)(height/​2),​ RGB);
 +    secondQuarter.copy(original,​ (int)(width/​2),​ 0, (int)(width/​2),​ (int)(height/​2),​ 0, 0, (int)(width/​2),​ (int)(height/​2));​
 +  ​
 +    PImage thirdQuarter = createImage((int)(width/​2),​ (int)(height/​2),​ RGB);
 +    thirdQuarter.copy(original,​ 0, (int)(height/​2),​ (int)(width/​2),​ (int)(height/​2),​ 0, 0, (int)(width/​2),​ (int)(height/​2));​
 +  ​
 +    PImage fourthQuarter = createImage((int)(width/​2),​ (int)(height/​2),​ RGB);
 +    fourthQuarter.copy(original,​ (int)(width/​2),​ (int)(height/​2),​ (int)(width/​2),​ (int)(height/​2),​ 0, 0, (int)(width/​2),​ (int)(height/​2));​
 +  ​
 +    PImage[] smallImages = new PImage[25];
 +    ​
 +    for(double i = 0; i< 25; i++)
 +    {
 +      double dWidth = .2-(i/125);
 +      double dHeight = .2-(i/125);
 +      smallImages[(int) i] = createImage((int) (dWidth * width), (int) (dHeight * height), RGB);
 +  ​
 +      smallImages[(int) i].copy(original,​ 0, 0, width, height, 0, 0, (int) (dWidth * width), (int) (dHeight * height));
 +    }
 +      ​
 +    firstQuarter.filter(INVERT);​
 +    secondQuarter.filter(GRAY);​
 +    thirdQuarter.filter(POSTERIZE,​ 4);
 +    image(firstQuarter,​ 0, 0);  ​
 +    image(secondQuarter,​ (int)(width/​2),​ 0);
 +    image(thirdQuarter,​ 0, (int)(height/​2));​
 +    tint(0, 153, 204);
 +    image(fourthQuarter,​ (int)(width/​2),​ (int)(height/​2));​
 +    noTint();
 +  ​
 +    int smallerDim;
 +    if(width < height)
 +      smallerDim = width;
 +    else
 +      smallerDim = height;
 +      ​
 +    for(int i = 0; i < 25; i ++)
 +    {
 +      float theta = 2 * PI * i / 25;
 +      double hypotenuse = i * smallerDim / 25;
 +      double dy = hypotenuse * sin(theta) / 2;
 +      double dx = hypotenuse * cos(theta) / 2;
 +      int x = (int) (width / 2 + dx);
 +      int y = (int) (height / 2 + dy);    ​
 +      image(smallImages[24 - i], x, y);
 +    }
 +  }
 +
 +The result:
 +
 +{{Window3.png}}
collages.txt ยท Last modified: 2007/08/30 13:53 (external edit)