xxxxxxxxxx
108
// 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 angle = 0;
let glitch;
let amp;
let vol;
let stage;
let fft
let freqs
function preload() {
font = loadFont("Humankind.ttf");
glitch = loadSound("NewPersonSameOldMistakes.mp3");
}
function setup() {
createCanvas(windowWidth, windowHeight);
textFont(font);
amp = new p5.Amplitude();
fft = new p5.FFT()
glitch.play();
const n = '24';
const s = 700;
points = font.textToPoints(n, 0, 0, s, {
sampleFactor: 0.8,
simplifyThreshold: 0.0
});
bounds = font.textBounds(n, 0, 0, s);
console.log(bounds)
}
function draw() {
background(180*vol);
translate(width/2, height/2);
vol = amp.getLevel();
freqs = fft.analyze()
console.log(freqs)
drawLetterShape();
// drawLetterVertex();
}
function drawLetterVertex() {
stroke(0,50);
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 + tan((frameCount + i) * 0.7) * 10;
y = points[i].y;
vertex(x, y);
}
endShape(CLOSE);
pop();
}
function drawLetterShape() {
colorMode(HSB);
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) * 10;
y = points[i].y;
push();
translate(x, y);
rotate((frameCount + i) * 0.005);
stroke(300, 80*vol, 80);
rect(-100, 0, 280*vol, 5);
pop();
}
pop();
}