forked from pypyjs/pypyjs-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.html
87 lines (84 loc) · 3.46 KB
/
mandelbrot.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<html>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta charset="utf-8">
<title>PyPy.js - Mandelbrot</title>
<style>
button {
display:none;
}
pre {
width: 90%;
height: 20%;
margin: 1em;
padding: 1em;
border: 5px solid #ddd;
overflow: auto;
}
</style>
</head>
<body>
<h1>PyPy.js - Mandelbrot</h1>
<p>
Render Mandelbrot fractal with <a href="https://pypyjs.org">PyPy.js</a>
</p>
<a href="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/jedie/pypyjs-examples"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<noscript><h3>Please enable JavaScript for using PyPy.js</h3></noscript>
<pre id="output"></pre>
<hr />
<p>
PyPy.js is an experiment in building a fast and compliant python environment for the web.
<br/>
It uses the <a href="https://pypy.org/">PyPy</a> python interpreter, compiled for the web via
<a href="https://emscripten.org">emscripten</a>, with a custom JIT backend that emits <a href="https://asmjs.org">asm.js</a>
code at runtime.
</p>
</div>
<script src="pypyjs-release/lib/Promise.min.js" type="text/javascript" charset="utf-8" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script src="pypyjs-release/lib/FunctionPromise.js" type="text/javascript" charset="utf-8" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script src="pypyjs-release/lib/pypyjs.js" type="text/javascript" charset="utf-8" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" onerror="JavaScript:alert('Error loading file ['+this.src+'] !');"></script>
<script type="text/javascript" charset="utf-8">
try {
jQuery(document);
} catch (e) {
alert("Error, jQuery JS not loaded!\n Original error was:" + e);
}
function console_exec(code) {
pypyjs.exec(code).then(function() {
console.log("OK");
}, function (err) {
// err is an instance of PyPyJS.Error
console.log("ERROR: "+err.name+": "+err.message+"!)");
pypyjs.stderr(err.trace); // the human-readable traceback, as a string
});
}
$(function () {
out = $("#output");
pypyjs.stdout = pypyjs.stderr = function(data) {
out.append(data);
out.scrollTop(out.prop("scrollHeight")); // scoll down
}
pypyjs.stdout.reset = pypyjs.stderr.reset = function(data) {
out.empty();
}
// Display a helpful message and twiddle thumbs as it loads.
pypyjs.stdout("Loading PyPy.js.\n\n");
pypyjs.stdout('It\'s big, so this might take a while...');
var pseudo_status = setInterval(function(){ pypyjs.stdout("."); }, 500);
pypyjs.ready().then(function() {
clearInterval(pseudo_status);
pypyjs.stdout.reset();
pypyjs.stdout("load 'mandelbrot.py'...");
$.get( "mandelbrot.py", function( data ) {
console_exec( data );
}).done(function() {
pypyjs.stdout("OK\n");
}).fail(function() {
pypyjs.stderr("error!");
});
});
});
</script>
</body>
</html>