18
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

processingでフォントデータを扱う

Last updated at Posted at 2015-07-08

Geomerativeライブラリを利用するとフォントのアウトラインデータを参照できるので、
そのデータでちょっとアニメーションを入れてみました。
このライブラリはフォントデータだけでなく、SVGデータにもアクセスできます。
https://vimeo.com/97508025

import geomerative.*;
 
RFont font;
RShape group;
RPoint[] points;
 
float[] x;
float[] y;
float[] z;
float[] ax;
float[] ay;
float[] az;
float[] vx;
float[] vy;
float[] vz;
float[] rx;
float[] ry;
float[] rz;
float[] px;
float[] py;
float[] pz;
 
float offsetx;
float offsety;
float offsetz;
float spring;
float friction;
float deg;
 
String msg = "a";
 
void setup () {
 
  size (1000, 800, P3D);
  background (255);
  frameRate (60);
 
  RG.init (this);
 
  offsetx = 0;
  offsety = 0;
  offsetz = 0;
 
  group = RG.getText (msg, "Georgia.ttf", 800, CENTER);
 
  points = group.getPoints ();
 
  x = new float[points.length];
  y = new float[points.length];
  z = new float[points.length];
  ax = new float[points.length];
  ay = new float[points.length];
  az = new float[points.length];
  vx = new float[points.length];
  vy = new float[points.length];
  vz = new float[points.length];
  rx = new float[points.length];
  ry = new float[points.length];
  rz = new float[points.length];
  px = new float[points.length];
  py = new float[points.length];
  pz = new float[points.length];
 
  spring = 0.1;
  friction = 0.96;
  deg = 0.0;
 
  for (int i = 0; i < points.length; i++) {
    ax[i] = 0;
    ay[i] = 0;
    az[i] = 0;
    vx[i] = 0;
    vy[i] = 0;
    vz[i] = 0;
    px[i] = points[i].x + offsetx;
    py[i] = points[i].y + offsety;
    pz[i] = offsetz;
    rx[i] = random (width);
    ry[i] = random (height);
    rz[i] = random (-1000, 0);
  }
 
}
 
void draw () {
 
    background (255);
 
  translate (width / 2, (height / 2) + 300, -400);
  rotateY (radians (deg));
 
    stroke (100);
    strokeWeight (2);
    noFill ();
 
    for (int i = 0; i < points.length; i++) {
        ax[i] = (px[i] - rx[i]) * spring;
        ay[i] = (py[i] - ry[i]) * spring;
    az[i] = (pz[i] - rz[i]) * spring;
        vx[i] += ax[i];
        vy[i] += ay[i];
    vz[i] += az[i];
        vx[i] *= friction;
        vy[i] *= friction;
    vz[i] *= friction;
        rx[i] += vx[i];
        ry[i] += vy[i];
    rz[i] += vz[i];
        point (rx[i], ry[i], rz[i]);
    }
 
  deg += 4.0;
 
  //saveFrame ();
 
}
 
void keyPressed () {
 
  msg = str (key);
  group = RG.getText (msg, "Georgia.ttf", 800, CENTER);
  points = group.getPoints ();
 
  x = new float[points.length];
  y = new float[points.length];
  z = new float[points.length];
  ax = new float[points.length];
  ay = new float[points.length];
  az = new float[points.length];
  vx = new float[points.length];
  vy = new float[points.length];
  vz = new float[points.length];
  rx = new float[points.length];
  ry = new float[points.length];
  rz = new float[points.length];
  px = new float[points.length];
  py = new float[points.length];
  pz = new float[points.length];
 
    for (int i = 0; i < points.length; i++) {
    px[i] = points[i].x + offsetx;
    py[i] = points[i].y + offsety;
    pz[i] = offsetz;
        rx[i] = random (width);
    ry[i] = random (height);
    rz[i] = random (-1000, 0);
    }
 
}
18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?