To avoid the unpleasant overlapping of the two rectangles, all the drawing operations are to be conducted in an unique stroke. The polyline summit is then extended to follow the outline of the cross.
drawOn: aCanvas
aCanvas strokeWidth: 8 color: Color lightOrange fillColor: Color red do: [ aCanvas polyLine: { 100@0 . 140@0 . 140@100 . 240@100 . 240@140 .140@140 . 140@240 . 100@240 . 100@140 . 0@140 . 0@100 . 100@100 . 100@0 } ]
To enjoy the update, the #redrawNeeded is to be sent to self.
step
width := width + 0.2. width > 30 ifTrue: [width := 0]. self redrawNeeded
The principle is to handle manually the indexes and to use the timesRepeat: method on integer. It reflects to how it will be coded with lower level languages.
drawOn: canvas
| font grad posX extent step | ../.. step := self ppcm / 2. " half centimeter step " canvas strokeWidth: 0.8 color: Color black do: [ posX := 0. length + 1 timesRepeat: [ canvas moveTo: posX @ 0.5; lineToY: 10. canvas moveTo: (posX + step) @ 0.5 ; lineToY: 6. posX := posX + self ppcm] ]. grad := posX := 0. length + 1 timesRepeat: [ canvas drawString: grad asString atCenterX: posX @12 font: font color: Color black. grad := grad + 1. posX := posX + self ppcm]
We add the following code at the end of the method and make the stick thinner to 0.3 pixel.
drawOn: canvas
step := self ppcm / 10. "millimeter step " canvas strokeWidth: 0.3 color: Color black do: [ posX := step. length * 2 + 1 timesRepeat: [ 4 timesRepeat: [ canvas moveTo: posX 0.2; lineToY: 4. posX := posX + step]. posX := posX + step] ]