Object subclass: #Mandelbrot instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Graphics-Fractal'! !Mandelbrot methodsFor: 'as yet unclassified' stamp: 'tf 8/30/2002 23:29'! mandelbrot1 | x y delta a b a2 b2 count r g size milliseconds | milliseconds _ Time millisecondsToRun:[ size _ 500. delta _ (2.2/size)@(2.2/size). 1 to:size do:[ :i | x _ (-0.7 + (delta x * i)) asFloat. 1 to:size do:[ :j | y _ (1 - (delta y * j)) asFloat. a _ x. b _ y. a2 _ a * a. b2 _ b * b. count _ 512. [((a2 + b2) <= 4) and:[count > 0]] whileTrue:[ b _ 2 * a * b - y. a _ a2 - b2 - x. a2 _ a * a. b2 _ b * b. count _ count - 1. ]. r _ count >> 6. g _ (count >> 3) bitAnd:7. b _ count bitAnd:7. Display colorAt:(i@j) put:(Color r:r g:g b:b range:3). ]. ]. ]. Transcript show:'Mandelbrot (', size printString, 'X', size printString,') took ', milliseconds printString, ' msec.'; cr. " Z0 = 0, Zn+1 = Zn^2 - c (n=0,1,2...) z _ x + iy; count _ M. while (|z| <= 4) and (count > 0) do begin z _ z^2 - (x + iy); count--; end while count = 0 -> black " ! ! !Mandelbrot methodsFor: 'as yet unclassified' stamp: 'tf 8/30/2002 23:30'! mandelbrot2 | aRectangle flag sPos ePos newRect factor | sPos _ -2@-2. ePos _ 2@2. aRectangle _ Rectangle fromUser. Transcript show:'aRectangle:', aRectangle printString; cr. flag _ true. [flag] whileTrue:[ Transcript show:'sPos:', sPos printString, ' ePos:', ePos printString; cr. self mandelbrotAt:aRectangle from:sPos to:ePos. newRect _ Rectangle fromUser. Transcript show:'newRect:', newRect printString; cr. flag _ aRectangle containsRect:newRect. flag ifTrue:[ factor _ (sPos corner:ePos) scaleBy:1000. Transcript show:'factor:', factor printString; cr. newRect _ (newRect scaleFrom:aRectangle to:factor) scaleBy:0.001. sPos _ newRect origin. ePos _ newRect corner. ]. ]. ! ! !Mandelbrot methodsFor: 'as yet unclassified' stamp: 'tf 8/30/2002 23:23'! mandelbrotAt:aRectangle from:startPoint to:endPoint | x y delta a b a2 b2 count r g offsetX offsetY | offsetX _ aRectangle left. offsetY _ aRectangle top. delta _ endPoint - startPoint. delta setX:(delta x / aRectangle width) setY:(delta y / aRectangle height). Transcript show:'delta x:', delta x asFloat printString, ' y:', delta y asFloat printString; cr. 1 to:(aRectangle width) do:[ :i | x _ (startPoint x + (i * delta x)) asFloat. 1 to:(aRectangle height) do:[ :j | y _ (startPoint y + (delta y * j)) asFloat. a _ x. b _ y. a2 _ a * a. b2 _ b * b. count _ 512. [((a2 + b2) <= 4) and:[count > 0]] whileTrue:[ b _ 2 * a * b + y. a _ a2 - b2 - x. a2 _ a * a. b2 _ b * b. count _ count - 1. ]. "(count = 512) ifFalse:[ Transcript show:'x:', i printString, ' y:', j printString, ' v:', count printString ;cr. ]." r _ count >> 6. g _ (count >> 3) bitAnd:7. b _ count bitAnd:7. Display colorAt:((i+offsetX)@(j+offsetY)) put:(Color r:r g:g b:b range:3). ]. ]. " Z0 = 0, Zn+1 = Zn^2 + c (n=0,1,2...) z _ x + iy; count _ M. while (|z| <= 4) and (count > 0) do begin z _ z^2 + (x + iy); count--; end while count = 0 -> black " ! !