ASCII Mandelbrot (was: Debugging assistance please :-) )
Christopher Barham
cbarham at pobox.com
Wed Oct 27 03:36:40 UTC 2004
Thanks to both Avi and Richard for taking the time to help me out. I was
confused with ifTrue: and IfFalse, I, (half), remembered that it was
considered better style to bracket your boolean conditions to make things
slightly more readable; but a whileTrue: is not the same as ifTrue:
though... ;-)
Once running I found that it was extremely slow with Transcript show:
(probably because the chars had to be converted to strings and then
flushed), changing things to nextPut: really sped things up. The current
method code is below. Can anyone suggest anything else I could improve to
make it more 'Squeak-Like' - I was thinking that sunit tests and a little
refactoring would be useful next step.
"Generate a MandelBrot image using only ASCII characters."
| d r n h |
Transcript show: Character cr.
1.1
to: -1.1001
by: -0.1
do: [:e |
-2.0
to: 0.9601
by: 0.04
do: [:b |
r := 0.0.
n := 0.0.
h := 127.
[r * r + (n * n) < 4.0
and: [h > 32]]
whileTrue: [h := h - 1.
d := r.
r := r * r - (n * n) + b.
n := 2 * d * n + e].
Transcript
nextPut: (Character
value: (b > 1
ifTrue: [13]
ifFalse: [h]))].
Transcript show: Character cr]
Thanks again :-)
Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2113 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20041027/07ebdb2c/smime.bin
More information about the Squeak-dev
mailing list
|