–––
Designing with Code

The real power of using code for data visualization is that you can use data to drive shapes and structures of your choosing. You can often build upon and combine simple structures to create more eleborate ones. We've seen this in our last exampe by reusing line genrating and axis generating functions. In this section let's start by looking at a few simple structures and the forms they can generate simply by scrubbing a few varaibles. Here we use a nested for() loop to create a grid.

void setup() {
  size(800, 800);
}

void draw() { 
  float radius1 = 1;
  float radius2 = 1;
  int objCount = 5;
  int margin = 0;

  background(240, 240, 240);
  rectMode(CENTER);
  ellipseMode(CENTER);
  noStroke();
  fill(20, 20, 20);
  randomSeed(14);
  //frameRate(2);

  for (int i=0; i < objCount; i++) {  
    float remappedX = map(i, 0, (objCount - 1), margin, (width - margin));
    for (int n=0; n < objCount; n++) {
      float randomRadius = random(radius1, radius2);
      float propRadius = randomRadius * ((width - (2*margin))/(objCount -1));
      float remappedY = map(n, 0, (objCount - 1), margin, (height - margin));
      
      ellipse(remappedX, remappedY, propRadius, propRadius);
      //rect(remappedX,remappedY,propRadius,propRadius);
      //arc(remappedX,remappedY,65,64,radians(0),radians(randomRadius * 360));
    }
  }
}
image

This one has a concentric structure. I've also added a useful function where you can save a png by pressing 's' on the keyboard

boolean record;

void setup() {
  size(800, 800);
}

void draw() {
  background(38, 38, 38);
  int objCount = 21;
  translate(width/2, height/2);
  noFill();
  float offset = 33;
  stroke(74, 100, 103);
  strokeWeight(11.1);
  float end1 = 108;
  float end2 = 183;
  randomSeed(19);
  //strokeCap(SQUARE);

  for (int i=0; i< objCount; i++) {
    float end = random(end1, end2);
    if (i > 10) {
      rotate(radians(random(0)));
      arc(0, 0, (i*offset), (i*offset), radians(-121), radians(end));
    }
  }
  // File is saved and 'record' boolean is set back to FALSE
  if (record) {
    saveFrame("####.png"); // change suffix to save as .jpg /.png / .tga /.tif
    record = false;
    println("PNG Saved!");
  }
}

// Use this function to save using a keystroke
void keyPressed() {
  if (key == 's') {
    record = true;
  }
}
image