|
Class: Spline
Object
|
+--Geometric
|
+--Spline
|
+--ArrowedSpline
- Package:
- stx:libbasic2
- Category:
- Graphics-Geometry-Objects
- Version:
- rev:
1.19
date: 2013/02/08 20:45:16
- user: cg
- file: Spline.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- scaletti@uxc.cso.uiuc.edu (Kurt J. Hebel)
- adapted to ST/X & minor fixes by Claus Gittinger
Spline defines a path that includes an arbitrary collection of points
connected by a third order curve. The curve passes through all controlPoints.
Both open and closed curves are possible.
Polygon
LineSegment
Circle
EllipticalArc
Rectangle
Curve
Arrow
ArrowedSpline
GraphicsContext
StrokingWrapper
FillingWrapper
instance creation
-
controlPoints: aSequentialCollectionOfPoints
-
return a new spline, which passes through aSequentialCollectionOfPoints
accessing
-
controlPoints
-
return the collection of points through which the spline is to pass
-
controlPoints: aCollectionOfPoints
-
set the collection of points through which the spline is to pass
converting
-
asPointArray
-
return an array containing my approximated vertex points.
-
asPolygon
-
return a polygon, approximating the spline
-
asPolyline
-
same as #asPolygon - for ST-80 compatibility
displaying
-
displayFilledOn: aGC
-
Display this Spline as a filled polygon from approximated lines.
-
displayStrokedOn: aGC
-
Display this Spline as a series of approximating lines.
private
-
computeCurve
-
Compute an array for the derivatives at each knot.
-
computeDerivatives: values
-
Computes the first, second and third derivatives at each point
in the collection values.
-
computeLineSegments
-
compute a series of approximating lines.
-
validateDerivatives
-
Make sure that the function and derivative arrays are still valid.
If they are not, recompute them.
queries
-
computeBounds
-
return the smallest enclosing rectangle
-
isCyclic
-
return true, if this spline represents a closed curve
testing
-
canBeFilled
-
return true, if the receiver can be drawn as a filled geometric.
Always true here.
open spline; filled & unfilled:
|v s|
v := (View extent:100@100) openAndWait.
s := Spline controlPoints:
(Array with:(20@20)
with:(80@80)
with:(20@80)).
v paint:Color blue.
s displayFilledOn:v.
v paint:Color red.
s displayStrokedOn:v.
|
closed spline; filled & unfilled:
|v s|
v := (View extent:100@100) openAndWait.
s := Spline controlPoints:
(Array with:(20@20)
with:(80@80)
with:(20@80)
with:(20@20)).
v paint:Color blue.
s displayFilledOn:v.
v paint:Color red.
s displayStrokedOn:v.
|
spiral:
|v points s|
v := View extent:(200 @ 200).
v openAndWait.
points := OrderedCollection new.
90 to:10 by:-10 do:[:r |
0 to:330 by:30 do:[:angle |
|d|
d := (angle / 360) * 10.
points add:(Point r:r-d angle:angle) + (100@100)
].
].
s := Spline controlPoints:points.
v paint:Color red.
s displayStrokedOn:v.
| interactive example:
click-left for first-points; right for last.
|v points eventCatcher|
v := StandardSystemView extent:(450 @ 450).
v label:'Spline Example - (click left/middle)'.
points := OrderedCollection new.
v viewBackground:Color black.
v openAndWait.
eventCatcher := Plug new.
eventCatcher respondTo:#handlesButtonPress:inView:
with:[:butt :view | true].
eventCatcher respondTo:#buttonPress:x:y:view:
with:[:butt :x :y :view |
v paint:(Color white).
v fillCircle:(x @ y) radius:3.
points add:(x @ y).
(butt == 1 or:[butt == #select]) ifFalse:[
v paint:(Color white).
v fillCircle:(x @ y) radius:3.
(Spline controlPoints:points) displayStrokedOn:v.
points := OrderedCollection new.
]
].
v delegate:(eventCatcher)
|
|