The project contains classes for drawing three types of curves:
The project illustrates how a program code can be divided into a small pieces of code stored in separate files. Open
and run the code from the app.l file. The code is quite short: it creates an object of a selected type of curve
and sliders based on parameters described in that curve class. Curve classes themselves are coded in separate files and
attached to the main app with use of the include
instruction.
Code splitted into many files, each containing description of one class, is more readable and easy to handle. Try to add your own curve class on basis of one of the provided classes. The following rules should be preserved:
curve
class:
use curve :c
:param,"name := {p0 pmin pmax step}
"name
- parameter name (word)p0
- initial value, from the range < pmin
; pmax
>pmin
- lower limit of parameter valuespmax
- upper limit of parameter valuesstep
- step in the value when it is changed with a slider (value is continuous if step is omitted)
fn
function defined; it is responsible for the curve drawing.
Each file with a curve definition has to include the file with the base class definition. To avoid unneccessary, multiple includes, use:
if not defined? "curve [include "curve.l]
The base class contains the fn
prototype and all the code neccessary for the curve repainting after the
graphics window size or scale changes. It also handles changes of the curve parameters.
As an excersise you may add to the project the following class of the asteroid curve:
to asteroid :c
use curve :c
to fn
pu setxy :s 0 pd
for [t 0 360] [
if :stop [stop]
let "x :s * (cos :t)^:k
let "y :s * (sin :t)^:k
setxy :x :y
]
end
:param,"K := {3 1 13 2}
:param,"S := {150 10 300 1}
end