INSTALLED SQUEAK METHOD SOURCE Extracted from this project image and compared with installed compiled methods. Method fragments for the corresponding Browser class/side; this is not a file-in. BouncingAtomsMorph >> initialize initialize "initialize the state of the receiver" super initialize. "" damageReported := false. self extent: 400 @ 250. infectionHistory := OrderedCollection new. transmitInfection := false. self addAtoms: 30 ----------------------------- BouncingAtomsMorph >> step step "Bounce those atoms!" | r bounces | super step. bounces := 0. r := bounds origin corner: (bounds corner - (8@8)). self submorphsDo: [ :m | (m isMemberOf: AtomMorph) ifTrue: [ (m bounceIn: r) ifTrue: [bounces := bounces + 1]]]. "compute a 'temperature' that is proportional to the number of bounces divided by the circumference of the enclosing rectangle" self updateTemperature: (10000.0 * bounces) / (r width + r height). transmitInfection ifTrue: [self transmitInfection]. ----------------------------- BouncingAtomsMorph >> stepTime stepTime "As fast as possible." ^ 0 ----------------------------- AtomMorph >> bounceIn: bounceIn: aRect "Move this atom one step along its velocity vector and make it bounce if it goes outside the given rectangle. Return true if it is bounced." | p vx vy px py bounced | p := self position. vx := velocity x. vy := velocity y. px := p x + vx. py := p y + vy. bounced := false. px > aRect right ifTrue: [ px := aRect right - (px - aRect right). vx := velocity x negated. bounced := true]. py > aRect bottom ifTrue: [ py := aRect bottom - (py - aRect bottom). vy := velocity y negated. bounced := true]. px < aRect left ifTrue: [ px := aRect left - (px - aRect left). vx := velocity x negated. bounced := true]. py < aRect top ifTrue: [ py := aRect top - (py - aRect top). vy := velocity y negated. bounced := true]. self position: px @ py. bounced ifTrue: [self velocity: vx @ vy]. ^ bounced ----------------------------- BouncingAtomsMorph >> startInfection startInfection self submorphsDo: [:m | m infected: false]. self firstSubmorph infected: true. infectionHistory := OrderedCollection new: 500. transmitInfection := true. self startStepping. ----------------------------- BouncingAtomsMorph >> transmitInfection transmitInfection | count | self collisionPairs do: [:pair | | infected | infected := false. pair do: [:atom | atom infected ifTrue: [infected := true]]. infected ifTrue: [pair do: [:atom | atom infected: true]]]. count := 0. self submorphsDo: [:m | m infected ifTrue: [count := count + 1]]. infectionHistory addLast: count. count = submorphs size ifTrue: [ transmitInfection := false. self stopStepping]. ----------------------------- BouncingAtomsMorph >> collisionPairs collisionPairs "Return a list of pairs of colliding atoms, which are assumed to be circles of known radius. This version uses the morph's positions--i.e. the top-left of their bounds rectangles--rather than their centers." | count sortedAtoms radius twoRadii radiiSquared collisions p1 continue j p2 distSquared m1 m2 | count := submorphs size. sortedAtoms := submorphs sorted: [:mt1 :mt2 | mt1 position x < mt2 position x]. radius := 8. twoRadii := 2 * radius. radiiSquared := radius squared * 2. collisions := OrderedCollection new. 1 to: count - 1 do: [:i | m1 := sortedAtoms at: i. p1 := m1 position. continue := (j := i + 1) <= count. [continue] whileTrue: [m2 := sortedAtoms at: j. p2 := m2 position. continue := p2 x - p1 x <= twoRadii ifTrue: [distSquared := (p1 x - p2 x) squared + (p1 y - p2 y) squared. distSquared < radiiSquared ifTrue: [collisions add: (Array with: m1 with: m2)]. (j := j + 1) <= count] ifFalse: [false]]]. ^collisions ----------------------------- AtomMorph >> infected: infected: aBoolean aBoolean ifTrue: [self color: Color red] ifFalse: [self color: Color blue]. ----------------------------- MovingEyeMorph class >> extraExampleSqueakIsWatchingYou extraExampleSqueakIsWatchingYou "MovingEyeMorph extraExampleSqueakIsWatchingYou openInHand" | logoMorph leftEye rightEye | logoMorph := Form squeakLogo asMorph. leftEye := self new extent: logoMorph extent * (0.1 @ 0.15); center: (logoMorph pointAtFraction: 0.39 @ 0.55); yourself. rightEye := self new extent: logoMorph extent * (0.1 @ 0.15); center: (logoMorph pointAtFraction: 0.59 @ 0.56); yourself. logoMorph addAllMorphs: {leftEye. rightEye}. ^ logoMorph. ----------------------------- MovingEyeMorph >> step step | cp | cp := self globalPointToLocal: self world primaryHand position. (inner containsPoint: cp) ifTrue: [iris position: (cp - (iris extent // 2))] ifFalse: [self irisPos: cp]. ----------------------------- MovingEyeMorph >> irisPos: irisPos: cp | a b theta x y | theta := (cp - self center) theta. a := inner width // 2. b := inner height // 2. x := a * (theta cos). y := b * (theta sin). iris position: ((x@y) asIntegerPoint) + self center - (iris extent // 2). ----------------------------- Flasher >> step step "Perform my standard periodic action" super step. self color = self onColor ifTrue: [self color: (onColor alphaMixed: 0.5 with: Color black)] ifFalse: [self color: onColor] ----------------------------- Flasher >> stepTime stepTime "Answer the desired time between steps, in milliseconds." ^ 500 ----------------------------- Flasher >> onColor onColor "Answer my onColor" ^ onColor ifNil: [onColor := Color red] ----------------------------- WatchMorph class >> example example "WatchMorph example openInWorld" ^ (WatchMorph fontName: #BitstreamVeraSerif bgColor: Color lightGray centerColor: Color red paler) handsColor: Color grape; toggleRoman; yourself ----------------------------- WatchMorph >> drawOn: drawOn: aCanvas "Draw the watch on the given canvas" | pHour pMin pSec time centerColor | time := Time now. pHour := self radius: 0.6 hourAngle: time hours + (time minutes/60.0). pMin := self radius: 0.72 hourAngle: (time minutes / 5.0). pSec := self radius: 0.8 hourAngle: (time seconds / 5.0). centerColor := cColor ifNil: [Color transparent] ifNotNil: [time hours < 12 ifTrue: [cColor muchLighter] ifFalse: [cColor]]. antialias ifTrue: [aCanvas asBalloonCanvas aaLevel: 4; drawOval: (self bounds insetBy: self borderWidth // 2 + 1) color: self fillStyle borderWidth: self borderWidth borderColor: self borderColor; drawOval: (self bounds insetBy: self extent*0.35) color: centerColor borderWidth: 0 borderColor: Color black; drawPolygon: {self center. pHour} color: Color transparent borderWidth: 3 borderColor: handsColor; drawPolygon: {self center. pMin} color: Color transparent borderWidth: 2 borderColor: handsColor; drawPolygon: {self center. pSec} color: Color transparent borderWidth: 1 borderColor: handsColor] ifFalse: [super drawOn: aCanvas. aCanvas fillOval: (self bounds insetBy: self extent*0.35) color: centerColor; line: self center to: pHour width: 3 color: handsColor; line: self center to: pMin width: 2 color: handsColor; line: self center to: pSec width: 1 color: handsColor] ----------------------------- WatchMorph >> toggleRoman toggleRoman romanNumerals := romanNumerals not. self createLabels ----------------------------- ClockMorph >> step step | time | super step. time := String streamContents: [ :stream | | t | t := Time now. t seconds: t asSeconds. "ignore nanoSeconds" t print24: (show24hr == true) showSeconds: (showSeconds == true) on: stream]. self contents: time ----------------------------- MagnifierMorph class >> newShowingPointer newShowingPointer "Answer a Magnifier that also displays Morphs in the Hand and the Hand position" ^(self new) showPointer: true; setNameTo: 'HandMagnifier'; yourself ----------------------------- MagnifierMorph >> sourcePoint sourcePoint "If we are being dragged use our center, otherwise use pointer position" ^(trackPointer not or: [owner notNil and: [owner isHandMorph]]) ifTrue: [self isFlexed ifTrue:[owner center] ifFalse:[self center]] ifFalse: [self currentHand position] ----------------------------- MagnifierMorph >> magnifiedForm magnifiedForm "Answer the magnified form" | srcRect form exclusion magnified | srcRect := self sourceRectFrom: self sourcePoint. (RecursionLock isNil and: [ self showPointer or: [ srcRect intersects: self bounds ]]) ifTrue: [RecursionLock := self. exclusion := self. form := self currentWorld patchAt: srcRect without: exclusion andNothingAbove: false. RecursionLock := nil] ifFalse: ["cheaper method if the source is not occluded" form := Display copy: srcRect]. "smooth if non-integer scale" magnified := form magnify: form boundingBox by: magnification smoothing: (magnification isInteger ifTrue: [1] ifFalse: [2]). "display the pointer rectangle if desired" self showPointer ifTrue: [magnified reverse: (magnified center - (2 @ 2) extent: 4 @ 4) fillColor: Color white]. ^ magnified ----------------------------- Tetris >> initialize initialize "initialize the state of the receiver" super initialize. "" board := TetrisBoard new game: self. self listDirection: #topToBottom; wrapCentering: #center; vResizing: #shrinkWrap; hResizing: #shrinkWrap; layoutInset: 3; addMorphBack: self makeGameControls; addMorphBack: self makeMovementControls; addMorphBack: self showScoreDisplay; addMorphBack: board. board newGame ----------------------------- Tetris >> keyStroke: keyStroke: evt | charValue | charValue := evt keyCharacter asciiValue. charValue = 28 ifTrue: [board moveLeft]. charValue = 29 ifTrue: [board moveRight]. charValue = 30 ifTrue: [board rotateClockWise]. charValue = 31 ifTrue: [board rotateAntiClockWise]. charValue = 32 ifTrue: [board dropAllTheWay]. ----------------------------- TetrisBoard >> step step (self ownerThatIsA: HandMorph) ifNotNil: [^self]. paused ifTrue: [^ self]. currentBlock ifNil: [ currentBlock := TetrisBlock new. self addMorphFront: currentBlock. currentBlock board: self. ] ifNotNil: [ currentBlock dropByOne ifFalse: [self storePieceOnBoard] ]. ----------------------------- TetrisBoard >> dropAllTheWay dropAllTheWay self running ifFalse: [^ self]. [currentBlock dropByOne] whileTrue: [ self score: score + 1 ]. ----------------------------- SameGame >> initialize initialize "initialize the state of the receiver" super initialize. "" self listDirection: #topToBottom; wrapCentering: #center; cellPositioning: #topCenter; vResizing: #shrinkWrap; hResizing: #shrinkWrap; layoutInset: 3; addMorph: self makeControls; addMorph: self board. helpText := nil. self newGame ----------------------------- SameGameBoard >> hint hint "find a possible selection and select it" | tile | self deselectSelection. tile := self findSelection. tile ifNotNil: [tile mouseDown: MouseButtonEvent new] ----------------------------- SameGameBoard >> removeSelection removeSelection selection ifNil: [^ self]. self rememberUndoableAction: [selection do: [:loc | (self tileAt: loc) setSwitchState: false; disabled: true]. self collapseColumns: (selection collect: [:loc | loc x] as: Set) sorted. selection := nil. flash := false. (target notNil and: [actionSelector notNil]) ifTrue: [target perform: actionSelector withArguments: arguments]] named: 'remove selection' translated ----------------------------- SameGameBoard >> capturedState capturedState "Note the state stored in the second element is an array of associations from submorph index to a shallowCopy of the morph, but only for those morphs that change. Therefore the capturedState record *first* delivers all the morphs, and *then* computes the difference and stores this back. In the end, both undo and redo records follow this format." | prior state oldMorphs priorChanges newChanges | (prior := self valueOfProperty: #priorState) isNil ifTrue: [state := { self shallowCopy. "selection, etc." self submorphs collect: [:m | m shallowCopy]. "state of all tiles" owner scoreDisplay flash. "score display" owner scoreDisplay value}. self setProperty: #priorState toValue: state. ^state]. oldMorphs := prior second. priorChanges := OrderedCollection new. newChanges := OrderedCollection new. 1 to: oldMorphs size do: [:i | (oldMorphs at: i) color = (submorphs at: i) color ifFalse: [priorChanges addLast: i -> (oldMorphs at: i). newChanges addLast: i -> (submorphs at: i) shallowCopy]]. self removeProperty: #priorState. prior at: 2 put: priorChanges asArray. "Store back into undo state.2" ^{ self shallowCopy. "selection, etc." newChanges asArray. "state of tiles that changed" owner scoreDisplay flash. "score display" owner scoreDisplay value} ----------------------------- Mines >> initialize initialize "initialize the state of the receiver" super initialize. level := 1. self listDirection: #topToBottom; wrapCentering: #center; cellPositioning: #topCenter; vResizing: #shrinkWrap; hResizing: #shrinkWrap; layoutInset: 3; addMorph: self makeControls; addMorph: self board. helpText := nil. self newGame ----------------------------- MinesBoard >> tileClickedAt:newSelection:modifier: tileClickedAt: location newSelection: isNewSelection modifier: mod | tile | "self halt." gameOver ifTrue: [^ false]. tile := self tileAt: location. isNewSelection ifFalse: [ mod ifTrue: [ tile mineFlag: ((tile mineFlag) not). tile mineFlag ifTrue: [owner minesDisplay value: (owner minesDisplay value - 1)] ifFalse: [owner minesDisplay value: (owner minesDisplay value + 1)]. ^ true.]. gameStart ifFalse: [ self setMines: location. gameStart := true. owner timeDisplay start.]. ^ self stepOnTile: location. ] ifTrue:[ self clearMines: location.]. ----------------------------- MinesBoard >> stepOnTile: stepOnTile: location | mines tile score | tile := self tileAt: location. tile mineFlag ifFalse:[ tile isMine ifTrue: [tile color: Color gray darker darker. self blowUp. ^false.] ifFalse:[ mines := self findMines: location. tile switchState: true. tileCount := tileCount + 1. mines = 0 ifTrue: [self selectTilesAdjacentTo: location]]. tileCount = ((columns*rows) - self preferredMines) ifTrue:[ gameOver := true. flashCount := 2. owner timeDisplay stop. score := owner timeDisplay value. ( score < (boardSize at:4)) ifTrue:[(BoardSizes at: owner level ) at: 4 put: score. owner hiScoreDisplay value: score]]. ^ true.] ifTrue: [^ false.] ----------------------------- BannerMorph class >> example example "BannerMorph example openInWorld" ^ self header: 'Yes, you are ...' withCRs asTextFromHtml contents: 'Live in Morphic' asUppercase asText ----------------------------- BannerMorph class >> header:contents: header: aStringOrText contents: anotherStringOrText ^ self basicNew header: aStringOrText contents: anotherStringOrText; initialize; yourself ----------------------------- BannerMorph >> initialize initialize super initialize. self extent: 300 @ 200. self changeProportionalLayout; addMorph: (Morph new color: Color transparent; changeTableLayout; listCentering: #center; wrapCentering: #center; addMorph: self createContents; yourself) fullFrame: LayoutFrame fullFrame; addMorph: self createHeader. ----------------------------- BannerMorph >> createHeader createHeader | text | text := (self header copyWithFirst: Character cr) asText addAttribute: TextEmphasis bold; addAttribute: (TextFontReference toFont: (StrikeFont familyName: #Accula size: 29)); yourself. ^ text asMorph centered; fillsOwner: true; yourself ----------------------------- BannerMorph >> createContents createContents | text | text := self contents asText addAttribute: TextEmphasis bold; addAttribute: (TextFontReference toFont: (StrikeFont familyName: #ComicPlain size: 39)); asMorph. text readOnly: true; flag: #ct. "We're no *that* life, yet :(" ^ ScreeningMorph new addMorph: (self createBackground extent: text extent; yourself); addMorph: text; showScreened; cellPositioning: #center; yourself