fork download
  1. Object subclass: #Polygon
  2. instanceVariableNames: 'apex name originX originY left top right bottom'
  3. classVariableNames: ''
  4. poolDictionaries: ''
  5. category: 'ProgrammingLanguages'!
  6.  
  7. !Polygon methodsFor: 'initialize-release'!
  8.  
  9. initialize: numberApex name: newName oX: x oY: y
  10.  
  11. name:=newName.
  12. apex:=Array new: numberApex.
  13. originX:= x.
  14. originY:= y.
  15. apex at: 1 put: originX@originY ! !
  16.  
  17. !Polygon methodsFor: 'accessing'!
  18.  
  19. name
  20. ^name!
  21.  
  22. name: new_name
  23. name:=new_name!
  24.  
  25. left
  26. ^left!
  27.  
  28. right
  29. ^right!
  30.  
  31. top
  32. ^top!
  33.  
  34. bottom
  35. ^bottom! !
  36.  
  37.  
  38. Polygon subclass: #Hexagon
  39. instanceVariableNames: 'sideLength'
  40. classVariableNames: ''
  41. poolDictionaries: ''
  42. category: 'ProgrammingLanguages'!
  43.  
  44. !Hexagon methodsFor: 'initialize-release'!
  45.  
  46. initialize: side oX: x oY: y
  47.  
  48. super initialize: 6 name: 'Hexagon' oX: x oY: y.
  49. sideLength:= side.
  50. apex at: 2 put: (x + ((side squared * (3 sqrt))/2))@(y + (0.5 * side)).
  51. apex at: 3 put: (x + ((side squared * (3 sqrt))/2))@(y + (1.5 * side)).
  52. apex at: 4 put: x@(y + (2* side)).
  53. apex at: 5 put: (x - ((side squared * (3 sqrt))/2))@(y + (1.5 * side)).
  54. apex at: 6 put: (x - ((side squared * (3 sqrt))/2))@(y + (0.5 * side)).
  55. left:= (x - ((side squared * (3 sqrt))/2)).
  56. top:= y.
  57. bottom:= (y + (2* side)).
  58. right:= (x + ((side squared * (3 sqrt))/2)).
  59. ! !
  60.  
  61. !Hexagon methodsFor: 'arithmetic'!
  62.  
  63. + figure
  64.  
  65.  
  66. | p newSide |
  67. p:=self area + figure area.
  68. newSide:= (2 * p /((3 * 3 sqrt) sqrt)).
  69.  
  70. ^(Hexagon new) initialize: newSide oX: originX oY: originY!
  71. !
  72.  
  73. !Hexagon methodsFor: 'actions'!
  74.  
  75. getPoints
  76.  
  77. Transcript cr.
  78. Transcript show: ('Dlugosc boku ').
  79. Transcript show: sideLength printString; cr.
  80. Transcript show: ('Pierwszy wierzcholek ').
  81. Transcript show: (apex at: 1) printString; cr.
  82. Transcript show: ('Drugi wierzcholek ').
  83. Transcript show: (apex at: 2) printString; cr.
  84. Transcript show: ('Trzeci wierzcholek ').
  85. Transcript show: (apex at: 3) printString; cr.
  86. Transcript show: ('Czwarty wierzcholek ').
  87. Transcript show: (apex at: 4) printString; cr.
  88. Transcript show: ('Piaty wierzcholek ').
  89. Transcript show: (apex at: 5) printString; cr.
  90. Transcript show: ('Szosty wierzcholek ').
  91. Transcript show: (apex at: 6) printString; cr.
  92. Transcript show: ('Pole pieciokata ').
  93. Transcript show: (self area) printString; cr. !
  94.  
  95. area
  96.  
  97. ^((3 * sideLength squared * 3 sqrt)/2)!
  98.  
  99. move: aa i: bb
  100. self initialize: sideLength oX: (originX + aa) oY: (originY + bb)!
  101. !
  102.  
  103. setOfHexagons := Set new.
  104.  
  105. r1:= (Hexagon new) initialize: 6 oX: 5 oY: 5.
  106. setOfHexagons add: r1.
  107. r2:= (Hexagon new) initialize: 5 oX: 5 oY: 5.
  108. setOfHexagons add: r2.
  109. r3:= (Hexagon new) initialize: 4 oX: 5 oY: 5.
  110. setOfHexagons add: r3.
  111. r4:= (Hexagon new) initialize: 2 oX: 5 oY: 5.
  112. setOfHexagons add: r4.
  113. r5:= (Hexagon new) initialize: 1 oX: 5 oY: 5.
  114. setOfHexagons add: r5.
  115. r6:= (Hexagon new) initialize: 1 oX: 5 oY: 5.
  116. r6 move: 1 i: 1.
  117. setOfHexagons add: r6.
  118. r7:= (Hexagon new).
  119. r7:= r1 + r2.
  120.  
  121.  
  122. setOfHexagons do: [:x|
  123. x getPoints
  124. ].
Success #stdin #stdout 0.02s 12000KB
stdin
Standard input is empty
stdout
Dlugosc boku 5
Pierwszy wierzcholek 5@5
Drugi wierzcholek Object: 1 error: The program attempted to divide a number by zero
ZeroDivide(Exception)>>signal (ExcHandling.st:254)
SmallInteger(Number)>>zeroDivide (SysExcept.st:1426)
Fraction>>setNumerator:setDenominator: (Fraction.st:485)
Fraction class>>numerator:denominator: (Fraction.st:66)
Fraction>>- (Fraction.st:151)
FloatD(Float)>>printOn:special: (Float.st:533)
FloatD(Float)>>printOn: (Float.st:436)
WriteStream(Stream)>>print: (Stream.st:501)
Point>>printOn: (Point.st:63)
Point(Object)>>printString (Object.st:534)
Hexagon>>getPoints (prog:83)
optimized [] in UndefinedObject>>executeStatements (prog:123)
Set(HashedCollection)>>do: (HashedColl.st:201)
UndefinedObject>>executeStatements (prog:122)