Help: #drawOn: method monopolizes processor
Bob Arning
arning at charm.net
Wed Jun 16 00:15:16 UTC 1999
On Tue, 15 Jun 1999 12:08:38 -0700 "Russ Van Rooy" <russvr at blarg.net> wrote:
> I think this would involve caching, drawing the object off-screen, and/or drawing the object in a seperate thread or process. How would I go about doing this ? Thanks in advance to anyone who can help !
Russ,
A separate thread/cached form version is included below. I have also posted a variant that uses the Mariani/Silver algorithm at:
http://www.charm.net/~arning/MandelBob.15Jun800pm.cs.txt
Check it out.
Cheers,
Bob
=======
'From Squeak 2.3 of January 14, 1999 on 15 June 1999 at 8:00:39 pm'!
BorderedMorph subclass: #MandelMorph
instanceVariableNames: 'cachedForm '
classVariableNames: 'ClassVarName1 ClassVarName2 '
poolDictionaries: ''
category: 'Morphic-RussProjects'!
!MandelMorph commentStamp: '<historical>' prior: 0!
MandelMorph draws a mandelbrot set . The drawing code was originally from a BASIC program in "Chaos, Fractals, and Dynamics" by Robert L. Devaney,Addison-Wesley, 1990 . Main problem/bug: the #drawOn: method takes over the processor completely. To run eval: " MandelMorph new " .!
!MandelMorph methodsFor: 'drawing' stamp: 'RAA 6/15/1999 16:39'!
drawCached
| c1 c2 x y x1 y1 r n canvas |
cachedForm _ Form extent: bounds extent depth: Display depth.
canvas _ FormCanvas on: cachedForm.
1.0 to: 300.0 do: [:i | 1.0 to: 150.0 do:
[:j |
c1 _ -2.0 + (4.0 * i / 300.0).
c2 _ 2.0 - (4.0 * j / 300.0).
x _ c1.
y _ c2.
n _ 0.
[x1 _ x squared - y squared + c1.
y1 _ 2 * x * y + c2.
r _ x1 squared + y1 squared.
r < 4.0 and: [n < 300.0]]
whileTrue:
[x _ x1.
y _ y1.
n _ n + 1].
n >= 300.0
ifTrue: [canvas
line: i @ j
to: i @ (300.0 - j)
color: Color red]].
self changed. "so we can watch it happen"
].
color _ Color lightBlue. "so we know when it is done"
self changed! !
!MandelMorph methodsFor: 'drawing' stamp: 'RAA 6/15/1999 16:35'!
drawOn: aCanvas
super drawOn: aCanvas.
cachedForm ifNil: [
[self drawCached] forkAt: Processor userBackgroundPriority.
^self
].
aCanvas image: cachedForm at: bounds origin! !
!MandelMorph methodsFor: 'initialization' stamp: 'rvr 6/15/1999 11:01'!
initialize
super initialize.
bounds _ 0 @ 0 corner: 500 @ 400.
color _ Color blue.
! !
More information about the Squeak-dev
mailing list
|