Problems with "fixed" position in toxiclibs (and geomerative)

edited December 2014 in Library Questions

Hi Guys, Im working with geomerative and toxiclib libraries in a generative typography project. The project is based on a word which letters are traced with geomerative. I get from this operation several points which are creating the word. Next I have created for each point a Verlet2D particle placed in a position, another Verlet2D particle with method .lock(). My objective is keep the points in the initial position (where geomerative place the points) but with a smooth flow. I have tried .lock() method but it´s blocking any movement and keeping it absolutely fixed. I have tried too with applying perlin noise to each particle but the whole word is moved...anything is working... I want to get in the initial state the same "flow" movement that the particles has right now...In a simple way, I "want my particles in the same place creating the word, but with a independent smooth movement" and no dispersed randomly for whole screen like is happen right now.

The rest of app is working more or less fine... I can drag and drop the fixed point around screen, and I can click in any place in the screen and the particles are attracted to this place. I really would like too that points go back to initial position (creating the word) when we released the mouse.

Help please, I´m getting crazy with toxiclibs.... for me is getting hard understand how works this amazing library.

import toxi.physics2d.*;
import geomerative.*;
import toxi.geom.*;
import toxi.processing.*;
import toxi.physics2d.behaviors.*;

//Geomerative
RFont font;
RPoint[] myPoints;
RGroup myGroup;
String myText = "FAX";

//Toxic
VerletPhysics2D world;
Point[] Points;
Line[] Lines;
AttractionBehavior mouseAttractor;
Vec2D mousePos;
Point fixed;


void setup() {

  size(800, 800); 
  background(255, 255, 213);
  smooth();



  //Geomerative

  RG.init(this);   
  font = new RFont("FreeMono.ttf", 300); 

  RCommand.setSegmentLength(20);
  RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
  RGroup myGroup = font.toGroup(myText);
  myGroup = myGroup.toPolygonGroup();
  myPoints = myGroup.getPoints(); 

  Points = new Point[myPoints.length];
  Lines = new Line[myPoints.length];

//---------------------------------------------------------  

  //Toxiclib

  world=new VerletPhysics2D();
  world.setDrag(0.03f);
  world.addBehavior(new GravityBehavior(new Vec2D(0, -0.001f)));
  world.setWorldBounds(new Rect(0, 0, width, height));
  mousePos =new Vec2D(mouseX, mouseY);
  mouseAttractor = new AttractionBehavior(mousePos, 250, -0.9f);
  world.addBehavior(mouseAttractor);
  fixed = new Point(new Vec2D(width/2, height/2));
  world.addParticle(fixed);


//----------------------------------------------------------- 
//creating toxiclib particles for each point generated by geomerative

  for (int i=0; i<=myPoints.length-1; i++) {
    Points[i] = new Point(new Vec2D(myPoints[i].x+150, myPoints[i].y+height/2));
    println(myPoints[i].x+";"+myPoints[i].y);

    world.addParticle(Points[i]);
    world.addBehavior(new AttractionBehavior(Points[i], 20, -1.2f, 0.2f));
    Lines[i] = new Line(Points[i], fixed, 300, 0.02);
    //world.addSpring(Lines[i]);
  }
}


void draw() {
  background(255, 255, 213);   
  world.update();  

  for (int i=0; i<=Points.length-1; i++) {
    strokeWeight(0.2);
    stroke(0);
    Points[i].update();   
    Points[i].display();
    Lines[i].display();
  }

  fixed.display();
  //handling();

}

void mousePressed() {

  mousePos = new Vec2D(mouseX, mouseY);

  mouseAttractor = new AttractionBehavior(mousePos, 250, 0.9);
  world.addBehavior(mouseAttractor);

  for (int i=0; i<=Points.length-1; i++) {
    strokeWeight(0.2);
    stroke(0);
    Points[i].unlock();
    Points[i].update();
    Points[i].display();
    //Lines[i].display();
  }


}


void mouseDragged(){

  mousePos.set(mouseX, mouseY);
}

void mouseReleased(){

  world.removeBehavior(mouseAttractor);
}

/*
void handling() {
  if (mousePressed) {
    for (int i=0; i<=Points.length-1; i++) {
      float distancia = dist(mouseX, mouseY, Points[i].x, Points[i].y);
      if (distancia<40) {
        Points[i].lock();
        Points[i].x = mouseX;
        Points[i].y = mouseY;
        if (keyPressed==false)Points[i].unlock();
      }
    }
  }
}*/



class Line extends VerletSpring2D {

  Line (VerletParticle2D a, VerletParticle2D b, float len, float strg) {
    super(a, b, len, strg);
  }

  void display() {
    stroke(55, 100);
    line(a.x, a.y, b.x, b.y);
    noStroke();
  }

}


class Point extends VerletParticle2D {


 Point(Vec2D loc) {
    super(loc);

  }


  void display() {

    fill(0);
    ellipse(x,y,3,3);
  }
}
Sign In or Register to comment.