xxxxxxxxxx
91
// load font with a link tag from inside the index.html
// file. (see sketch files).
//
// for this example we use Krona One by by Yvonne Schüttler
// https://fonts.google.com/specimen/Krona+One
//
// check the Sketch Files and the additional file
// KronaOne-Regular.ttf
//
// Note that this will work for the default renderer,
// however this does not work as expected with WEBGL and
// Tthe following notification will be posted in the console:
//
// You must load and set a font before drawing text.
// See `loadFont` and `textFont` for more details.
//
// see the following WEBGL type example.
// https://editor.p5js.org/sojamo/sketches/mvEZEFfB6
let points;
let bounds;
let font;
function preload() {
font = loadFont("Emergent-Regular.otf");
}
function setup() {
createCanvas(windowWidth, windowHeight);
textFont(font);
const n = '3';
const s = 800;
points = font.textToPoints(n, 0, 0, s, {
sampleFactor: 1.08,
simplifyThreshold: 0.0
});
bounds = font.textBounds(n, 0, 0, s);
console.log(bounds)
}
function draw() {
background(255);
translate(width/2, height/2);
drawLetterShape();
// drawLetterVertex();
}
function drawLetterVertex() {
stroke(0,100);
noFill();
push();
translate(-bounds.w/2, bounds.h/2);
beginShape();
let x = 0;
let y = 0;
let n = points.length;
let angle = TWO_PI / (n);
for (let i = 0; i < n; i += 1) {
x = points[i].x + cos((frameCount + i) * 1.07) * 10;
y = points[i].y;
vertex(x, y);
}
endShape(CLOSE);
pop();
}
function drawLetterShape() {
stroke(0,100);
noFill();
push();
translate(-bounds.w/2, bounds.h/2);
let x = 0;
let y = 0;
let n = points.length;
let res = 2;
for (let i = 0; i < n; i += res) {
x = points[i].x + sin((frameCount + i) * 0.01) * 1;
y = points[i].y;
push();
translate(x, y);
rotate((frameCount + i) * 0.01);
rect(-10, 0, 250, 1);
pop();
}
pop();
}