per page, with , order by , clip by
Results of 0 - 1 of about 0 (0.000 sec.)
Smalltalk sketch (GNU Dr. Geo user guide)
@digest: 977b82e6f97bdd228eed625d81928b28
@id: 27062
@mdate: 2019-02-18T20:00:01Z
@size: 48783
@type: text/html
content-type: text/html; charset=utf-8
description: Smalltalk sketch (GNU Dr. Geo user guide)
distribution: global
generator: makeinfo
keywords: Smalltalk sketch (GNU Dr. Geo user guide)
resource-type: document
#keywords: drgeosketch (462605), drgwrappedcurve (128315), drgwrappedpoint (74805), middleof (66871), drgwrappedvalue (66332), canvas (62238), freevalue (41263), ourrandom (36904), drgwrappeditem (33832), pointoncurve (30804), circlecenter (27727), sketches (20665), mathitem (19040), sketch (17241), abscissa (14895), coordinates (14075), polygon (12335), segment (11571), point (7750), parents (7266), perpendicular (7117), centre (6611), workspace (6523), angle (6470), circle (6359), smalltalk (6252), figure (6068), geometric (5745), fullscreen (5631), triangle (4747), method (4484), arc (4007)
Next: Didactic applications , Previous: Smalltalk script , Up: Top [ Contents ][ Index ] 5 Dr.Geo Smalltalk sketch Dr.Geo Smalltalk sketches – (DSS) – are sketches entirely defined in the Smalltalk language. This is not about constructing a sketch with the Dr.Geo graphical interface, but about describing a sketch with the Smalltalk language. We provide a nice programming interface with an easy and light syntax. 5.1 Smalltalk sketches by example Smalltalk itself is a high level language, carefully crafted iteratively for about 10 years at Xerox Parc Research Labs. When a sketch is defined with it, we can use all the power of the language to build a sketch, or to position some objects randomly to get a slightly different sketch at each execution of its Smalltalk code. Therefore, a Smalltalk sketch is freed from the constraints of the graphic user interface while reinforced by the Smalltalk language. A Smalltalk sketch is source code to execute in a workspace , which is a text editor where source code can be written and executed. To open one, use the shortcut Ctrl-k when no window is selected – or click on the background and in the menu select Tools→Workspace. It is possible to paste text in with the shortcut Ctrl-v . (See workspace to learn more about this tool). Smalltalk sketches are not saved within Dr.Geo. They must be pasted to an external text editor and saved to external files in order to be available for reuse in Dr.Geo. Then the text must be copied from the external file and pasted into a Dr.Geo workspace in order to be executed again. To introduce the concepts of Smalltalk sketches, we will study a few examples. Each one will be written in a workspace and its source code will be selected with mouse, then executed with the shortcut Ctrl-d to Do-it! 14 . Let's start with the simplest possible Smalltalk sketch: DrGeoSketch new When executing it, it simply creates a new empty sketch. The Dr.Geo canvas displayed is simplified as there is no toolbar, only the menu bar. A second example that begins to do something: | c item | c := DrGeoSketch new. item := c point: 1.2 @ -2. item name: 'A'. Here we define a sketch containing a free point A of coordinates (1,2 ; -2). An object is added to the construction by sending a message to the canvas, here #point: to create a free point given its coordinates. The result is a point object. We can also modify the point by sending a message to it. Here we rename it 'A'. Let's continue with a third, more interesting example: | c triangle ourRandom m n p | triangle := [:p1 :p2 :p3 | c segment: p1 to: p2. c segment: p2 to: p3. c segment: p3 to: p1]. ourRandom := [6 - 11 atRandom]. c := DrGeoSketch new. m := c point: ourRandom value @ 0. n := c point: 5 @ 0. p := c point: ourRandom value @ 3. triangle value: m value: n value: p. This example shows us three interesting things: The introduction of more elaborate constructions, not initially implemented in Dr.Geo. Here we define a block of code triangle between the square brackets: given three points, construct a triangle. We can compare this to the macro construction method but with a different, programming oriented approach. The definition of a block of code – ourRandom – to give us integer random number between -5 and 5. It is used for a random positioning of the points. Therefore each time the sketch is executed, it is slightly different. Assigning the result of a construction – the object we got when sending a construction message to the canvas – is not mandatory. We do it when we need to keep a reference to the constructed object for later use. Here in the block of code triangle , we don't keep references to the constructed segments. However, concerning the defined points, we keep references in the local variables m , n and p , for later use as arguments when executing the block of code triangle . To finish with this introduction by example, here is the last one: | c a b d | c := DrGeoSketch new. a := c point: 1@0. b := c point: 5@0. d := c line: a to: b. a color: Color yellow; round; large. b hide. d dashed. Two points and a line are constructed. Then messages are sent to them to modify their styles, including hiding one. We have finished our small guided tour of Dr.Geo Smalltalk sketches . In the following sections, we expose the commands available. 5.2 Reference methods for the Dr.Geo Smalltalk sketch To add an object to a construction, you send a message to the canvas. The resulting constructed object can be modified as well by sending messages to it. So before adding any object to a canvas, we need to create the canvas with the command DrGeoSketch new . 5.2.1 Various messages Method on DrGeoSketch: <DrGeoSketch> new ⇒ Return a canvas and open it. The result is normally assigned to a variable for later use to add constructions. | canvas | canvas := DrGeoSketch new. Method on DrGeoSketch: fullscreen The sketch is set to fill the Dr.Geo window. | canvas | canvas := DrGeoSketch new. canvas fullscreen Method on DrGeoSketch: do: block block , Smalltalk block of code with instructions for construction and/or animation of the sketch. Execute the block of code in a specific background process. Use it when a construction needs to be done step by step in front of the user or when the sketch is animated. | canvas point | canvas := DrGeoSketch new. canvas fullscreen. point := canvas point: 0@0. canvas do: [ -5 to: 5 by: 0.1 do: [:x | point moveTo: x @ (x cos * 3). (Delay forMilliseconds: 100) wait. canvas update] ] Method on DrGeoSketch: update Update the canvas after some objects were modified. Used mainly for animation, or for modifications that do not cause an update themselves. Method on DrGeoSketch: gridOn Display the grid in the canvas. Method on DrGeoSketch: centerTo: aPoint aPoint , coordinates of a point The canvas is displaced so the point given by the argument is at the centre of the canvas window. canvas centerTo: 5@0 Method on DrGeoSketch: scale: anInteger anInteger , scale of the canvas Modify the scale of the canvas. canvas scale: 10 Point. Method on DrGeoSketch: <DrGeoWrappedPoint> point: aPoint aPoint , coordinates (x,y) ⇒ free point in the plane with coordinates aPoint. canvas point: 5@2. Method on DrGeoSketch: <DrGWrappedPoint> pointX:Y: v1 v2 v1 , value object v2 , value object ⇒ point determined by its coordinates in the form of values placed in the sketch canvas pointX: (canvas freeValue: 2) hide Y: (canvas freeValue: 5) hide. Method on DrGeoSketch: <DrGWrappedPoint> pointOnCurve:at: curve abscissa curve , line (straight line, ray, segment, etc.) abscissa , curvilinear abscissa of the free point, abscissa in interval [0 ; 1] ⇒ free point on a line myPoint := canvas pointOnCurve: s1 at: 0.5. Method on DrGeoSketch: <DrGWrappedPoint> middleOf:and: p1 p2 p1 , point item or coordinates p2 , point item or coordinates ⇒ middle of two points | canvas a i | canvas := DrGeoSketch new. a := canvas point: 1@1. i := canvas middleOf: a and: 4@4. Method on DrGeoSketch: <DrGWrappedPoint> middleOf: s s , segment ⇒ middle of a segment canvas middleOf: s. Method on DrGeoSketch: <DrGWrappedPoint> intersectionOf:and: l1 l2 l1 , line l2 , line ⇒ point of intersection of two lines canvas intersectionOf: line1 and: line2 Method on DrGeoSketch: <DrGWrappedPoint> altIntersectionOf:and: l1 l2 l1 , line l2 , line ⇒ second point of intersection of two lines, when it exists canvas altIntersectionOf: line and: circle. Method on DrGeoSketch: <DrGWrappedPoint> point:parents block item block , block of code returning coordinates item , math item ⇒ pointBlockItem whose coordinates are calculated with the block of code with “item” as argument | figure s mobile c block | figure := DrGeoSketch new. figure fullscreen. s:=figure segment: (figure point: -5@0) to: (figure point: 5@0). mobile := figure pointOnCurve: s at: 0.1. block := [:mathItem | |x| x := mathItem point x. x (x * x * x / 25 - x)]. c := figure point: block parent: mobile. figure locusOf: c when: mobile. Method on DrGeoSketch: <DrGWrappedPoint> point:parents block collection block , block of code returning coordinates collection , math item collection ⇒ point whose coordinates are calculated with the block of code with “collection” as argument | figure a b d m p | figure:=DrGeoSketch new. a:=figure point: (-2)@1. b:=figure point: 3@3. d:=figure line: a to: b. d color: Color blue. m:=figure point: 1@(-1). p:= figure point: [:parents | parents first closestPointTo: parents second point] parents: {d . m}. This example uses array notation { . } to provide the collection needed. Line. Method on DrGeoSketch: <DrGWrappedCurve> line:to: p1 p2 p1 , point or coordinates p2 , point or coordinates ⇒ line passing through these two points | canvas p1 | canvas := DrGeoSketch new. p1 := canvas point: 0@0. canvas line: p1 to: 1@2. Note that if one or both arguments are given as literals, those points are not drawn, and are not available in the sketch to click and drag. The direction of the line thus cannot be changed interactively. Method on DrGeoSketch: <DrGWrappedCurve> parallel:at: d p d , direction (line, segment, vector,...) p , point or coordinates ⇒ line parallel to direction d and passing through point p | canvas a d | canvas := DrGeoSketch new. a := canvas point: 1@5. d := canvas line: (-2)@1 to: 3@3. canvas parallel: d at: a. Method on DrGeoSketch: <DrGWrappedCurve> perpendicular:at: d p p , point or coordinates d , direction (line, segment, vector, ...) ⇒ line perpendicular to direction d and passing through point p canvas perpendicular: d at: 1@5. Method on DrGeoSketch: <DrGWrappedCurve> perpendicularBisector: s s , segment ⇒ perpendicular bisector to s canvas perpendicularBisector: (canvas segment: 0@0 to: 4@4) Method on DrGeoSketch: <DrGWrappedCurve> perpendicularBisector:to: a b a , point or coordinates b , point or coordinates ⇒ perpendicular bisector to segment joining a and b canvas perpendicularBisector: 0@0 to: 4@4 Method on DrGeoSketch: <DrGWrappedCurve> angleBisector: a a , geometric angle defined by three points ⇒ angle bisector of the angle a canvas angleBisector: angle Method on DrGeoSketch: <DrGWrappedCurve> angleBisectorSummit:side1:side2: a b c a,b,c , points defining a geometric angle BAC ⇒ angle bisector of the angle BAC canvas angleBisectorSummit: 0@0 side1: 1@0 side2: 0@1 Ray. Method on DrGeoSketch: <DrGWrappedCurve> ray:to: o p o , point or coordinate, the origin p , point or coordinates, point anywhere on the ray ⇒ ray defined by its origin and a second point | canvas a | canvas := DrGeoSketch new. a := canvas point: 1@5. canvas ray: 0@0 to: a. Segment. Method on DrGeoSketch: <DrGWrappedSegment> segment:to: p1 p2 p1 , points or coordinates p2 , points or coordinates ⇒ segment defined by two points | canvas a | canvas := DrGeoSketch new. a := canvas point: 5@5. canvas segment: 10@10 to: a. Circle. Method on DrGeoSketch: <DrGWrappedFilledCircle> circleCenter:to: c p c , point or coordinates, centre of the circle p , point or coordinates, point on the circle ⇒ circle defined by its centre and a point | canvas a | canvas := DrGeoSketch new. a := canvas point: 1@5. canvas circleCenter: a to: 10@4. Method on DrGeoSketch: <DrGWrappedFilledCircle> circleCenter:radius: c r c , point or coordinates, centre of the circle r , numeric item or numeric value, radius ⇒ circle defined by its centre and radius | canvas a r | canvas := DrGeoSketch new. a := canvas point: 1@5. r := canvas freeValue: 4. canvas circleCenter: a radius: r. canvas circleCenter: 4@4 radius: 5 Arc. Method on DrGeoSketch: <DrGWrappedFinitCurve> arc:to:to: p1 p2 p3 p1 , point or coordinates, 1st extremity of the arc p2 , point or coordinates representing a point on arc p3 , point or coordinates, 2nd extremity of the arc ⇒ arc defined by its extremities and a point | canvas a b | canvas := DrGeoSketch new. a := canvas point: 1@5. b := canvas point: 0@5. canvas arc: a to: b to: -1 @ -2. Method on DrGeoSketch: <DrGWrappedFinitCurve> arcCenter:from:to: o a b o , point or coordinates, centre of the arc a , point or coordinates, origin of the arc b , point or coordinates, so the angle is AOB ⇒ arc defined by its centre and angle AOB | canvas a b | canvas := DrGeoSketch new. a := canvas point: 1@5. b := canvas point: 0@5. canvas arcCenter: a from: b to: -1 @ -2. Polygon. Method on DrGeoSketch: <DrGWrappedFinitCurve> polygon: collection collection , collection of points or coordinates; vertices of the polygon ⇒ polygon defined by its vertices | canvas b | canvas := DrGeoSketch new. b := canvas point: 1@3. canvas polygon: {1@2. b. 0@0. d} Method on DrGeoSketch: <DrGWrappedFinitCurve> regularPolygonCenter:vertex:sides: c s n c , point or coordinates, centre of the polygon s , point or coordinate, a vertex of the polygon n , value item or numeric value, number of vertices of the polygon ⇒ regular polygon defined by its centre, one vertex and number of vertices | canvas b | canvas := DrGeoSketch new. b := canvas point: 1@3. canvas regularPolygonCenter: b vertex: 1@1 sides: 7. Geometric transformations. Geometric transformations are to transform any kind of geometric objects: point, segment, line, ray, vector, circle, arc and polygon. Method on DrGeoSketch: <DrGWrappedCurve> rotate:center:angle: i c a i , object to transform (point, segment, line, ray, vector, circle, arc, polygon) c , point or coordinates, rotation centre a , value item or numeric value, rotation angle ⇒ transformed object | canvas c k l | canvas := DrGeoSketch new. c := canvas point: 5@5. k := 3.14159. l := canvas line: 0@0 to: 5@5. canvas rotate: l center: c angle: k. canvas rotate: l center: 0@0 angle: Float pi / 3. Method on DrGeoSketch: <DrGWrappedCurve> scale:center:factor: i c k i , object to transform (point, segment, line, ray, vector, circle, arc, polygon) c , point or coordinates, homothety centre k , value item or numeric value, homothety factor ⇒ transformed object | canvas c k l | canvas := DrGeoSketch new. c := canvas point: 0@5. k := -3. l := canvas line: 0@0 to: 5@5. canvas scale: l center: c factor: k. canvas scale: l center: 0@4 factor: 5. Method on DrGeoSketch: <DrGWrappedCurve> symmetry:center: i c i , point, segment, line, ray, vector, circle, arc, polygon c , point or coordinates, symmetry centre ⇒ transformed object | canvas a | canvas := DrGeoSketch new. a := canvas point: 4@2. canvas symmetry: a center: 0@0. Method on DrGeoSketch: <DrGWrappedCurve> reflect:axe: i a item , point, segment, line, ray, vector, circle, arc, polygon axe , line, symmetry axis ⇒ transformed object | canvas a d polygon | canvas := DrGeoSketch new. a := canvas polygon: {0@0 . 2@0 . 3@2 . 0@4} d := canvas line: (-1)@(-1) to: 4@(-1). canvas reflect: a axis: d Method on DrGeoSketch: <DrGWrappedCurve> translate:vector: i v item , point, segment, line, ray, vector, circle, arc, polygon vector , vector or coordinates ⇒ transformed object | canvas u a| canvas := DrGeoSketch new. u := canvas vector: (canvas point: 1@1) to: (canvas point: 3@2). a := canvas translate: (canvas point: 2@1) vector: u. | canvas u a| canvas := DrGeoSketch new. a := canvas translate: (canvas point: 2@1) vector: 2@1. Locus of a point. Method on DrGeoSketch: <DrGWrappedCurve> locusOf:when: m c m , mobile point on a line c , fixed point depending on the mobile point m ⇒ locus canvas locusOf: c when: mobile. Vector. Method on DrGeoSketch: <DrGWrappedCurve>vector:to: o e o , point or coordinates, vector origin e , point or coordinates, vector extremity ⇒ vector | canvas b | canvas := DrGeoSketch new. b := canvas point: 0@5. canvas vector: b to: -1 @ -2. Method on DrGeoSketch: <DrGWrappedCurve> vector: p p , point or coordinates, the vector coordinates ⇒ vector from 0@0 to point | canvas p | canvas := DrGeoSketch new. p := canvas point: 5@5. canvas vector: p. canvas vector: -5 @ -5 Number. When applying a method to a canvas that creates a numeric value, the value is placed as a Dr.Geo math item somewhat at random in the sketch, and is initially hidden. It can be revealed with the show command described below. Method on DrGWrappedPoint: <Point> coordinates pointItem , point ⇒ coordinates (static) of self | canvas c p segment | canvas := DrGeoSketch new. segment := canvas segment: 0@0 to: 3@5 p := canvas pointOnCurve: segment at: 0.5. c := p coordinates. canvas freeValue: c x Method on DrGeoSketch: <DrGWrappedValue> abscissaOf: item item , point or vector item ⇒ abscissa (dynamic) item of item | canvas m x | canvas := DrGeoSketch new. m := canvas middleOf: 10@5 and: 7@8. x := canvas abscissaOf: m. The abscissa of a point is its x coordinate. The abscissa of a vector is the difference between the x coordinates of its initial and final points. Method on DrGeoSketch: <DrGWrappedValue> ordinateOf: item item , point or vector item ⇒ ordinate (dynamic) item of item | canvas m x | canvas := DrGeoSketch new. m := canvas middleOf: 10@5 and: 7@8. x := canvas ordinateOf: m The ordinate of a point is its y coordinate. The ordinate of a vector is the difference between the y coordinates of its initial and final points. Method on DrGeoSketch: <DrGWrappedValue> freeValue: v v , initial value ⇒ free value item, initially hidden, randomly placed v:= canvas freeValue: (-1 arcCos). v show Method on DrGWrappedValue: value: aNumber item , a free value item aNumber , a number Eedit the value of a free number item v := canvas freeValue: 3. v show. v value: Float pi Method on DrGeoSketch: <DrGWrappedValue> lengthOf: item item , segment, circle, arc or vector ⇒ number item, the item length canvas lengthOf: v1. Method on DrGeoSketch: <DrGWrappedValue> distance:to: item point item , line or point point , point ⇒ number, distance between two points or a point and a line canvas distance: l1 to: a. Method on DrGeoSketch: <DrGWrappedValue> slopeOf: line line , line ⇒ number, slope of the line | canvas p | canvas := DrGeoSketch new. p := canvas slopeOf: d. Dr.Geo does not handle infinite slope for vertical lines well. If a slope is placed in a sketch, and then the line is made vertical, the slope disappears from the sketch, and its value does not update in the data pane. Angle. Method on DrGeoSketch: <DrGWrappedValue> angle:to:to: a b c a , point b , point, angle summit c , point ⇒ geometric angle ABC in the interval [0 ; pi] | canvas a b c angle | canvas := DrGeoSketch new. a :=canvas point: 0@0. b :=canvas point: 0@4. c :=canvas point: 3@0. angle := canvas angle: b to: a to: c. angle show. Method on DrGeoSketch: <DrGWrappedValue> angle:to: v1 v2 v1 , vector v2 , vector ⇒ oriented angle given two vectors in the interval ]-pi ; pi] | canvas v1 v2 a b c angle | canvas := DrGeoSketch new. a :=canvas point: 0@0. b :=canvas point: 0@4. c :=canvas point: 3@0. v1 := canvas vector: a to: b. v2 := canvas vector: a to: c. angle := canvas angle: v2 to: v1. angle show. Equation. Method on DrGeoSketch: <DrGWrappedValue> equationOf: item item , line or circle ⇒ equation of the line or circle | canvas e d | canvas := DrGeoSketch new. d := canvas line: 0@0 to: 15@13. e := canvas equationOf: d. e show. Text. Method on DrGeoSketch: <DrGWrappedText> text: string string , a string ⇒ a text arbitrary positioned canvas text: 'Hello' Method on DrGeoSketch: <DrGWrappedText> text:at: string point string , a string point , coordinates ⇒ a text positioned at aPoint canvas text: 'Hello, I am happy!' at: 0@0 Method on item: text: aString item , an item representing a text aString , a string Edit the text of a text object myText := canvas text: 'Hello'. myText text: 'Bye' 5.2.2 Modification of object attributes To modify object attributes, we send messages to the objects. So the attributes are always modified after creating the objects. Method on DrGWrappedItem: color: aColor aColor , a Color , see methods in this class for existing colors : Color black, Color red, Color blue, Color orange, Color yellow,... Modify the item color pointA color: Color green. Method on DrGWrappedText: backgroundColor: aColor aColor , a Color Modify the background color of the text item myText backgroundColor: Color green. Method on DrGWrappedItem: name: aString aString , a string, text Rename item segment name: '[AB]'. Method on DrGWrappedItem: hide Hide an item point hide Method on DrGWrappedItem: show Show an item value show Method on DrGWrappedCurve: small Set thickness of line to small circle small. Method on DrGWrappedCurve: normal Set thickness of line to normal arc normal. Method on DrGWrappedCurve: large Set thickness of line to large polygon large. Method on DrGWrappedCurve: plain Plain, undotted, style line polygon plain. Method on DrGWrappedCurve: dashed Dash style line polygon dashed. Method on DrGWrappedCurve: dotted Dotted style line arc dotted. Method on DrGWrappedPoint: cross Cross shape for point a cross. Method on DrGWrappedPoint: round Round shape for point a round. Method on DrGWrappedPoint: square Square shape for point a square. Method on DrGWrappedPoint: small Small sized point a small. Method on DrGWrappedPoint: medium Medium sized point a medium. Method on DrGWrappedPoint: large Large sized point a large. Method on DrGWrappedItem: moveTo: point point , coordinates Move the item to the given position, if its constraints permit | canvas a | canvas := DrGeoSketch new. a := canvas point: 0@0. a moveTo: 5@5. canvas update 5.2.3 Complementary methods The DrGeoSketch class proposes in the category helpers complementary methods to ease the computation of complex, interactive sketches. Method on DrGeoSketch: plot:from:to: block x0 x1 block , block of code, with one argument, to describe a function on an interval x0 , number, lower boundary of the function's domain x1 , number, upper boundary of the function's domain Display the curve representing the function described by the block of code, in the interval [x0 ; x1], and display a free point on the x axis together with a relative point on the curve, representing the value of the function at that point. canvas plot: [:x| x * x] from: -3 to: 3. Method on DrGeoSketch: <BlockClosure> float:at:from:to:name: f1 p f2 f4 s f1 , initial value p , left position of the ruler f2 , minimum value f3 , maximum value s , name of the value ⇒ block of code returning the current value of the ruler Construct a ruler at the given position with a decimal value in the interval [float2 ; float3] | canvas A F | canvas := DrGeoSketch new. A := canvas float: 1 at: -10@4 from: 0 to: 10 name: 'A'. F := canvas integer: 3 at: -10@3 from: 0 to: 10 name: 'F' showValue: true. A value + F value. There are other variants, some for integer values. 5.3 Gallery of examples To illustrate the use of Dr.Geo Smalltalk sketches, we present below a small set of examples. It shows you some possibilities that we hope will inspire you for your own needs. For each example for which we give the Smalltalk source code, we encourage you to copy and paste it into a Dr.Geo workspace and run the code. 5.3.1 Animate a figure These examples rely on time handling and background processes. We begin with a simple animation in order to understand the concept: | figure p pause | figure:=DrGeoSketch new. p := figure point: 0@0. pause := Delay forSeconds: 0.2. figure do: [ 100 timesRepeat: [ p mathItem moveTo: (p mathItem point + (0.1@0)). figure update. pause wait]]. The Delay class supports setting time intervals for pausing Dr.Geo. The do: and timeRepeat: control structures repeat a code block that moves its argument item across the sketch. The update is necessary so that the point is displayed in its new position after each move. A second example with a more elaborate sketch: | figure s r u pause | figure := DrGeoSketch new fullscreen. s := figure segment: 0@ -1 to: 4@ -1. r := figure pointOnCurve: s at: 0.8. s := figure segment: 0@0 to: 0@1. u := figure pointOnCurve: s at: 0.7. u round small; color: Color blue. 1 to: 100 do: [:n| u := figure point: [:parents| |y t| y := parents first point y. t := parents second point x. (n / 5) @ t * y * (1 - y)] parents: {u . r}. u round small; color: Color blue]. pause := Delay forSeconds: 0.1. figure do: [ 0 to: 1 by: 0.05 do: [:x | r mathItem setCurveAbscissa: x. figure update. pause wait]]. 5.3.2 Sierpinski triangle This example largely relies on a recursive block of code for drawing triangles and subdividing them to a specified number of levels. | triangle c | triangle := [:s1 :s2 :s3 :n | c segment: s1 to: s2; segment: s2 to: s3; segment: s3 to: s1. n > 0 ifTrue: [triangle value: s1 value: (c middleOf: s1 and: s2) hide value: (c middleOf: s1 and: s3) hide value: n-1. triangle value: (c middleOf: s1 and: s2) hide value: s2 value: (c middleOf: s2 and: s3) hide value: n-1. triangle value: (c middleOf: s1 and: s3) hide value: (c middleOf: s2 and: s3) hide value: s3 value: n-1.]]. c := DrGeoSketch new. triangle value: (c point: 0 @ 3) value: (c point: 4 @ -3) value: (c point: -4 @ -3) value: 3. Figure 5.1: Triangle de Sierpinski Footnotes (14) Alternatively, this is the entry to select in the contextual menu of the workspace. Next: Didactic applications , Previous: Smalltalk script , Up: Top [ Contents ][ Index ] ...
http://www.gnu.org/savannah-checkouts/gnu/dr-geo/doc/en/Smalltalk-sketch.html - [detail] - [similar]
PREV NEXT
Powered by Hyper Estraier 1.4.13, with 213332 documents and 1081104 words.