Advertisement
here2share

# js_transparency.py

Nov 26th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. # js_transparency.py
  2.  
  3. import tempfile
  4. import webbrowser
  5. import os
  6.  
  7. js_data = '''<!DOCTYPE html>
  8. <html>
  9. <head>
  10. <title>HTML5 transparency</title>
  11. <script>
  12.    function draw() {
  13.        var canvas = document.getElementById('myCanvas');
  14.        var ctx = canvas.getContext('2d');
  15.        
  16.         ctx.fillStyle = '#FD0';
  17.         ctx.fillRect(0, 0, 100, 100);
  18.         ctx.fillStyle = '#6C0';
  19.         ctx.fillRect(100, 0, 100, 100);
  20.         ctx.fillStyle = '#09F';
  21.         ctx.fillRect(0, 100, 100, 100);
  22.         ctx.fillStyle = '#F30';
  23.         ctx.fillRect(100, 100, 100, 100);
  24.         ctx.fillStyle = '#FFF';
  25.        
  26.         // set transparency value
  27.         ctx.globalAlpha = 0.2;
  28.  
  29.         // Draw semi transparent circles
  30.         for (var i = 0; i < 9; i++) {
  31.             ctx.beginPath();
  32.             ctx.arc(100, 100, 10 + 10 * i, 0, Math.PI * 2, true);
  33.             ctx.fill();
  34.         }
  35.    }
  36. </script>
  37. </head>
  38.  
  39. <body onload="draw();">
  40.    <canvas id="myCanvas" width="450" height="350">
  41.    </canvas>
  42. </body>
  43. </html>
  44. '''
  45.  
  46. chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
  47.  
  48. tf = tempfile.mktemp(".html", "JSdemo_")
  49. print tf
  50. with open(tf, 'w') as temp:
  51.     temp.write(js_data)
  52. webbrowser.get(chrome_path).open(tf)
  53. os.remove(tf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement