Fibonacci word/fractal: Difference between revisions

Content added Content deleted
(new Logo)
Line 336: Line 336:
return p1
return p1
end</lang>
end</lang>

=={{header|Logo}}==
<code>fibonacci.word.fractal</code> can draw any number of line segments. A Fibonacci number shows the self-similar nature of the fractal. The Fibonacci word values which control the turns are generated here by some bit-twiddling iteration.

{{works with|ucblogo}}
<lang Logo>; Return the low 1-bits of :n
; For example if n = binary 10110111 = 183
; then return binary 111 = 7
to low.ones :n
output ashift (bitxor :n (:n+1)) -1
end

; :fibbinary should be a fibbinary value
; return the next larger fibbinary value
to fibbinary.next :fibbinary
localmake "filled bitor :fibbinary (ashift :fibbinary -1)
localmake "mask low.ones :filled
output (bitor :fibbinary :mask) + 1
end

to fibonacci.word.fractal :steps
localmake "step.length 5 ; length of each step
localmake "fibbinary 0
repeat :steps [
forward :step.length
if (bitand 1 :fibbinary) = 0 [
ifelse (bitand repcount 1) = 1 [right 90] [left 90]
]
make "fibbinary fibbinary.next :fibbinary
]
end

setheading 0 ; initial line North
fibonacci.word.fractal 377</lang>


=={{header|Perl}}==
=={{header|Perl}}==
Line 376: Line 410:
close $out;
close $out;
</lang>
</lang>



=={{header|Python}}==
=={{header|Python}}==