Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
500 calculi
Last updated at 5:51 am UTC on 9 May 2018
Also see: 100 calculi; works fine in Squeak 6 and Pharo 6 (and earlier versions).
 dotSize := 15.
 p500 := AlignmentMorph newRow color: Color white; hResizing: #shrinkWrap; vResizing: #shrinkWrap.
 
 "literal array of color objects"
 {Color red . Color green . Color blue . Color yellow . Color gray} 
 
 do: [:color |  "create block of 100"
 	       p100 := AlignmentMorph newColumn color: Color white; hResizing: #shrinkWrap; vResizing: #shrinkWrap.
                10 timesRepeat: [ |row| 
                                  row := AlignmentMorph newRow color: Color white; 
                                         hResizing: #shrinkWrap; vResizing: #shrinkWrap.
 
                                  10 timesRepeat: [row addMorph: (CircleMorph new extent: dotSize@dotSize; color: color)].
                                  p100 addMorph: row].
 
                p500 addMorphBack: p100
 ].
 
 p500 openInHand
500-calculi.png

Using a block

The code above rewritten to use
 createNewRowBlock := [AlignmentMorph newRow color: Color white; hResizing: #shrinkWrap; vResizing: #shrinkWrap].
Then a new row is created by sending the #value message
 createNewRowBlock value

This will simplify code if there is a lot of code in the block.

dotSize := 17.
 createNewRowBlock := [AlignmentMorph newRow color: Color white; hResizing: #shrinkWrap; vResizing: #shrinkWrap].
 createNewColumnBlock := [AlignmentMorph newColumn color: Color white; hResizing: #shrinkWrap; vResizing: #shrinkWrap].

 p500 := createNewRowBlock value.
 

 "literal array of color objects"
 {Color red . Color green . Color blue . Color yellow . Color gray} 
 
   do: [:color |  "create block of 100"
 	        p100 := createNewColumnBlock value.
                10 timesRepeat: [ |row| 
                                  row := createNewRowBlock value.
                                  10 timesRepeat: [row addMorph: (CircleMorph new extent: dotSize@dotSize; color: color; borderColor: Color white)].
                                  p100 addMorph: row
                                ].
                p500 addMorphBack: p100
        ].
 
 p500 openInHand

500-calculi_no_borders.png
Tag: Montessori