xxxxxxxxxx
102
let words = ['Bestiary,', 'Geometrica'];
let font;
let fontSize = 100;
function preload() {
// Charger une police de caractères de Google Fonts
font = loadFont('SpaceGrotesk-Bold.ttf');
}
function setup() {
// Créer un canvas SVG
createCanvas(windowWidth, windowHeight, SVG);
textFont(font);
textSize(fontSize);
noLoop();
}
function draw() {
background(255);
// Position initiale du texte
let x = 100;
let y = 200;
let lineHeight = fontSize * 1.2; // Ajustez cette valeur pour l'espacement des lignes
// Dessiner chaque ligne de texte
fill(0);
stroke(0);
strokeWeight(3); // Épaisseur de texte plus importante
words.forEach((line, index) => {
text(line, x, y + index * lineHeight);
});
// Obtenir les points des lettres
let points = [];
words.forEach((line, index) => {
points = points.concat(font.textToPoints(line, x, y + index * lineHeight, fontSize, {
sampleFactor: 0.1, // Ajuste cette valeur pour changer la densité des points
simplifyThreshold: 0
}));
});
// Ajouter les croissances
for (let i = 0; i < points.length; i++) {
let pt = points[i];
drawRoots(pt.x, pt.y);
}
// Redessiner le texte pour le garder au premier plan
fill("#FFFFF5");
stroke(0);
strokeWeight(3); // Épaisseur de texte plus importante
words.forEach((line, index) => {
text(line, x, y + index * lineHeight);
});
// Exporter en SVG
save('racines.svg');
}
function drawRoots(x, y) {
let numRoots = int(random(3, 6));
for (let i = 0; i < numRoots; i++) {
let angle = random(TWO_PI);
let length = random(30, 80);
let x1 = x;
let y1 = y;
let x2 = x1 + cos(angle) * length;
let y2 = y1 + sin(angle) * length;
// Points de contrôle pour la courbe de Bézier
let cx1 = x1 + cos(angle - PI / 4) * length / 2;
let cy1 = y1 + sin(angle - PI / 4) * length / 2;
let cx2 = x1 + cos(angle + PI / 4) * length / 2;
let cy2 = y1 + sin(angle + PI / 4) * length / 2;
stroke(0);
strokeWeight(1);
noFill();
bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2);
// Ajout de ramifications secondaires
let numBranches = int(random(1, 4));
for (let j = 0; j < numBranches; j++) {
let branchAngle = angle + random(-PI / 4, PI / 4);
let branchLength = length * random(0.3, 0.7);
let bx1 = x2;
let by1 = y2;
let bx2 = bx1 + cos(branchAngle) * branchLength;
let by2 = by1 + sin(branchAngle) * branchLength;
// Points de contrôle pour la courbe de Bézier de la branche
let bcx1 = bx1 + cos(branchAngle - PI / 6) * branchLength / 2;
let bcy1 = by1 + sin(branchAngle - PI / 6) * branchLength / 2;
let bcx2 = bx1 + cos(branchAngle + PI / 6) * branchLength / 2;
let bcy2 = by1 + sin(branchAngle + PI / 6) * branchLength / 2;
bezier(bx1, by1, bcx1, bcy1, bcx2, bcy2, bx2, by2);
}
}
}