mirror of
https://github.com/danbee/canvas
synced 2025-03-04 08:39:08 +00:00
50 lines
1.1 KiB
HTML
50 lines
1.1 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Mandelbrot</title>
|
|
<style>
|
|
body {
|
|
position: relative;
|
|
text-align: center;
|
|
}
|
|
button {
|
|
position: absolute;
|
|
top: 5px;
|
|
left: 5px;
|
|
}
|
|
canvas {
|
|
width: 640px;
|
|
height: 640px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="mandelbrot" width="1280" height="1280">
|
|
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var canvas = document.getElementById('mandelbrot');
|
|
var context = canvas.getContext('2d');
|
|
|
|
context.fillStyle = 'black';
|
|
|
|
worker = new Worker("mandelbrot.js");
|
|
worker.addEventListener('message', function(e) {
|
|
// console.log("Plot: " + e.data.x + ", " + e.data.y);
|
|
if (e.data.i == 0) {
|
|
a = 1;
|
|
}
|
|
else {
|
|
a = e.data.i / 100
|
|
}
|
|
context.fillStyle = "rgba(0, 0, 0, " + a + ")";
|
|
console.log(context.fillStyle);
|
|
context.fillRect(e.data.x, e.data.y, 1, 1);
|
|
}, false);
|
|
worker.postMessage("");
|
|
})();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|