🔍

generative shape drawing in Processing


PGraphics paintlayer;
PVector[] nodes;
boolean curved = false;
 
void setup(){

  colorMode(HSB);
  // hue / sat / bri
  size(600,600);
  background(255);
  
  paintlayer = createGraphics(width,height);
  paintlayer.colorMode(HSB);
  
  // initalize nodes // vary with amount here!
  nodes = new PVector[33];
  for(int i=0; i<nodes.length; i++){
    nodes[i] = new PVector();
  }
  
}


void draw(){

  // calculate all positions of all nodes -----------
  
  float abit = TWO_PI/nodes.length;
  
  for(int i=0; i<nodes.length; i++){
  
    float offx = sin( millis()*.00012 )*168;
    float offy = cos( millis()*.000123 )*160;
    
     float x = sin(abit*i)*110+ offx;
     float y = cos(abit*i)*110+ offy;
     
     x += sin(millis()*.00051+ i*2.2)*233;
     y += cos(millis()*.000513+ i*1.2)*222;
     
     nodes[i].x = x;
     nodes[i].y = y;
    
  }
  
      
   // draw shape by nodes -----------
  
  paintlayer.beginDraw();
  paintlayer.noFill();
  paintlayer.fill(255,4);
   paintlayer.colorMode(HSB);
  
   float hue = (sin(millis()*.0001)+1)*127;
   float sat = 222;
   float bri = 222;
   paintlayer.stroke(hue,sat,bri,42);
   paintlayer.strokeWeight(2);
  
  paintlayer.translate(paintlayer.width/2,paintlayer.height/2);
  paintlayer.beginShape();
  
  
  for(int i=0; i<nodes.length ; i++){
 
       paintlayer.vertex(nodes[i].x,nodes[i].y);
   
  }
   
   paintlayer.endShape(CLOSE);
   paintlayer.endDraw();
  
  
  // draw the painted layer itself
  image(paintlayer,0,0);
  
  
}


void mousePressed(){

    // create special effect ;)
    paintlayer.beginDraw();
    
    paintlayer.filter(BLUR,2);
    paintlayer.filter(INVERT);
    paintlayer.filter(BLUR,2);

    paintlayer.endDraw();
}