~hilaire-fernandes/drgeo/trunk

« back to all changes in this revision

Viewing changes to resources/SmalltalkSketches/Archimedes PI Interval.st

  • Committer: Hilaire Fernandes
  • Date: 2022-08-15 15:18:37 UTC
  • Revision ID: hilaire.fernandes@gmail.com-20220815151837-6ta4g0ymzln715j4
Organisation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
| sketch circle ray1 ray2 tangent1 tangent2 points angle radius innerPolygon outerPolygon computePolygons|
 
2
sketch := DrGeoSketch new.
 
3
radius := 5.       
 
4
circle := sketch circleCenter: 0@0 radius: radius.
 
5
circle large color: Color red.
 
6
computePolygons := [ ].
 
7
points := nil.
 
8
computePolygons := [:sides  |
 
9
angle := Float twoPi  / sides.
 
10
points ifNotNil: [ points do: [ :point | sketch domain deleteMathItem: point mathItem ] ].
 
11
points := Array new: sides.
 
12
points at: 1 put: (sketch point: radius@0) hide.
 
13
2 to: sides do: [:i | 
 
14
        points at: i put: (sketch rotate: (points at: i - 1) center: 0@0 angle: angle) hide].
 
15
ray1 := (sketch ray: 0@0 to: (sketch middleOf: points first and: points second) hide) dotted.
 
16
tangent1 := (sketch perpendicular: ray1 at: (sketch altIntersectionOf: circle and: ray1) hide) dotted.
 
17
ray2 := (sketch ray: 0@0 to: (sketch middleOf: points second and: points third) hide) dotted.
 
18
tangent2 := (sketch perpendicular: ray2 at: (sketch altIntersectionOf: circle and: ray2) hide) dotted.
 
19
outerPolygon := sketch 
 
20
        regularPolygonCenter: 0@0 
 
21
        vertex: (sketch intersectionOf: tangent1 and: tangent2) hide 
 
22
        sides: sides.
 
23
innerPolygon := (sketch regularPolygonCenter: 0@0 vertex: radius@0 sides: sides) opaque color: Color white.
 
24
sketch 
 
25
        text: (String streamContents: [:s |
 
26
                s nextPutAll: 'Sides: '; print: sides;  cr;
 
27
                nextPutAll:  ((innerPolygon mathItem length / (2 * radius)) printShowingDecimalPlaces: 4); 
 
28
                nextPutAll: ' < π < ';
 
29
                nextPutAll: ((outerPolygon mathItem length / (2 * radius)) printShowingDecimalPlaces: 4)])
 
30
        at: 0@0].
 
31
 
 
32
sketch do: [ 
 
33
        3 to: 20 do: [ :mySide | 
 
34
                computePolygons value: mySide.
 
35
                sketch update.
 
36
                (Delay forMilliseconds: 500) wait].
 
37
]