Oilspill


  // Oilspill 2.1 (Feb 15 '06)
  //
  // original by Jim Bumgardner
  // Port by Ryan Govostes and Jim Bumgardner
  
  PVector noisePos = new PVector(0,0,0), curPos = new PVector(0,0,0);
  int  frameNbr = 0;
  int  startTime = millis();
  PImage offs;
  
  void setup() {
    size(500, 500);
    colorMode(HSB, 2);
    background(0);
    noiseDetail(1);
  
    offs = createImage(width/2,  height/2, ARGB);
  }
  
  void draw() {
    float d, n;
    curPos.set(noisePos.x,noisePos.y,noisePos.z);
    int w2 = offs.width / 2;
    int h2 = offs.height / 2;
  
    offs.loadPixels();
    
    int offset = 0;
    for (int y = 0; y < offs.height; y ++) {
      curPos.x = noisePos.x;
      for (int x = 0; x < offs.width; x ++) {
          d = dist(x, y, w2, h2) * 0.03;
  
          n = noise(curPos.x, curPos.y, noisePos.z)*0.5;
          
          // determine pixel color
          offs.pixels[offset ++] = color(1 - sin(d + n * 3) % 2, 
                                         sin(d + n * 2) * .5 + 1, 
                                         sq(cos(d + n)) + 1);
        
        curPos.x += 0.0625; // = x/16.0
      }
      curPos.y += 0.0625;
    }
    
    // move through noise space -> animation
    noisePos.add(0.13,0.007,0.01);
    
    offs.updatePixels();
    image(offs,0,0,width,height);
  
    /******** I Used this to measure performance - it prints the average frame rate
              every 100 frames
    
    ++frameNbr;
    if (frameNbr >= 100) {
        int endTime = millis();
        int  elapsed = endTime - startTime;
        float myFrameRateMS = 100 / (float) elapsed;
        println(myFrameRateMS*1000 + " fps");
        startTime = millis();
        frameNbr = 0;
    }
  ******/
  
  }