<!doctype html>
<html>
<head>
<title>Circular Text or Emoji - RJM Programming - December, 2018 ... Thanks to https://appendto.com/2016/09/how-to-make-circularcurved-text-with-javascript/</title>
<meta charset="utf-8">
<script type='text/javascript'>
var rad=100, radbit='', deg=360;
if (!String.fromCodePoint) { // thanks to http://xahlee.info/js/js_unicode_code_point.html
// ES6 Unicode Shims 0.1 , © 2012 Steven Levithan , MIT License
String.fromCodePoint = function fromCodePoint () {
var chars = [], point, offset, units, i;
for (i = 0; i < arguments.length; ++i) {
point = arguments[i];
offset = point - 0x10000;
units = point > 0xFFFF ? [0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF)] : [point];
chars.push(String.fromCharCode.apply(null, units));
}
return chars.join("");
}
}
// parseInt("hex",16);
// https://appendto.com/2016/09/how-to-make-circularcurved-text-with-javascript/
function circularText(intxt, radius, arcd) {
var txt=[], etxt=[], one=1, isemoji=false, kk=0, kkk=0, zero=0, ishex=false, dtxt=[], dectxt='', lu='';
//alert(intxt);
if (intxt.replace(/\&\;/g,'&').indexOf('&#') != -1 && intxt.indexOf(';') != -1) {
etxt=intxt.replace(/\&\;/g,'&').replace(/\;\&\#/g,',').split('&#');
for (var k=0; k<etxt.length; k+=one) {
if (!isemoji) {
if (etxt[k].substring(zero).length > 1 && etxt[k].substring(zero).substring(0,1).charCodeAt(0) > 255) {
while (zero < etxt[k].length && etxt[k].substring(zero).length > 1 && etxt[k].substring(zero).substring(0,1).charCodeAt(0) > 255) {
//alert(etxt[k].substring(zero).substring(0,1).charCodeAt(0)) + ' ' + eval('' + etxt[k].substring(zero).substring(1).charCodeAt(0));
txt.push(String.fromCodePoint(eval('' + etxt[k].substring(zero).substring(0,1).charCodeAt(0)),eval('' + etxt[k].substring(zero).substring(1).charCodeAt(0)) ));
zero+=2;
}
}
//if (zero != 0) { alert('' + zero + ' ' + etxt[k].substring(zero) + '! k=' + k + ' and etxt.length=' + etxt.length + ' ... ' + intxt.replace(/\;\&\#/g,',')); }
one=1;
for (kk=zero; kk<etxt[k].length; kk+=one) {
if (etxt[k].substring(kk, eval(1 + kk)).charCodeAt(0) > 255) {
txt.push(String.fromCodePoint(eval('' + etxt[k].substring(kk).charCodeAt(0)),eval('' + etxt[k].substring(kk).substring(1).charCodeAt(0)) ));
one=2;
} else {
txt.push(etxt[k].substring(kk, eval(1 + kk)));
one=1;
}
}
one=1;
zero=0;
isemoji=true;
} else {
if (ishex || etxt[k].split(';')[0].toLowerCase().replace('x','a').replace('b','a').replace('c','a').replace('d','a').replace('e','a').replace('f','a').indexOf('a') != -1) {
ishex=true;
dtxt=etxt[k].split(';')[0].split(',');
dectxt='' + parseInt(dtxt[0].replace('x','').replace('X',''),16);
lu=dtxt[0];
for (kkk=1; kkk<dtxt.length; kkk++) {
dectxt+=',' + parseInt(dtxt[kkk].replace('x','').replace('X',''),16);
lu=dtxt[kkk];
}
eval("txt.push(String.fromCodePoint(" + dectxt + "))");
} else {
eval("txt.push(String.fromCodePoint(" + etxt[k].split(';')[0].replace(/x/g,'').replace(/X/g,'') + "))");
}
zero=eval(1 + eval('' + etxt[k].split(';')[0].length));
//if (zero != 0) { alert('' + zero + ' ' + etxt[k].substring(zero) + '! k=' + k + ' and etxt.length=' + etxt.length + ' ... ' + intxt.replace(/\;\&\#/g,',')); }
if ((etxt[k] + '&').substring(kk, eval(1 + kk)) != '&'.substring(0,1)) {
if (intxt.split(lu + ';')[1].length > 1 && intxt.split(lu + ';')[1].substring(0,1).charCodeAt(0) > 255) {
//alert('' + String.fromCodePoint(eval('' + intxt.split(lu + ';')[1].substring(0,1).charCodeAt(0))) + ' ' + intxt.split(lu + ';')[1].substring(0,1).charCodeAt(0) + ' ' + intxt.split(lu + ';')[1].substring(1).charCodeAt(0) + ' ' + etxt[k].substring(kk));
//txt.push(etxt[k].substring(kk));
txt.push(String.fromCodePoint(eval('' + intxt.split(lu + ';')[1].substring(0,1).charCodeAt(0)),eval('' + intxt.split(lu + ';')[1].substring(1).charCodeAt(0)) ));
} else {
//alert(intxt.split(lu + ';')[1] + ' ' + intxt.split(lu + ';')[1].length + ' ' + intxt.split(lu + ';')[1].substring(0,1).charCodeAt(0));
one=1;
for (kk=zero; kk<etxt[k].length; kk+=one) {
if (etxt[k].substring(kk, eval(1 + kk)).charCodeAt(0) > 255) {
txt.push(String.fromCodePoint(eval('' + etxt[k].substring(kk).charCodeAt(0)),eval('' + etxt[k].substring(kk).substring(1).charCodeAt(0)) ));
one=2;
} else {
txt.push(etxt[k].substring(kk, eval(1 + kk)));
one=1;
}
}
}
one=1;
zero=0;
} else {
isemoji=false;
}
}
}
} else {
txt = intxt.split("");
}
var deg = arcd / txt.length, origin = 0, j = 0;
while (eval('' + origin) < arcd) {
if (txt.length > j) {
document.getElementById('test').innerHTML+="<p style='height:" + radius + "px;position:absolute;transform:rotate(" + origin + "deg);transform-origin:0 100%'>" + txt[j] + "</p>";
}
origin += deg;
j++;
}
}
//circularText("this text is in a circle ", 100, 0);
function onl() {
var textis=location.search.split('text=')[1] ? decodeURIComponent(location.search.split('text=')[1].split('&')[0]) : '';
deg=location.search.split('degrees=')[1] ? eval(decodeURIComponent(location.search.split('degrees=')[1].split('&')[0])) : deg;
var crad=location.search.split('radius=')[1] ? decodeURIComponent(location.search.split('radius=')[1].split('&')[0]) : '' + rad;
if (crad != ('' + rad)) {
if (crad.indexOf('.') != -1) {
deg=eval(crad.split('.')[1]);
rad=eval(crad.split('.')[0]);
} else {
rad=eval(crad);
}
}
if (('' + rad) != '100' || ('' + deg) != '360') { radbit='radius=' + encodeURIComponent('' + rad + '.' + deg) + '&'; document.getElementById('irad').value='' + rad; document.getElementById('ideg').value='' + deg; }
if (textis == '') {
circularText("this text is in a circle 🍍 🍌 ", rad, deg);
} else {
//document.getElementById('inp').value=textis; //.replace(/\&\#/g,'&#');
//alert(textis);
circularText(textis, rad, deg);
document.getElementById('inp').value=textis.replace(/\&\#/g,'&#');
}
}
function placethis(oi) {
if (oi.value == '') {
oi.value=oi.placeholder;
} else {
location.href=document.URL.split('#')[0].split('?')[0] + '?' + radbit + 'text=' + encodeURIComponent(oi.value.replace(/\&\#/g,'&#'));
}
}
</script>
</head>
<body onload='onl();'>
<h1>Circular Text or Emoji</h1>
<h3>RJM Programming - December, 2018</h3>
<h3>Thanks to <a target=_blank title='Usefulk link, thanks' href='https://appendto.com/2016/09/how-to-make-circularcurved-text-with-javascript/'>https://appendto.com/2016/09/how-to-make-circularcurved-text-with-javascript/</a></h3>
Your text (on circle radius <input style='width:5%;' id=irad title=pixels type=number onchange="rad=eval(this.value); radbit='radius=' + encodeURIComponent('' + rad + '.' + deg) + '&'; " value=100 min=1 max=2000></input><input style='width:5%;' title=degrees id=ideg type=number onchange="deg=eval(this.value); radbit='radius=' + encodeURIComponent('' + rad + '.' + deg) + '&'; " value=360 min=1 max=360></input> arc): <input id=inp onblur=placethis(this); type=text style='width:50%;' placeholder="this text is in a circle 🍍 🍌"></input>
<div class="container" style="text-align: center;">
<!--the holders for the text, reuse as desired-->
<div class="circTxt" id="test" style="display: inline-block; margin-bottom: 128px; "></div>
</div>
<input type=text style="position:absolute;top:-200px;left:-200px;" value=""></input>
</body>
</html>