Section 4

We can use these new mask forms for drawing our laser beam. The masks will have to be saved. We can use the same technique as before.

Before we destroy the contents of our workspace we should probably save this. It's pretty handy if we want to go back and create the mask forms again in the future. We didn't really create any sort of utility classes so far. The GridFactory class is kind of a utility class but it's used to create our random grids now. I think we can just add a new class method on the LaserGameForms class where we can safely put this workspace code. Don't close the workspace yet. Open up a class hierarchy browser on the LaserGameForms and save this new class method.

extractLaserBeamMaskForms
    "LaserGameForms extractLaserBeamMaskForms"

    | beamForm newExtent splatterForm centerForm color splatterMask centerMask |
    self initializeCachedForms.
    beamForm := LaserGameForms laserBeam.
    newExtent := beamForm extent * (2@1).
    splatterForm := Form extent: newExtent depth: beamForm depth.
    centerForm := Form extent: newExtent depth: beamForm depth.
    beamForm displayOn: splatterForm at: 0@0.
    beamForm displayOn: centerForm at: 0@0.
    (beamForm flipBy: #horizontal centerAt: 0@0)
        displayOn: splatterForm at: (beamForm width@0);
        displayOn: centerForm at: (beamForm width@0).
    color := splatterForm colorAt: 10@60.
    splatterForm replaceColor: color withColor: Color white.
    centerForm replaceColor: color withColor: Color white.
    splatterMask := (splatterForm makeBWForm: Color white) reverse.
    color := beamForm colorAt: 10@90.
    centerForm replaceColor: color withColor: Color black.
    centerMask := centerForm makeBWForm: Color black.
    splatterForm displayAt: 10@0.
    splatterMask displayAt: 10@200.
    centerMask displayAt: 10@400.
    color := beamForm colorAt: 10@80.
    splatterMask
        displayOn: Display
        at: 10@560
        clippingBox: Display boundingBox
        rule: Form oldPaint
        fillColor: color.
    centerMask
        displayOn: Display
        at: 10@560
        clippingBox: Display boundingBox
        rule: Form oldPaint
        fillColor: (Color r: 0.909 g: 1.0 b: 0.27)

Open up the Transcript window and make sure it's empty. We'll modify our workspace to dump the mask forms onto the Transcript. Try this in your workspace.

LaserGameForms initializeCachedForms.
beamForm := LaserGameForms laserBeam.
newExtent := beamForm extent * (2@1).
splatterForm := Form extent: newExtent depth: beamForm depth.
centerForm := Form extent: newExtent depth: beamForm depth.
beamForm displayOn: splatterForm at: 0@0.
beamForm displayOn: centerForm at: 0@0.
(beamForm flipBy: #horizontal centerAt: 0@0)
    displayOn: splatterForm at: (beamForm width@0);
    displayOn: centerForm at: (beamForm width@0).
color := splatterForm colorAt: 10@60.
splatterForm replaceColor: color withColor: Color white.
centerForm replaceColor: color withColor: Color white.
splatterMask := (splatterForm makeBWForm: Color white) reverse.
color := beamForm colorAt: 10@90.
centerForm replaceColor: color withColor: Color black.
centerMask := centerForm makeBWForm: Color black.
Transcript
    show: 'drawSplatterLaserBeamMask'; cr;
    show: ' ^'.
splatterMask storeOn: Transcript.
Transcript
    show: ''; cr.

This is a little different from before. We saved some work by having the method code written complete to the Transcript. Select the code from the Transcript window and paste in as a new class method on the LaserGameForms class.

Clear the contents of the Transcript and try this in your workspace and execute it.

LaserGameForms initializeCachedForms.
beamForm := LaserGameForms laserBeam.
newExtent := beamForm extent * (2@1).
splatterForm := Form extent: newExtent depth: beamForm depth.
centerForm := Form extent: newExtent depth: beamForm depth.
beamForm displayOn: splatterForm at: 0@0.
beamForm displayOn: centerForm at: 0@0.
(beamForm flipBy: #horizontal centerAt: 0@0)
displayOn: splatterForm at: (beamForm width@0);
displayOn: centerForm at: (beamForm width@0).
color := splatterForm colorAt: 10@60.
splatterForm replaceColor: color withColor: Color white.
centerForm replaceColor: color withColor: Color white.
splatterMask := (splatterForm makeBWForm: Color white) reverse.
color := beamForm colorAt: 10@90.
centerForm replaceColor: color withColor: Color black.
centerMask := centerForm makeBWForm: Color black.
Transcript
show: 'drawCenterLaserBeamMask'; cr;
show: ' ^'.
centerMask storeOn: Transcript.
Transcript
show: ''; cr.

Again, copy the contents of the Transcript window and paste them in as a new class method on the LaserGameForms class.

We're done with the Transcript window and your workspace. You can close them both.

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels    stevewessels@me.com