Browse Source

add hilbert curve with noise

master
Fr3deric 5 years ago
parent
commit
4adfaf1b07
  1. 40
      lindenmayer-system/lindenmeyer-system.html

40
lindenmayer-system/lindenmeyer-system.html

@ -141,6 +141,40 @@ function sierpinski(noise) {
p.strokeColor = '#ff00ff'; p.strokeColor = '#ff00ff';
} }
/************************************************
* Hilbert Curve
************************************************/
function hilbert() {
project.clear();
var r = generate(
'ImjJA',
[
['A', '-BF+AFA+FB-'],
['B', '+AF-BFB-FA+']
],
6
);
var p = draw(
r,
{
'F': draw_forward(),
'I': draw_angle_init(Math.PI/2),
'-': draw_angle_turn(-1),
'+': draw_angle_turn(1),
'j': draw_set_turn_noise(0.05),
'J': draw_set_length_noise(0.1),
'm': draw_forward(0.001),
}
);
p.scale(5);
p.translate(new Point(200, 200));
p.strokeWidth = 1;
p.strokeColor = '#ff00ff';
}
/************************************************ /************************************************
* Barnsley Fern * Barnsley Fern
@ -249,6 +283,7 @@ function sierpinski(noise) {
globals.dragon_curve = dragon_curve; globals.dragon_curve = dragon_curve;
globals.sierpinski2 = sierpinski2; globals.sierpinski2 = sierpinski2;
globals.sierpinski = sierpinski; globals.sierpinski = sierpinski;
globals.hilbert = hilbert;
globals.barnsley_fern = barnsley_fern; globals.barnsley_fern = barnsley_fern;
globals.other_tree = other_tree; globals.other_tree = other_tree;
@ -308,6 +343,10 @@ window.onload = function() {
window.globals.sierpinski(0.2); window.globals.sierpinski(0.2);
}); });
document.getElementById('hilbert').addEventListener('click', function() {
window.globals.hilbert();
});
document.getElementById('barnsley-fern').addEventListener('click', function() { document.getElementById('barnsley-fern').addEventListener('click', function() {
window.globals.barnsley_fern(); window.globals.barnsley_fern();
}); });
@ -333,6 +372,7 @@ window.onload = function() {
<button id="sierpinski2-noise">sierpinski2 (noise)</button> <button id="sierpinski2-noise">sierpinski2 (noise)</button>
<button id="sierpinski">sierpinski</button> <button id="sierpinski">sierpinski</button>
<button id="sierpinski-noise">sierpinski (noise)</button> <button id="sierpinski-noise">sierpinski (noise)</button>
<button id="hilbert">hilbert</button>
<button id="barnsley-fern">barnsley fern</button> <button id="barnsley-fern">barnsley fern</button>
<button id="barnsley-fern-defects">barnsley fern (random defects)</button> <button id="barnsley-fern-defects">barnsley fern (random defects)</button>
<button id="other-tree">other tree</button> <button id="other-tree">other tree</button>

Loading…
Cancel
Save