Pattern Attractors

Hi jakejake,

This looked neat, so I gave it a go here.

I know nothing about Grasshopper, but this Generative Landscapes tutorial laid out the process fairly well. Between that and the steps @jb4x laid out, I had a path forward. To repeat and rephrase what’s already been said:

  • I took an ideal grid of the range ([0 - 1], [0 - 1]).

  • I subdivided that range by a count, storing the result in an array of vectors.

  • I used a sine function to generated an array of vectors.

  • How did I know which distance from the cell to the curve is smallest? Here’s why the sketch is slow, and where there may be room to improve.

    • I wanted the array of vectors for the curve to remain unchanged, so I could keep drawing it. I made a copy of the array; then I sorted the copy according to custom criteria. The point in the curve nearest to the cell would be the first element.
  • The distance info needs to be compared against a maximum possible distance to be converted to a range [0 - 1]. Once that’s through, I can supply that range to lerp or lerpColor, etc.

Sorting an array by a custom criterion requires a bit more gear in Java, but the idea remains the same.

import java.util.Comparator;
import java.util.Arrays;

static void drawEllipses(PGraphics r, 
  PVector[] grid, PVector[] curve, 
  float left, float right, 
  float bottom, float top, 
  float padding, float minScale, 
  color clr0, color clr1, int clrMode, 
  DistSort sorter) {
  /* ... */
  for (int i = 0; i < len; ++i) {
    /* ... */
    Arrays.sort(curve, sorter);
    /* ... */
  }
  /* ... */
}

static class DistSort implements Comparator < PVector > {
  /* ... */
  int compare(PVector a, PVector b) {
     /* Return either -1, 0, or 1. */
  }
}

Hope that helps out. Best.

4 Likes