Skip to content

Commit

Permalink
kind of refactored CADisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
kpawlak committed Jul 12, 2024
1 parent 32a86c6 commit 488083f
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions src/ComputationalArt/CADisplay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@ CADisplay class >> border [
^ 1.
]

{
#category : #constants,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:04'
}
CADisplay class >> borderWidth [
"I return the borderWidth of a viewMorph"

^ 5.
]

{
#category : #constants,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:01'
}
CADisplay class >> bounds [
"I return the bounds of a viewMorph"

^ 100 @ 100 corner: 1450 @ 1160.
]

{
#category : #constants,
#'squeak_changestamp' : 'KoPa 7/12/2024 19:02'
}
CADisplay class >> color [
"I return the color of a viewMorph"

^ Color r: 176/255 g: 196/255 b: 222/255.
]

{
#category : #constants,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:26'
Expand Down Expand Up @@ -68,27 +98,27 @@ CADisplay >> attachedGrid: aGrid [

{
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 18:22'
#'squeak_changestamp' : 'KoPa 7/12/2024 19:03'
}
CADisplay >> initialize [

cells := OrderedCollection new.
viewMorph := Morph new
bounds: (100 @ 100 corner: 1450 @ 1160);
color: (Color r: 176/255 g: 196/255 b: 222/255);
bounds: CADisplay bounds;
color: CADisplay color;
borderColor: Color gray;
borderWidth: 5;
borderWidth: CADisplay borderWidth;
openInWorldOrWorldlet;
yourself.
]

{
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:31'
#'squeak_changestamp' : 'KoPa 7/12/2024 18:58'
}
CADisplay >> showGrid: aGrid [

| grid cols rows origin size border gap blockLookup |
| grid cols rows origin size border gap blockLookup cellMorph cell |
blockLookup := CABlocks new.
grid := aGrid grid.
cols := aGrid numCols.
Expand All @@ -102,7 +132,6 @@ CADisplay >> showGrid: aGrid [

1 to: rows do: [ :rowIndex |
1 to: cols do: [ :colIndex |
| cellMorph cell |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cellMorph := Morph new
extent: size @ size;
Expand All @@ -116,28 +145,26 @@ CADisplay >> showGrid: aGrid [

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 18:33'
#'squeak_changestamp' : 'KoPa 7/12/2024 18:58'
}
CADisplay >> step [

| grid cols rows origin size border gap blockLookup aGrid |
| grid cols rows origin size border gap blockLookup aGrid cell cellMorph |
aGrid := attachedGrid.
blockLookup := CABlocks new.
grid := aGrid grid.
cols := aGrid numCols.
rows := aGrid numRows.
origin := viewMorph position + (320@30).
origin := viewMorph position + CADisplay offset.
size := CADisplay size.
border := CADisplay border.
gap := CADisplay gap.

cells isEmpty
ifTrue: [Transcript show: 'grid was empty';
cr.
ifTrue: [
(1 to: rows)
do: [:rowIndex | (1 to: cols)
do: [:colIndex |
| cellMorph cell |
do: [ :rowIndex | (1 to: cols)
do: [ :colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cellMorph := CACellMorph new extent: size @ size;
borderColor: Color gray;
Expand All @@ -149,18 +176,16 @@ CADisplay >> step [
col: colIndex;
game: attachedGame.
viewMorph addMorph: cellMorph.
cells add: cellMorph]]].
cells add: cellMorph. ]]].
cells isEmpty
ifFalse: [Transcript show: 'grid was not empty';
cr.
ifFalse: [
(1 to: rows)
do: [:rowIndex | (1 to: cols)
do: [:colIndex |
| cellMorph cell |
do: [ :rowIndex | (1 to: cols)
do: [ :colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cellMorph := cells at: rowIndex - 1 * rows + colIndex.
cellMorph
color: (blockLookup colorAt: cell)]]]
color: (blockLookup colorAt: cell). ]]].
]

{
Expand Down

0 comments on commit 488083f

Please sign in to comment.