Advertisement
here2share

# js_text_along_arc_path.py

Nov 26th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. # js_text_along_arc_path.py
  2.  
  3. import tempfile
  4. import webbrowser
  5. import os
  6.  
  7. js_data = '''<!DOCTYPE html>
  8. <html>
  9.     <head>
  10.     <title>HTML5 Text Along Arc Path</title>
  11.     </head>
  12.     <body>
  13.         <canvas id="myCanvas" width="500" height="250" 
  14.                         style="border:1px solid blue;">
  15.         </canvas>
  16.         <script>
  17.             function drawTextAlongArc(context, str, centerX, centerY, radius, angle) {
  18.               var len = str.length,
  19.                 s;
  20.               context.save();
  21.               context.translate(centerX, centerY);
  22.               context.rotate(-1 * angle / 2);
  23.               context.rotate(-1 * (angle / len) / 2);
  24.               for (var n = 0; n < len; n++) {
  25.                 context.rotate(angle / len);
  26.                 context.save();
  27.                 context.translate(0, -1 * radius);
  28.                 s = str[n];
  29.                 context.fillText(s, 0, 0);
  30.                 context.restore();
  31.               }
  32.               context.restore();
  33.             }
  34.             var canvas = document.getElementById('myCanvas'),
  35.               context = canvas.getContext('2d'),
  36.               centerX = canvas.width / 2,
  37.               centerY = canvas.height - 30,
  38.               angle = Math.PI * 0.8,
  39.               radius = 150;
  40.  
  41.             context.font = '32pt Impact';
  42.             context.textAlign = 'center';
  43.             context.fillStyle = 'blue';
  44.             context.strokeStyle = 'purple';
  45.             context.lineWidth = 4;
  46.             drawTextAlongArc(context, 'TEXT ALONG ARC PATH', centerX, centerY, radius, angle);
  47.  
  48.             // draw circle underneath text
  49.             context.stroke();
  50.         </script>
  51.     </body>
  52. </html>
  53. '''
  54.  
  55. chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
  56.  
  57. tf = tempfile.mktemp(".html", "JSdemo_")
  58. print tf
  59. with open(tf, 'w') as temp:
  60.     temp.write(js_data)
  61. webbrowser.get(chrome_path).open(tf)
  62. os.remove(tf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement