topical media & game development

talk show tell print

graphic-processing-learning-15-example-15-14-example-15-14.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 15-14: "Pointillism"
  
  PImage img;
  int pointillize = 16;
  
  void setup() {
    size(200,200);
    img = loadImage("sunflower.jpg");
    background(255);
    smooth();
  }
  
  void draw() {
    
    // Pick a random point
    int x = int(random(img.width));
    int y = int(random(img.height));
    int loc = x + y*img.width;
    
    // Look up the RGB color in the source image
    loadPixels();
    float r = red(img.pixels[loc]);
    float g = green(img.pixels[loc]);
    float b = blue(img.pixels[loc]);
    noStroke();
    
    // Draw an ellipse at that location with that color
    fill(r,g,b,100);
    // Back to shapes! Instead of setting a pixel, we use the color from a pixel to draw a circle.
    ellipse(x,y,pointillize,pointillize); 
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.