Search code examples
geometrysmalltalkpharosqueak

circle inside a square in Smalltalk


I draw a circle inside a square in Smalltalk But I want to reduce it size by 10% so i tried to write it like that:

initialize
 | circleWidth circleHeight|
  super initialize.
  self label: ''.
  self borderWidth: 0.
  bounds := 0@0 corner: 70@70.

  circle := CircleMorph new.
  circleWidth := self bounds width*0.9.
  circleHeight := self bounds height*0.9.
  circle bounds: self bounds*0.9.

  circle color: Color paleBuff.
  circle borderWidth: 1.
  self addMorphCentered: circle.


  offColor := Color gray darker.
  onColor := Color gray darker.
  self useSquareCorners.
  self turnOff

But the line: circle bounds: self bounds*0.9. has some problem when compiling "Message not understood rectangle >>*" how can I do it?


Solution

  • Use the message scaleBy: scale to scale a rectangle.

    So

    circle bounds: self bounds*0.9.
    

    becomes:

    circle bounds: (self bounds scaleBy: 0.9).