Object subclass: #Polygon
instanceVariableNames: 'apex name originX originY left top right bottom'
classVariableNames: ''
poolDictionaries: ''
category: 'ProgrammingLanguages'!
!Polygon methodsFor: 'initialize-release'!
initialize: numberApex name: newName oX: x oY: y
name:=newName.
apex:=Array new: numberApex.
originX:= x.
originY:= y.
apex at: 1 put: originX@originY ! !
!Polygon methodsFor: 'accessing'!
name
^name!
name: new_name
name:=new_name!
left
^left!
right
^right!
top
^top!
bottom
^bottom! !
Polygon subclass: #Hexagon
instanceVariableNames: 'sideLength'
classVariableNames: ''
poolDictionaries: ''
category: 'ProgrammingLanguages'!
!Hexagon methodsFor: 'initialize-release'!
initialize: side oX: x oY: y
super initialize: 6 name: 'Hexagon' oX: x oY: y.
sideLength:= side.
apex at: 2 put: (x + ((side squared * (3 sqrt))/2))@(y + (0.5 * side)).
apex at: 3 put: (x + ((side squared * (3 sqrt))/2))@(y + (1.5 * side)).
apex at: 4 put: x@(y + (2* side)).
apex at: 5 put: (x - ((side squared * (3 sqrt))/2))@(y + (1.5 * side)).
apex at: 6 put: (x - ((side squared * (3 sqrt))/2))@(y + (0.5 * side)).
left:= (x - ((side squared * (3 sqrt))/2)).
top:= y.
bottom:= (y + (2* side)).
right:= (x + ((side squared * (3 sqrt))/2)).
! !
!Hexagon methodsFor: 'arithmetic'!
+ figure
| p newSide |
p:=self area + figure area.
newSide:= (2 * p /((3 * 3 sqrt) sqrt)).
^(Hexagon new) initialize: newSide oX: originX oY: originY!
!
!Hexagon methodsFor: 'actions'!
getPoints
Transcript cr.
Transcript show: ('Dlugosc boku ').
Transcript show: sideLength printString; cr.
Transcript show: ('Pierwszy wierzcholek ').
Transcript show: (apex at: 1) printString; cr.
Transcript show: ('Drugi wierzcholek ').
Transcript show: (apex at: 2) printString; cr.
Transcript show: ('Trzeci wierzcholek ').
Transcript show: (apex at: 3) printString; cr.
Transcript show: ('Czwarty wierzcholek ').
Transcript show: (apex at: 4) printString; cr.
Transcript show: ('Piaty wierzcholek ').
Transcript show: (apex at: 5) printString; cr.
Transcript show: ('Szosty wierzcholek ').
Transcript show: (apex at: 6) printString; cr.
Transcript show: ('Pole pieciokata ').
Transcript show: (self area) printString; cr. !
area
^((3 * sideLength squared * 3 sqrt)/2)!
move: aa i: bb
self initialize: sideLength oX: (originX + aa) oY: (originY + bb)!
!
setOfHexagons := Set new.
r1:= (Hexagon new) initialize: 6 oX: 5 oY: 5.
setOfHexagons add: r1.
r2:= (Hexagon new) initialize: 5 oX: 5 oY: 5.
setOfHexagons add: r2.
r3:= (Hexagon new) initialize: 4 oX: 5 oY: 5.
setOfHexagons add: r3.
r4:= (Hexagon new) initialize: 2 oX: 5 oY: 5.
setOfHexagons add: r4.
r5:= (Hexagon new) initialize: 1 oX: 5 oY: 5.
setOfHexagons add: r5.
r6:= (Hexagon new) initialize: 1 oX: 5 oY: 5.
r6 move: 1 i: 1.
setOfHexagons add: r6.
r7:= (Hexagon new).
r7:= r1 + r2.
setOfHexagons do: [:x|
x getPoints
].