xxxxxxxxxx
86
let font;
function preload() {
font = loadFont('MomcakeBold-WyonA.otf');
}
let points;
let bounds;
let t;
let fontSize;
let posx;
let posy;
function setup() {
createCanvas(400, 400);
//rectMode(CORNER);
noStroke();
fill(0);
t = "wave";
fontSize = 150;
textSize(fontSize);
textFont(font);
let tw = textWidth(t);
let th = textAscent(); // doesn't expect any kind of argument
// position of upper left corner
posx = (width - tw)/2;
posy = (height + th)/2;
// calculate text bounds
bounds = font.textBounds(t, posx, posy, fontSize);
// calculate points on text
points = font.textToPoints(t, posx, posy, fontSize, {
sampleFactor: 10,
simplifyThreshold: 0,
//separatePaths: true // returns: [paths][points]
separateGlyphs: true // returns: [glyphs][paths][points] (supersedes separatePaths)
});
console.log("text width : " + textWidth(t));
console.log("text bounds.w : " + bounds.w)
}
function draw() {
background(255);
// Text Boundary draw
//fill(200,100)
//rect(bounds.x, bounds.y, bounds.w, bounds.h);
// Actual Text Draw
//fill(0);
//text(t, posx, posy);
// Points of text draw
noFill();
stroke(0);
for (let i = 0; i < points.length; i++) { // glyphs
for (let j = 0; j < points[i].length; j++) { // paths
beginShape();
for (let k = 0; k < points[i][j].length; k++) { // points
let p = points[i][j][k];
vertex(p.x + cos(p.y/100 + millis()/1000)* 10,
p.y);
}
endShape(CLOSE);
}
}
}