Darkness in the Darkness

Darkness in the Darkness

For this exercise, I have utilized the Geomerative library to trace the points within the text string, inspired from Aaron’s repository on geomerative text. Using this library, I wanted to show the general tracing of one point to another in a sorted order by drawing a line from i to i+1 in a loop – which created a mysterious illusion as if it is a handwriting.

To add some tweak, I have made each point as particles that starts off at random positions on the screen that eventually reaches its original position in the text. Also, the frameRate changes depending on the location of the cursor in respect to the X-axis.

The following are the source code and a short recording of the exercise:

import geomerative.*;
int iterator, count;
color c;
RFont font;
RPoint[] pnts;
Particle[] particles;

float w, h, mapVal;

void setup() {
  size(640, 480);

  RG.init(this);

  // set the font, the size, and left, center, or right adjusted
  font = new RFont("Franklin Goth Ext Condensed.ttf", 150, RFont.CENTER);
  
  // get the points along a String
  pnts = getPoints("DARKNESS");
  
  particles = new Particle[pnts.length];
  for (int i=0; i<particles.length; i++) {
    particles[i] = new Particle(random(-width/2, width/2), random(-height, height), pnts[i].x, pnts[i].y);
  }
  
  w = width/2;
  h = height/1.5;
  
  count = 1;  
  c = color(random(0,255), random(0,255), random(0,255));
  
  noFill();
  strokeWeight(3);
}

void draw() {
  mapVal = map(mouseX, 0, width, 10, 120);
  frameRate(mapVal);
  iterator = count % (particles.length-1);
  if (iterator == 0) {
      c = color(random(50,255), random(50,255), random(50,255));
    }
  
  fill(0, 11);
  noStroke();
  rect(0, 0, width, height);
  pushMatrix();
    translate(w, h);
    stroke(c);
    fill(c);
    for (int i=0; i<particles.length; i++) {
      particles[i].update();
    }
    line(particles[iterator].x, particles[iterator].y, particles[iterator+1].x, particles[iterator+1].y);
    count++;
  popMatrix();
}

// function that returns an array of RPoints based on a string
RPoint[] getPoints(String str) {
  // change this number to change the resolution of points outlining the circle
  RCommand.setSegmentLength(5);
  RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
  RGroup grp;
  grp = font.toGroup(str);
  grp = grp.toPolygonGroup();
  return grp.getPoints();
}
class Particle {
  float x, y, destX, destY, xSpeed, ySpeed;
  float dirX, dirY, rand;
  color c;
  
  Particle(float _x, float _y, float _destX, float _destY) {
    x = _x;
    y = _y;
    destX = _destX;
    destY = _destY;
    xSpeed = 0;
    ySpeed = 0;
  }
  
  void update() {
    dirX = destX - x;
    dirY = destY - y;
    xSpeed = (dirX*0.003);
    ySpeed = (dirY*0.003);

    xSpeed *= 0.95;
    ySpeed *= 0.95;
    x += xSpeed;
    y += ySpeed;
  }
}

 

Leave a Reply