Squeak Smalltalk でマンデルブロ集合 その2(id:squeakerさん版)
コメントでいただいた id:squeakerさんのコードに僭越ながら少し手を入れたものを。FlaotArray>>#*= とか知らなくてなんじゃこれ?!となったのは内緒です。^^; Float nan や Float infinity の振る舞いを利用するのは面白いですね。
| size half zREs zIMs prevREs prevIMs cREs cIMs idx time | size := 600. half := size / 2. zREs := FloatArray new: size * size. zIMs := FloatArray new: size * size. prevREs := FloatArray new: size * size. prevIMs := FloatArray new: size * size. cREs := FloatArray new: size * size. cIMs := FloatArray new: size * size. idx := 1. half negated to: half - 1 do: [:y | half negated to: half - 1 do: [:x | cREs at: idx put: x / half. cIMs at: idx put: y / half. idx := idx + 1 ] ]. cREs -= 0.5. time := [ 1 to: 100 do: [:z | zREs replaceFrom: 1 to: zREs size with: prevREs startingAt: 1. zIMs replaceFrom: 1 to: zIMs size with: prevIMs startingAt: 1. zREs *= prevREs -= (prevIMs *= prevIMs) += cREs. zIMs *= prevREs *= 2.0 += cIMs. {prevREs. prevIMs} elementsExchangeIdentityWith: {zREs. zIMs}. "prevREs := zREs. zREs := (zREs * zREs) - (zIMs * zIMs) + cREs. zIMs := (zIMs * prevREs) + (prevREs * zIMs) + cIMs." ] ] timeToRun. Display restoreAfter: [ idx := 1. 0 to: size - 1 do: [:y | 0 to: size - 1 do: [:x | | re im | re := prevREs at: idx. im := prevIMs at: idx. idx := idx + 1. ((re isNaN not and: [re isInfinite not]) and: [im isNaN not and: [im isInfinite not]]) ifTrue: [Display colorAt: x@y put: Color black] ifFalse: [Display colorAt: x@y put: Color white] ] ]. [Sensor anyButtonPressed] whileFalse ]. time "=> 16442 vs 25594 "