xxxxxxxxxx
117
// 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;
let xx=0, nx =0;
let yy=0, ny=0;
let label = "x";
function preload() {
font = loadFont("KronaOne-Regular.ttf");
}
function setup() {
createCanvas(windowWidth, windowHeight);
textFont(font);
const n = 'X';
const s = 800; // size
points = font.textToPoints(n, 0, 0, s, {
sampleFactor: 0.3, //the bezier amount*
simplifyThreshold: 0.0
});
bounds = font.textBounds(n, 0, 0, s);
console.log(bounds)
}
function draw() {
if(frameCount%20 == 0){
nx=random(3, 30);
ny=random(20, 255);
}
xx += (nx - xx) * 0.1;
yy += (ny - yy) * 0.1;
background(255, yy,0,70);
translate(width/2, height/2);
//scale(xx);
drawLetterShape();
drawLetterVertex(); //connects the line
}
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) {
stroke(yy,0,255);
x = points[i].x + tan((frameCount + i+xx) * 0.05) * 6;
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 = 4;
for (let i = 0; i < n; i += res) {
x = points[i].x + cos((frameCount + i) * 0.05)*10; //*
y = points[i].y;
push();
translate(x, y);
rotate((frameCount + i) * 0.1); //*
// rect(-10, 0, xx, 0);
ellipse(xx,xx,xx,xx); //*
pop();
}
pop();
}
function keyPressed() {
if (key === "s") {
if(this._renderer.elt.svg !== undefined) {
saveSVG(label + ".svg");
} else {
saveCanvas(label + ".png");
}
}
}