Skip to content

Commit

Permalink
it's the final brain cell
Browse files Browse the repository at this point in the history
  • Loading branch information
kpawlak authored and kpawlak committed Jul 12, 2024
1 parent b521725 commit 7799597
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 165 deletions.
10 changes: 5 additions & 5 deletions src/ComputationalArt/CADisplay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ CADisplay >> initialize [

{
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 20:30'
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CADisplay >> showGrid: aGrid [

Expand All @@ -132,7 +132,7 @@ CADisplay >> showGrid: aGrid [

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

{
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 20:31'
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CADisplay >> step [

Expand All @@ -166,7 +166,7 @@ CADisplay >> step [
do: [:rowIndex |
(1 to: cols)
do: [:colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cell := aGrid cellAtRow: rowIndex andCol: colIndex.
cellMorph := CACellMorph new extent: size @ size;
borderColor: Color gray;
color: (blockLookup colorAt: cell);
Expand All @@ -182,7 +182,7 @@ CADisplay >> step [
do: [:rowIndex |
(1 to: cols)
do: [:colIndex |
cell := aGrid getCellAtRow: rowIndex andCol: colIndex.
cell := aGrid cellAtRow: rowIndex andCol: colIndex.
cellMorph := cells at: rowIndex - 1 * rows + colIndex.
cellMorph
color: (blockLookup colorAt: cell).]]].
Expand Down
158 changes: 77 additions & 81 deletions src/ComputationalArt/CAGrid.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,141 +65,137 @@ CAGrid class >> fillTNT: aGrid [
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 5/31/2024 13:38'
#category : #constants,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:51'
}
CAGrid class >> size [
"I return the num of rows and cols"

^ 100.
]

{
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CAGrid >> cellAtRow: aRow andCol: aCol [

^ grid at: aRow at: aCol.
]

{
#category : #copy,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CAGrid >> deepcopy [
|clone|

| clone |
clone := CAGrid new.

1 to: numRows do: [:rowIndex |
1 to: numCols do: [: colIndex|
"grid at: rowIndex at: colIndex put: 10 * rowIndex + colIndex."
clone putCell: (grid at: rowIndex at: colIndex) atRow: rowIndex andCol: colIndex.
].
].
^ clone
1 to: numCols do: [:colIndex |
clone putCell: (grid at: rowIndex at: colIndex) atRow: rowIndex andCol: colIndex.]].
^ clone.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 5/29/2024 23:51'
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CAGrid >> getCellAtRow: row andCol: col [
CAGrid >> grid [

^grid at: row at: col
^ grid.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 5/30/2024 13:43'
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 23:51'
}
CAGrid >> getNeighborsOfCellAtRow: row andCol: col [
"get the 3x3 of cells surrounding a certain input"
|neighborMatrix temp gridRow gridCol|
CAGrid >> initialize [

numCols := CAGrid size.
numRows := CAGrid size.

grid := Matrix rows: numRows columns: numCols.

1 to: numRows do: [:rowIndex |
1 to: numCols do: [:colIndex |
grid at: rowIndex at: colIndex put: 0.]].
]

{
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CAGrid >> neighborsOfCellAtRow: aRow andCol: aCol [

| neighborMatrix temp gridRow gridCol |
neighborMatrix := Matrix rows: 3 columns: 3.

1 to: 3 do: [:i |
1 to: 3 do: [:j |
neighborMatrix at: i at: j put: 0.
].
].
1 to: 3 do: [:row |
1 to: 3 do: [:col |
neighborMatrix at: row at: col put: 0.]].

(col=1) ifTrue: [
aCol=1 ifTrue: [
neighborMatrix
at: 1 at: 1 put: -1;
at: 2 at: 1 put: -1;
at: 3 at: 1 put: -1.
].
at: 3 at: 1 put: -1.].

(row=1) ifTrue: [
aRow=1 ifTrue: [
neighborMatrix
at: 1 at: 1 put: -1;
at: 1 at: 2 put: -1;
at: 1 at: 3 put: -1.
].
at: 1 at: 3 put: -1.].

(row=numRows) ifTrue: [
aRow=numRows ifTrue: [
neighborMatrix
at: 3 at: 1 put: -1;
at: 3 at: 2 put: -1;
at: 3 at: 3 put: -1.
].
at: 3 at: 3 put: -1.].

(col=numCols) ifTrue: [
aCol=numCols ifTrue: [
neighborMatrix
at: 1 at: 3 put: -1;
at: 2 at: 3 put: -1;
at: 3 at: 3 put: -1.
].
at: 3 at: 3 put: -1.].

1 to: 3 do: [:rowOffset |
1 to: 3 do: [:colOffset |
temp := neighborMatrix at: rowOffset at: colOffset.
(temp == 0) ifTrue: [
gridRow := row+rowOffset-2.
gridCol := col+colOffset-2.
(temp = 0) ifTrue: [
gridRow := aRow+rowOffset-2.
gridCol := aCol+colOffset-2.
temp := grid at: gridRow at: gridCol.
neighborMatrix at: rowOffset at: colOffset put: temp.
].
].
].
neighborMatrix at: rowOffset at: colOffset put: temp.]]].

^neighborMatrix
^ neighborMatrix.

]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:45'
}
CAGrid >> grid [

^grid
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/7/2024 15:51'
}
CAGrid >> initialize [

numCols := 100.
numRows := 100.

grid := Matrix rows: numRows columns: numCols.

1 to: numRows do: [:rowIndex |
1 to: numCols do: [:colIndex |
grid at: rowIndex at: colIndex put: 0.

].
].
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:44'
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:51'
}
CAGrid >> numCols [

^numCols
^ numCols.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:45'
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:51'
}
CAGrid >> numRows [

^numRows
^ numRows.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 5/30/2024 12:04'
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:52'
}
CAGrid >> putCell: cell atRow: row andCol: col [
CAGrid >> putCell: aCell atRow: aRow andCol: aCol [

grid at: row at: col put: cell.
grid at: aRow at: aCol put: aCell.
]
15 changes: 9 additions & 6 deletions src/ComputationalArt/CAOverlay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@ CAOverlay class >> uiPosition [
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/19/2024 15:16'
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:54'
}
CAOverlay >> game [

^ game.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/19/2024 15:13'
#category : #accessing,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:54'
}
CAOverlay >> game: aCAGame [

game := aCAGame.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/23/2024 17:19'
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 23:54'
}
CAOverlay >> initialize [

| lastHeight menus |
super initialize.
menus := OrderedCollection new.
Expand Down
13 changes: 7 additions & 6 deletions src/ComputationalArt/CAOverlayBlockMenu.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ Class {
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/23/2024 17:30'
#category : #'initialize-release',
#'squeak_changestamp' : 'KoPa 7/12/2024 23:55'
}
CAOverlayBlockMenu >> initialize [
| blockList |


| blockList s|
super initialize.

self addMorph: [|s| s := (CAOverlayListItem new) initialize. s contents: 'BlockMenu'. s] value.
self addMorph:
[s := (CAOverlayListItem new) initialize.
s contents: 'BlockMenu'. s] value.

blockList := CAOverlayList new fromListOfStrings:
#('Water' 'Sand' 'Stone' 'Air' 'TNT' 'Wood' 'Algae' 'Fire' 'Fish' 'Smoke').
Expand Down
14 changes: 8 additions & 6 deletions src/ComputationalArt/CAOverlayItem.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Class {
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/23/2024 15:00'
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:54'
}
CAOverlayItem >> fitChildren [
|originX originY cornerX cornerY|

| originX originY cornerX cornerY |
originX := 10000. originY := 10000. cornerX := 0. cornerY:= 0.
self submorphsDo: [:s | s bounds corner x < originX
ifTrue: [originX := s bounds origin x]].
Expand All @@ -24,7 +25,7 @@ CAOverlayItem >> fitChildren [
]

{
#category : #'as yet unclassified',
#category : #'initialize-release',
#'squeak_changestamp' : 'JAL 6/23/2024 14:13'
}
CAOverlayItem >> initialize [
Expand All @@ -34,10 +35,11 @@ CAOverlayItem >> initialize [
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/23/2024 15:17'
#category : #functional,
#'squeak_changestamp' : 'KoPa 7/12/2024 23:54'
}
CAOverlayItem >> padding: aRectangle [

self extent: (self extent + aRectangle origin + aRectangle corner).
self submorphsDo: [:s | s position: (s position + aRectangle origin)]
]
10 changes: 5 additions & 5 deletions src/ComputationalArt/CARuler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 7/10/2024 14:41'
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CARuler >> applyRules: aRuleSet to: aGrid [
| aGridCopy cellNeighbors newCellNeighbors newCellVal |
Expand All @@ -18,8 +18,8 @@ CARuler >> applyRules: aRuleSet to: aGrid [
aGridCopy := aGrid deepcopy.
1 to: aGrid numRows do: [:rowIndex |
1 to: aGrid numCols do: [:colIndex |
cellNeighbors := aGridCopy getNeighborsOfCellAtRow: rowIndex andCol: colIndex.
newCellNeighbors := aGrid getNeighborsOfCellAtRow: rowIndex andCol: colIndex.
cellNeighbors := aGridCopy neighborsOfCellAtRow: rowIndex andCol: colIndex.
newCellNeighbors := aGrid neighborsOfCellAtRow: rowIndex andCol: colIndex.
newCellVal := rule applyRuleWith: cellNeighbors and: newCellNeighbors.
aGrid putCell: newCellVal atRow: rowIndex andCol: colIndex
]
Expand All @@ -29,7 +29,7 @@ CARuler >> applyRules: aRuleSet to: aGrid [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:45'
#'squeak_changestamp' : 'KoPa 7/12/2024 23:49'
}
CARuler >> printGrid: aGrid [

Expand All @@ -40,7 +40,7 @@ CARuler >> printGrid: aGrid [

1 to: numRows do: [:i |
1 to: numCols do: [:j |
Transcript show: (aGrid getCellAtRow: i andCol: j) printString; space.
Transcript show: (aGrid cellAtRow: i andCol: j) printString; space.
].
Transcript cr.
].
Expand Down
Loading

0 comments on commit 7799597

Please sign in to comment.