geomerative RFont with outline ellipse

edited January 2016 in Library Questions

hi guys,

i got a simple sketch for writing live in the browser using geomerative RFont:

import geomerative.*;
import processing.pdf.*;
boolean doSave = false;

RFont font;
RPoint[] myPoints; 
String myText = "";
RGroup myGroup;
int textsite;
//----------------SETUP---------------------------------
void setup() {
  size(800,300);
  background(255);
  smooth();
  RG.init(this); 
  font = new RFont("FreeSans.ttf",100, CENTER);
}

//----------------DRAW---------------------------------
void draw() {

  background(0);
  stroke(#00FFE8);
  noFill();
  translate(width/2, height/1.7);

  RCommand.setSegmentLength(1);
  RCommand.setSegmentator(RCommand.UNIFORMLENGTH);

  if (myText.length() > 0) {
    RGroup myGroup = font.toGroup(myText); 
    myGroup = myGroup.toPolygonGroup();
    RPoint[] myPoints = myGroup.getPoints();

    beginShape();
    for(int i=0; i<myPoints.length; i++) {
      //ellipse(myPoints[i].x, myPoints[i].y,1,1);
      curveVertex(myPoints[i].x, myPoints[i].y);
    }
    endShape();

    // ------ SAVING  ------ 
    if (doSave) {
      doSave = true;
      endRecord();

      println("gespeichert");
    }
  }
  println(textWidth(myText));
}

//----------------KEYS---------------------------------
void keyReleased() {
  if (keyCode == CONTROL) doSave = true;
}

void keyPressed() {
  if(key !=CODED) {
    switch(key) {
    case DELETE:
    case BACKSPACE:
      myText = myText.substring(0,max(0,myText.length()-1));
      break;
    case ENTER:

      break;
    default:
      myText +=key;
    }
  }
}

and i got another sketch dropping an ellipse by pressing any key on the current mouseX mouseY position:

ArrayList plist = new ArrayList();
int MAX = 1;

void setup() {
  size(400,400);
  background(100);
}

void draw() {
  background(50);
  if(mousePressed && mouseButton == RIGHT) {
    background(50);
    boolean clearall = true;
    while(plist.size() > 0) {
      for(int i = 0; i < plist.size(); i++) {
        plist.remove(i);
      }
    }
  }

  for(int i = 0; i < plist.size(); i++) {
    Particle p = (Particle) plist.get(i); 
    //makes p a particle equivalent to ith particle in ArrayList
    p.run();
    p.update();
    p.gravity();
  }
}

void keyReleased() {
  for (int i = 0; i < MAX; i ++) {
    plist.add(new Particle(mouseX,mouseY)); // fill ArrayList with particles

    if(plist.size() > 50*MAX) {
      plist.remove(0);
    }
  }
}

class Particle {
  float r = random(1,5);
  PVector pos,speed,grav; 
  ArrayList tail;
  float splash = 3;
  int margin = 5;
  int taillength = 2;

  Particle(float tempx, float tempy) {
    float startx = tempx + random(-splash,splash);
    float starty = tempy + random(-splash,splash);
    startx = constrain(startx,0,width);
    starty = constrain(starty,0,height);
    float xspeed = random(0,0);
    float yspeed = random(0,-10);

    pos = new PVector(startx,starty);
    speed = new PVector(xspeed,yspeed);
    grav = new PVector(0,0.02);

    tail = new ArrayList();
  }

  void run() {
    pos.add(speed);

    tail.add(new PVector(pos.x,pos.y,0));
    if(tail.size() > taillength) {
      tail.remove(0);
    }

    float damping = random(-0.5,0.0);
    if(pos.x > width - margin || pos.x < margin) {
      speed.x *= damping;
    }
    if(pos.y > height -margin) {
      speed.y *= damping;
    }
  }

  void gravity() {
    speed.add(grav);
  }

  void update() {
    for (int i = 0; i < tail.size(); i++) {
      PVector tempv = (PVector)tail.get(i);
      noStroke();
      //fill(6*i + 50);
      fill(255);
      ellipse(tempv.x,tempv.y,r,r);
    }
  }
}

how can i impement the dropping dot as a dot of the outline of the typed letter??? can you help me?

Tagged:
Sign In or Register to comment.