let num = '程序猿1024节日快乐'; function strToBinary(str) { let result = []; let list = str.split(""); for (let i = 0; i < list.length; i ) { if (i !== 0) { result.push(" "); } let item = list[i]; let binaryStr = item.charCodeAt().toString(2); result.push(binaryStr); } return result.join(""); } function binaryToStr(str) { let result = []; let list = str.split(" "); for (let i = 0; i < list.length; i ) { let item = list[i]; let asciiCode = parseInt(item, 2); let charValue = String.fromCharCode(asciiCode); result.push(charValue); } return result.join(""); } function drawText(value) { let canvas = document.getElementById("myCanvas"); let context = canvas.getContext("2d"); context.font = "30pt Arial"; context.textAlign = "center"; let centerX = canvas.width / 2; let centerY = canvas.height - 30; let angle = Math.PI * 0.8; // radians let radius = 180; drawTextAlongArc(context, value, centerX, centerY, radius, angle); } function drawTextAlongArc(context, str, centerX, centerY, radius, angle){ context.save(); context.translate(centerX, centerY); context.rotate(-1 * angle / 2); context.rotate(-1 * (angle / str.length) / 2); for (let n = 0; n < str.length; n ) { context.rotate(angle / str.length); context.save(); context.translate(0, -1 * radius); let char = str[n]; context.fillText(char, 0, 0); context.restore(); } context.restore(); } drawText(binaryToStr(strToBinary(num)));,节日快乐,1024...展开