xxxxxxxxxx
56
var name = "Divyanshu";
var identity = "developer";
var len = name.length;
var a = "a".charCodeAt();
var radius = 150;
var totalAlphabets = 26;
function setup() {
noLoop();
createCanvas(400, 400);
name = name.toLowerCase();
}
function draw() {
background(255);
noStroke();
for (var i = 0; i < len; i++) {
var posCurr = name[i].charCodeAt() - a + 1;
var xCurr = width / 2 + (radius - ((radius * posCurr)) / totalAlphabets) * cos(i * TWO_PI / len - PI / 2);
var yCurr = height / 2 + (radius - ((radius * posCurr)) / totalAlphabets) * sin(i * TWO_PI / len - PI / 2);
var posPrev, xPrev, yPrev;
if (i + 1 === len) {
posPrev = name[0].charCodeAt() - a + 1;
xPrev = width / 2 + (radius - ((radius * posPrev)) / totalAlphabets) * cos((0) * TWO_PI / len - PI / 2);
yPrev = height / 2 + (radius - ((radius * posPrev)) / totalAlphabets) * sin((0) * TWO_PI / len - PI / 2);
}
else {
posPrev = name[i + 1].charCodeAt() - a + 1;
xPrev = width / 2 + (radius - ((radius * posPrev)) / totalAlphabets) * cos((i + 1) * TWO_PI / len - PI / 2);
yPrev = height / 2 + (radius - ((radius * posPrev)) / totalAlphabets) * sin((i + 1) * TWO_PI / len - PI / 2);
}
if (identity === "designer") {
fill(3, 190, 252, (i + 1) * 255 / len);
}
else if (identity === "developer") {
fill(252, 3, 90, (i + 1) * 255 / len);
}
beginShape();
vertex(xCurr, yCurr);
vertex(xPrev, yPrev);
vertex(width / 2, height / 2);
endShape(CLOSE);
}
}
function keyPressed() {
console.log(key);
if (key == ' ') {
saveCanvas((name + '-' + (floor(random(100)))), 'png');
draw();
}
}