Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
42
Task/Barnsley-fern/JavaScript/barnsley-fern-1.js
Normal file
42
Task/Barnsley-fern/JavaScript/barnsley-fern-1.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Barnsley fern fractal
|
||||
//6/17/16 aev
|
||||
function pBarnsleyFern(canvasId, lim) {
|
||||
// DCLs
|
||||
var canvas = document.getElementById(canvasId);
|
||||
var ctx = canvas.getContext("2d");
|
||||
var w = canvas.width;
|
||||
var h = canvas.height;
|
||||
var x = 0.,
|
||||
y = 0.,
|
||||
xw = 0.,
|
||||
yw = 0.,
|
||||
r;
|
||||
// Like in PARI/GP: return random number 0..max-1
|
||||
function randgp(max) {
|
||||
return Math.floor(Math.random() * max)
|
||||
}
|
||||
// Clean canvas
|
||||
ctx.fillStyle = "white";
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
// MAIN LOOP
|
||||
for (var i = 0; i < lim; i++) {
|
||||
r = randgp(100);
|
||||
if (r <= 1) {
|
||||
xw = 0;
|
||||
yw = 0.16 * y;
|
||||
} else if (r <= 8) {
|
||||
xw = 0.2 * x - 0.26 * y;
|
||||
yw = 0.23 * x + 0.22 * y + 1.6;
|
||||
} else if (r <= 15) {
|
||||
xw = -0.15 * x + 0.28 * y;
|
||||
yw = 0.26 * x + 0.24 * y + 0.44;
|
||||
} else {
|
||||
xw = 0.85 * x + 0.04 * y;
|
||||
yw = -0.04 * x + 0.85 * y + 1.6;
|
||||
}
|
||||
x = xw;
|
||||
y = yw;
|
||||
ctx.fillStyle = "green";
|
||||
ctx.fillRect(x * 50 + 260, -y * 50 + 540, 1, 1);
|
||||
} //fend i
|
||||
}
|
||||
7
Task/Barnsley-fern/JavaScript/barnsley-fern-2.js
Normal file
7
Task/Barnsley-fern/JavaScript/barnsley-fern-2.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<head><script src="BarnsleyFern.js"></script></head>
|
||||
<body onload="pBarnsleyFern('canvas', 100000)">
|
||||
<br /> <h3>Barnsley fern fractal</h3>
|
||||
<canvas id="canvas" width="540" height="540" style="border: 2px inset;"></canvas>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue