Advertisement
xeromino

blob

Apr 19th, 2017
642
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Blob[] blobs = new Blob[30];
  2. float theta;
  3. int frms = 120;
  4.  
  5. void setup() {
  6.   size(540, 540);
  7.   //colorMode(HSB,360,100,100);
  8.   for (int i=0; i<blobs.length; i++) {
  9.     int d = i%2==0?1:-1;
  10.     float offSet = TWO_PI/blobs.length*i;
  11.     blobs[i] = new Blob(random(width), random(height),offSet);
  12.   }
  13. }
  14.  
  15. void draw() {
  16.   background(34);
  17.   for (int i=0; i<blobs.length; i++) {
  18.     blobs[i].update();
  19.   }
  20.   loadPixels();
  21.   for (int x=0; x<width; x++) {
  22.     for (int y=0; y<height; y++) {
  23.       int index = x + y * width;
  24.       float sum = 0;
  25.       for (Blob b : blobs) {
  26.         float d = dist(x, y, b.pos.x, b.pos.y);
  27.         sum += b.r/d*20;
  28.       }
  29.       pixels[index] = color(sum-50);
  30.     }
  31.   }
  32.   updatePixels();
  33.   theta += TWO_PI/frms;
  34.   //if (frameCount<frms) saveFrame("image-###.gif");
  35. }
  36.  
  37. class Blob {
  38.  
  39.   PVector orig;
  40.   PVector pos;
  41.   PVector vel;
  42.   float r;
  43.   float d;
  44.   float offSet;
  45.  
  46.   Blob(float x, float y, float _offSet) {
  47.     orig = new PVector(x, y);
  48.     pos = new PVector(0, 0);
  49.     //vel = PVector.random2D();
  50.     //vel.mult(random(2, 5));
  51.     r = random(10, 100);
  52.     //d = random(50, 200);
  53.     offSet = _offSet;
  54.   }
  55.  
  56.   void update() {
  57.     //pos.add(vel);
  58.     d = map(pow(sin(theta+offSet*3),1),-1,1,50,200);
  59.     //d = map(pow(sin(theta+offSet*3),3),0,1,50,200);
  60.     pos.x = width/2 + cos(offSet)*d;
  61.     pos.y = height/2 + sin(offSet)*d;
  62.   }
  63. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement