Peano
to Peano :d
if :d = 0 [forward :atom stop]
Peano - :d 1
left 90
Peano - :d 1
repeat 3 [right 90 Peano - :d 1]
repeat 3 [left 90 Peano - :d 1]
right 90
Peano - :d 1
end
to peanoDraw :depth [:plane 300] 1
local "atom
make "atom :plane
repeat :depth [make "atom (/ :atom 3)]
penup
back / :plane 2
pendown
Peano :depth
end
(peanoDraw 1 200)
前回と同様な空間充填曲線の仲間の、ピアノ曲線です。
ちょっと書き順が、判りづらいので番号を振ってみました。
to PeanoZero :d :s
if :d = 0 [forward :s stop]
PeanoZero - :d 1 (/ :s 3) ;1
left 90
PeanoZero - :d 1 (/ :s 3) ;2
right 90
PeanoZero - :d 1 (/ :s 3) ;3
right 90
PeanoZero - :d 1 (/ :s 3) ;4
right 90
PeanoZero - :d 1 (/ :s 3) ;5
left 90
PeanoZero - :d 1 (/ :s 3) ;6
left 90
PeanoZero - :d 1 (/ :s 3) ;7
left 90
PeanoZero - :d 1 (/ :s 3) ;8
right 90
PeanoZero - :d 1 (/ :s 3) ;9
end
素直にプログラムすると上記の様に、番号と対応しますが、勿体無いので
repeat文でまとめているだけですね。
(peanoDraw 3 200)
再帰レベルを、ちょっと深くするだけで碁盤の目の様な図形になりますね。
更にレベルを深くすると、、、、、、。
left 45 cPeanoDraw 16
;------------------- Color version Peano curve -------------------
to precount :d :x
local "out
make "out 0
repeat :d [make "out (+ * :out :x 1)]
output :out
end
to sethpc :ct
(local "max "divval "modval)
name 255 "max
make "divval int quotient :ct 256
make "modval remainder :ct 256
if :divval < 0 or :divval > 5 [setpc 0 stop]
run item + :divval 1 [
[setpc (list :max :modval 0)]
[setpc (list (- :max :modval) :max 0)]
[setpc (list 0 :max :modval)]
[setpc (list 0 (- :max :modval) :max)]
[setpc (list :modval 0 :max)]
[setpc (list :max 0 (- :max :modval))]
]
end
to seconds.since.midnight
local "t
make "t time
output + + * first :t 3600 (* item 2 :t 60) last :t
end
to pass :seconds
(local
"passtime "h "m "s
"temp
)
make "passtime []
make "h int quotient :seconds 3600
make "temp difference :seconds (* h 3600)
make "m int quotient :temp 60
make "s difference :temp (* :m 60)
output fput :h fput :m fput :s :passtime
end
to cPeano :d
if :d = 0 [forward :atom stop]
sethpc round * :hcdiv :counter
make "counter sum :counter 1
cPeano - :d 1
left 90
cPeano - :d 1
repeat 3 [right 90 cPeano - :d 1]
repeat 3 [left 90 cPeano - :d 1]
right 90
cPeano - :d 1
end
to cPeanoDraw :depth [:plane 300] 1
(local
"atom "counter "hcdiv
"stime "etime
)
make "atom :plane
make "counter 0
make "hcdiv (/ 1535 precount :depth 9)
repeat :depth [make "atom (/ :atom 3)]
penup
back / :plane 2
pendown
make "stime seconds.since.midnight
cPeano :depth
make "etime seconds.since.midnight
print sentence "counter :counter
print sentence "|PassTime| pass - :etime :stime
end
描画時間が、計れる様に仕込んでみました。
再帰レベルが、10を超えると結構な時間が掛かります。iMac Rev.D
333MHz ではレベル16で5〜6時間掛かった様な....;-D
|