xxxxxxxxxx
59
let font;
let points = [];
let additionalPoints = 5; // Number of additional random points
function preload() {
// Load a custom font (make sure to have a .ttf or .otf font file in the project)
font = loadFont('thulth2.ttf'); // Replace with your font path
}
function setup() {
createCanvas(800, 600);
textSize(300);
textFont(font);
noLoop();
// Extract points from the text
let textPoints = font.textToPoints('س', width / 2, height / 2, 300, {
sampleFactor: 0.1
});
// Store the points, centering them
points = textPoints.map(p => createVector(p.x - width / 2, p.y - height / 2));
}
function draw() {
background(255);
noFill();
stroke(0);
strokeWeight(1);
//fill(0);
beginShape();
let randomCount = int(random(20, 60));
for (let i = 0; i <= randomCount ; i++) {
// Apply homotopy equation to all points
let t = map(i, 0, points.length - 1, 0, HALF_PI);
fill(0);
// Example transformation using homotopy
let x = points[i].x + 20 * cos(t) * 2; // Offset in x
let y = points[i].y + 20 * sin(t); // Offset in y
// Draw the transformed point at the center
curveVertex(width / 2 + x, height / 2 + y);
}
// Generate additional random twisted points
for (let j = 0; j < additionalPoints; j++) {
let angle = map(j, 0, additionalPoints, 0, HALF_PI);
let randX = 50 * cos(angle) * random(0.5, 5); // Random offset in x
let randY = -50 * sin(angle) * random(0.5, 5); // Random offset in y
fill(random(255),random(255),random(255));
curveVertex(width / 2 + randX, height / 2 + randY);
}
// Connect the last point to the first point to close the shape
curveVertex(width / 2 + points[0].x + 50 * cos(0) * 2, height / 2 + points[0].y + 50 * sin(0));
endShape(CLOSE);
}