|
|
|
@ -66,11 +66,12 @@ function dragon_curve(variant) {
@@ -66,11 +66,12 @@ function dragon_curve(variant) {
|
|
|
|
|
* Sierpinski Triangle |
|
|
|
|
************************************************/ |
|
|
|
|
|
|
|
|
|
function sierpinski2(num_defects) { |
|
|
|
|
function sierpinski2(num_defects, noise) { |
|
|
|
|
project.clear(); |
|
|
|
|
if(typeof num_defects == 'undefined') { num_defects = 0 }; |
|
|
|
|
if(typeof noise == 'undefined') { noise = 0 }; |
|
|
|
|
var r = generate( |
|
|
|
|
'IA', |
|
|
|
|
'ImjJA', |
|
|
|
|
[ |
|
|
|
|
['A', 'B-A-B'], |
|
|
|
|
['B', 'A+B+A'] |
|
|
|
@ -86,12 +87,16 @@ function sierpinski2(num_defects) {
@@ -86,12 +87,16 @@ function sierpinski2(num_defects) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var actions = { |
|
|
|
|
// TODO properly initialize draw state and remove this |
|
|
|
|
'm': draw_forward(0.001), |
|
|
|
|
'A': draw_forward(), |
|
|
|
|
'B': draw_forward(), |
|
|
|
|
'I': draw_angle_init(Math.PI/3), |
|
|
|
|
'-': draw_angle_turn(-1), |
|
|
|
|
'+': draw_angle_turn(1), |
|
|
|
|
'*': draw_angle_add(0.001), |
|
|
|
|
'j': draw_set_turn_noise(noise/10), |
|
|
|
|
'J': draw_set_length_noise(noise), |
|
|
|
|
}; |
|
|
|
|
var p = draw(r, actions); |
|
|
|
|
p.scale(1.5); |
|
|
|
@ -104,10 +109,11 @@ function sierpinski2(num_defects) {
@@ -104,10 +109,11 @@ function sierpinski2(num_defects) {
|
|
|
|
|
* Sierpinski Triangle |
|
|
|
|
************************************************/ |
|
|
|
|
|
|
|
|
|
function sierpinski() { |
|
|
|
|
function sierpinski(noise) { |
|
|
|
|
if(typeof noise == 'undefined') { noise = 0 }; |
|
|
|
|
project.clear(); |
|
|
|
|
var r = generate( |
|
|
|
|
'IF-G-G', |
|
|
|
|
'ImjJF-G-G', |
|
|
|
|
[ |
|
|
|
|
['F', 'F-G+F+G-F'], |
|
|
|
|
['G', 'GG'] |
|
|
|
@ -123,6 +129,10 @@ function sierpinski() {
@@ -123,6 +129,10 @@ function sierpinski() {
|
|
|
|
|
'I': draw_angle_init(2*Math.PI/3), |
|
|
|
|
'-': draw_angle_turn(-1), |
|
|
|
|
'+': draw_angle_turn(1), |
|
|
|
|
'j': draw_set_turn_noise(noise/10), |
|
|
|
|
'J': draw_set_length_noise(noise), |
|
|
|
|
// TODO properly initialize draw state and remove this |
|
|
|
|
'm': draw_forward(0.001), |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
p.scale(5); |
|
|
|
@ -286,10 +296,18 @@ window.onload = function() {
@@ -286,10 +296,18 @@ window.onload = function() {
|
|
|
|
|
window.globals.sierpinski2(10); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('sierpinski2-noise').addEventListener('click', function() { |
|
|
|
|
window.globals.sierpinski2(0, 0.2); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('sierpinski').addEventListener('click', function() { |
|
|
|
|
window.globals.sierpinski(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('sierpinski-noise').addEventListener('click', function() { |
|
|
|
|
window.globals.sierpinski(0.2); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('barnsley-fern').addEventListener('click', function() { |
|
|
|
|
window.globals.barnsley_fern(); |
|
|
|
|
}); |
|
|
|
@ -312,7 +330,9 @@ window.onload = function() {
@@ -312,7 +330,9 @@ window.onload = function() {
|
|
|
|
|
<button id="dragon-curve-random-angles">dragon curve (random angles)</button> |
|
|
|
|
<button id="sierpinski2">sierpinski2</button> |
|
|
|
|
<button id="sierpinski2-defects">sierpinski2 (random defects)</button> |
|
|
|
|
<button id="sierpinski2-noise">sierpinski2 (noise)</button> |
|
|
|
|
<button id="sierpinski">sierpinski</button> |
|
|
|
|
<button id="sierpinski-noise">sierpinski (noise)</button> |
|
|
|
|
<button id="barnsley-fern">barnsley fern</button> |
|
|
|
|
<button id="barnsley-fern-defects">barnsley fern (random defects)</button> |
|
|
|
|
<button id="other-tree">other tree</button> |
|
|
|
|