xxxxxxxxxx
98
// 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 sound;
function preload() {
font = loadFont("KronaOne-Regular.ttf");
sound = loadSound("rumble.wav");
}
function setup() {
createCanvas(1080, 1080);
textFont(font);
const n = '8';
const s = 1000;
points = font.textToPoints(n, 0, 0, s, {
sampleFactor:2,
simplifyThreshold: 0
});
bounds = font.textBounds(n, 0, 0, s);
}
function draw() {
background(0,0,133);
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) * 0.08) * 10;
y = points[i].y;
vertex(x, y);
}
endShape(CLOSE);
pop();
}
function drawLetterShape() {
fill(132,250,212);
push();
translate(-bounds.w/1.65, bounds.h/2.1);
let x = 0;
let y = 0;
let n = points.length;
let res = 1;
for (let i = 0; i < n; i += res) {
x = points[i].x +tan((frameCount + i) * 10) * 10;
y = points[i].y +tan((frameCount + i) * 0.1) * 10;
push();
translate(x, y);
circle(0, 0, PI*2);
pop();
}
pop();
}
function mouseClicked() {
// Play the sound when the canvas is clicked
sound.play();
}