Week 4: Generative Text

 

This was a disaster to figure out, but it was worth it at the end. (I had a very long victory dance).

My initial idea is that i wanted something on an animated text, with a ball moving around. I drew a sketch on procreate to illustrate:

 

My first of many hurdles was getting a font of mine to work. I kept getting errors, (and sometimes processing would display the text different than i expected).  Next, I created two of the text, and placed them away from each other to mirror the illustration I had in mind. After trying and trying to figure out how to get the ball to slide like I did in my illustration, I decided to try something else. I used the example shown (The Bubble One) in class to create circles in each point,  and wanted to print them out one by one so that the text could be drawn. After spending a full day on this (no really, a full day), I found my mistake -I had accidentally called noLoop();.

After that, it was pretty smooth. I figured out my speed, how I wanted it to look, as well as how to toggle the colour to make it fade from black to red back and forth.

import geomerative.*;
import java.util.concurrent.TimeUnit;
RFont font; 
RPoint[] pnts;
float xValue = 0;
float yValue = 0;
int a = 175;
int i = 0;
int previousTime = 0;
float timePassed = 0.1;
int r = 255;
boolean b = true;

void setup(){
  frameRate(120);
  background(255);
  size (500, 500);
  RG.init(this);
  // set the font, the size, and left, center, or right adjusted
  font = new RFont("LeckerliOne-Regular.ttf", 150, RFont.CENTER);
  
  // get the points along a String
  pnts = getPoints("Media");
  System.out.println(pnts);
    
  noFill();
  //noLoop();
  stroke(0,100);
  
}
void update () {
  //stroke( 0, 0, 0, a);
  noStroke();
  fill( r, 0, 0);
  circle(xValue, yValue, 6);
}

void draw() {
  int time = -1;
  pushMatrix();
  translate(width/2, height/1.5);
  if ( millis() > previousTime + timePassed){
     previousTime= millis();
     //println("it works");
    if ( i <pnts.length ){
        update();
        if ( r >= 0 && b == true){
          r -= 1; 
          b = true; 
        }
        else if (r == 225 && b == false){
          r -= 1; 
          b = true; 
        }
        else {
          r +=1;
          b = false; 
        }
        //float diam = random(5,15);
        xValue =  pnts[i].x;
        yValue = pnts[i].y;
        i++;
        //System.out.println("This is Xvalue:" + xValue);
        //System.out.println("This is yvalue:" + yValue);
      }
     }
  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(1);
  RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
  RGroup grp;
  grp = font.toGroup(str);
  grp = grp.toPolygonGroup();
  return grp.getPoints();
}

void mousePressed(){
  xValue-=1;
  update();
  
}

 

 

Leave a Reply