/*
|
* ifs.js
|
*
|
*/
|
|
import "./lib/dfhi.js";
|
import * as JXG from "jsxgraph" ;
|
|
import * as DHFIRandom from "./lib/dfhi-random";
|
import {exportBoard} from "./lib/dfhi-plot";
|
|
|
let board = undefined;
|
function initBoard() {
|
return JXG.JSXGraph.initBoard('plotter', {
|
boundingbox: [-6, 12, 6, -1],
|
axis: false,
|
keepAspectRatio:true
|
});
|
}
|
|
window.init = function() {
|
board = initBoard();
|
function exportSvg(event) {
|
exportBoard(board);
|
}
|
document.getElementById("export")
|
.addEventListener("click", exportSvg);
|
};
|
|
const tanenbaum = [
|
[ 0.0, 0.0, 0.0, 0.160, 0.0, 0.0, 0.03],
|
[ 0.197, -0.026, 0.226, 0.197, 0.0, 1.6, 0.14],
|
[-0.155, 0.283, 0.260, 0.237, 0.0, 0.44, 0.27],
|
[-0.849, 0.037,-0.037, 0.849, 0.0, 1.6, 0.56]
|
];
|
|
window.main = function(...argv) {
|
if (board) {
|
try {
|
JXG.JSXGraph.freeBoard(board);
|
board = undefined;// remove all child of board
|
board = initBoard();
|
}catch (e) {
|
console.log(e);
|
console.log(board);
|
}
|
}
|
let n = Number.parseInt(argv[0]);
|
let points = ifs (tanenbaum, n);
|
let opt = {withLabel:false, fixed:true, size:0.001, fillColor:"#00aa00", strokeWidth:0};
|
plotBarnsley(board, points, opt);
|
};
|
|
|
function ifs(matrix, iteration) {
|
let p = [];
|
for(let i = 0; i < matrix.length; ++i) {
|
p.push(matrix[i][6])
|
}
|
let x = 0, y = 0;
|
let points = [ [x, y] ];
|
for(let i = 0; i < iteration; ++i ) {
|
let r = DHFIRandom.discrete(p);
|
let nX = (matrix[r][0] * x) + (matrix[r][1] * y) + matrix[r][4];
|
y = (matrix[r][2] * x) + (matrix[r][3] * y) + matrix[r][5];
|
x = nX;
|
points.push([x,y]);
|
}
|
return points;
|
}
|
|
/**
|
*
|
* @param board
|
* @param points
|
* @param attr
|
*
|
* */
|
function plotBarnsley(board, points, attr ) {
|
for(let p of points) {
|
board.create('point', p, attr );
|
}
|
}
|