Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # js_droplets.py
- import tempfile
- import webbrowser
- import os
- js_data = '''<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>Droplets</title>
- <script>
- document.createElement("canvas");
- </script>
- <style>
- body {
- font-family: sans-serif;
- margin: 20px;
- color: #333;
- background-color: #fff;
- }
- #mycanvas {
- float: left;
- width: 300px;
- height: 300px;
- margin: 0 20px 0 0;
- background-image: url(rain.jpg);
- border: 1px solid #000;
- }
- #mycanvas.active {
- background-image: none;
- }
- </style>
- </head>
- <body>
- <h1>HTML Canvas Example</h1>
- <canvas id="mycanvas" width="300" height="300"></canvas>
- <p>This page works in any browser.</p>
- <script>
- var canvas = document.getElementById("mycanvas");
- if (canvas.getContext) {
- // canvas supported
- canvas.className = "active";
- // start animation
- var cxt = canvas.getContext("2d");
- cxt.fillStyle = "rgba(255,255,255,0.5)";
- setInterval(function () {
- var x = Math.round(Math.random() * canvas.width),
- y = Math.round(Math.random() * canvas.height),
- e = 20 + Math.round(Math.random() * 30),
- s = 0;
- (function () {
- s++;
- if (s <= e) {
- setTimeout(arguments.callee, s);
- var c = 255 - (e - s) * 3;
- cxt.strokeStyle = "rgb(" + c + "," + c + "," + c + ")";
- cxt.beginPath();
- cxt.arc(x, y, s, 0, Math.PI * 2, true);
- cxt.fill();
- cxt.stroke();
- }
- })();
- }, 100);
- }
- </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