Curvature from noise

by tsulej

spr00F52545

In last article I’ve made the research about vector fields and movement based on it. This time I’m going to treat values from noise (and other functions) as acceleration.

Instead of reading an angle from noise and apply step to my drawing agents I’ll be changing angle itself and then use it in drawing step.

The code

This time drawing code looks like this. Marked line is responsible for modification of the angle.

//drawing agent
class Agent {
  PVector pos; // position of the agent
  float angle; // current angle of the agent

  void update() {
    // modify position using current angle
    pos.x += cos(angle);
    pos.y += sin(angle);

    // get point coordinates
    float xx = map(pos.x, 0, width, -1, 1);
    float yy = map(pos.y, 0, height, -1, 1);

    PVector v = new PVector(xx, yy);

    // modify an angle using noise information
    angle += map( noise(v.x, v.y), 0, 1, -1, 1);
  }
}

// all agents in the list
ArrayList<Agent> agents = new ArrayList<Agent>();

void setup() {
  size(800, 800);
  background(240);
  stroke(20, 10);
  smooth(8);
  strokeWeight(0.7);

  // initialize in random positions
  for (int i=0; i<5000; i++) {
    Agent a = new Agent();
    float posx = random(200, 600);
    float posy = random(200, 600);
    a.pos = new PVector(posx, posy);
    a.angle = random(TWO_PI);
    agents.add(a);
  }
}

float time = 0;
void draw() {
  for (Agent a : agents) {
    pushMatrix();
    // position
    translate(a.pos.x, a.pos.y);
    // rotate
    rotate(a.angle);
    // paint
    point(0, 0);
    popMatrix();
    // update
    a.update();
  }
  time += 0.001;
}

spr002CFCD8

Scaling

After scaling and shifting noise I got more interesing patterns.

void update() {
  // modify position using current angle
  pos.x += cos(angle);
  pos.y += sin(angle);

  // get point coordinates
  float xx = 3 * map(pos.x, 0, width, -1, 1);
  float yy = 3 * map(pos.y, 0, height, -1, 1);

  PVector v = new PVector(xx, yy);
  v.add(new PVector(5,-3));

  // modify an angle using noise information
  angle += 3 * map( noise(v.x, v.y), 0, 1, -1, 1);
}

Applying variations

The other results can be achieved by using variations and curves described in previous articles: Folds  and Drawing vector field. Just copy them at the end of the file. Change marked line from the previous code for following code for example:

PVector v = swirl(new PVector(xx, yy),1);

spr00760B0A

Other variations produce different results and patterns.

Or something like this:

float n1 = noise(xx+5,yy-3)-0.55;

PVector vc = kampyle(n1);
PVector v = sinusoidal(vc,1);
v.mult(5);
v.add(new PVector(5,-3));

spr00363AC2

Time

As previously we can add time to get noise change during drawing. It gives nice, tissue like, objects.

angle += (3+time) * map( noise(v.x, v.y, time), 0, 1, -1, 1);

Forced movement

Another method is to add some constant value to x position in order to force movement of the points towards the right side.

Lets position all points on the left side during initialization and make number of point smaller.

// initialize in random positions
for (int i=0; i<2000; i++) {
  Agent a = new Agent();
  float posx = 100;
  float posy = random(200, 600);
  a.pos = new PVector(posx, posy);
  a.angle = random(TWO_PI);
  agents.add(a);
}

Then force movement

void update() {
  // modify position using current angle
  pos.x += cos(angle)+0.1;
  pos.y += sin(angle);

  // get point coordinates
  float xx = 3 * map(pos.x, 0, width, -1, 1);
  float yy = 3 * map(pos.y, 0, height, -1, 1);

  PVector v = new PVector(xx,yy);
  v.add(new PVector(5,-3));

  // modify an angle using noise information
  angle += (5+time) * map( noise(v.x, v.y), 0, 1, -1, 1);
}

spr004CD988

Using some previous techniques (variations and curves) I got also such results

Or something like this.

Play and enjoy 🙂

The end

Questions? generateme.blog@gmail.com or 

Blogs:

 

Advertisements