Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # js_text_along_arc_path.py
- import tempfile
- import webbrowser
- import os
- js_data = '''<!DOCTYPE html>
- <html>
- <head>
- <title>HTML5 Text Along Arc Path</title>
- </head>
- <body>
- <canvas id="myCanvas" width="500" height="250"
- style="border:1px solid blue;">
- </canvas>
- <script>
- function drawTextAlongArc(context, str, centerX, centerY, radius, angle) {
- var len = str.length,
- s;
- context.save();
- context.translate(centerX, centerY);
- context.rotate(-1 * angle / 2);
- context.rotate(-1 * (angle / len) / 2);
- for (var n = 0; n < len; n++) {
- context.rotate(angle / len);
- context.save();
- context.translate(0, -1 * radius);
- s = str[n];
- context.fillText(s, 0, 0);
- context.restore();
- }
- context.restore();
- }
- var canvas = document.getElementById('myCanvas'),
- context = canvas.getContext('2d'),
- centerX = canvas.width / 2,
- centerY = canvas.height - 30,
- angle = Math.PI * 0.8,
- radius = 150;
- context.font = '32pt Impact';
- context.textAlign = 'center';
- context.fillStyle = 'blue';
- context.strokeStyle = 'purple';
- context.lineWidth = 4;
- drawTextAlongArc(context, 'TEXT ALONG ARC PATH', centerX, centerY, radius, angle);
- // draw circle underneath text
- context.stroke();
- </script>
- </body>
- </html>
- '''
- chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
- tf = tempfile.mktemp(".html", "JSdemo_")
- print tf
- with open(tf, 'w') as temp:
- temp.write(js_data)
- webbrowser.get(chrome_path).open(tf)
- os.remove(tf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement