ALGOL 68/prelude/graph 2d.a68: Difference between revisions
m
<lang> -> <syntaxhighlight>
(A simple tookit for producing basic 2d graphs available for various RC tasks) |
m (<lang> -> <syntaxhighlight>) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1:
<
#############################################
Line 17:
INT axis 2d = 2, axis 3d = 3, flex axis = 0;
MODE NOARG=BITS; # required when partial parameterisation is not supported #
MODE POINT = [axis 2d]GREAL;
MODE POINTDETAIL = STRUCT(STRINGOPT label, POINTOPTION option);
MODE
MODE
MODE TICK = STRUCT(INT number, GREAL len);
Line 90:
);
# A crude CLASS declaration #
MODE GRAPHDD = STRUCT (
PROC(NOARG)
WINDOW window,
GREAL border,
Line 98 ⟶ 99:
[axis 2d]AXIS axis
# FLEX[0]AXISOPT y2, #
#
);
MODE FUNCTIONINTERVAL = STRUCT(PROC(REAL)REAL function, INTERVAL interval);
MODE CURVE = UNION(
MODE
PROC (NOARG)REF GRAPHDD init,
PROC (LINEOPTION #options#)VOID begin options,
Line 112 ⟶ 113:
PROC (NOARG)VOID decorate,
PROC (NOARG)VOID begin curve,
PROC (
PROC ([]POINT #curve#, LINEOPTION #option#)VOID add curve array point,
PROC (FUNCTIONINTERVAL #function interval#, LINEOPTION #option#)VOID add curve function interval,
Line 119 ⟶ 120:
);
OP
GREAL zoom = 1;
Line 127 ⟶ 128:
# Bind the Attributes to the Instance #
PROC
PROC init of graph 2d = (REF GRAPHDD self, NOARG skip)REF GRAPHDD: (
title OF self := sub title OF self := EMPTY;
Line 216 ⟶ 217:
# label x axis axis #
point := (pan and zoom OF (
draw move (window, label start, point[y axis]-pan);
draw text (window, "c", "c", (label OF axis OF self)[x axis] ORELSE "X Axis");
Line 224 ⟶ 225:
# draw x axis axis #
point := (pan and zoom OF (
draw line point (window, point);
draw move (window, point[x axis], point[y axis]-pan);
Line 230 ⟶ 231:
# label y axis axis #
point := (pan and zoom OF (
draw text angle (window, 90);
draw move (window, point[x axis]-pan, label start);
Line 239 ⟶ 240:
# draw y axis axis #
draw move point(window, point);
point := (pan and zoom OF (
draw line point(window, point);
draw move (window, point[x axis]-pan, point[y axis]);
Line 255 ⟶ 256:
draw device (window, type OF window OF self, sprintf(($g(0)"x axis"g(0)$, pixels OF window OF self)));
(init pan and zoom OF (
(decorate OF (
);
PROC add curve gen point of graph 2d = (REF GRAPHDD self,
REF FILE window = file OF window OF self;
BOOL first := TRUE;
POINT prev specimen;
(begin options OF (
#FOR POINT point IN # gen point #DO#(
## (POINT point)VOID: (
POINT next specimen = (pan and zoom OF (
IF UPB next specimen = 2 AND FALSE THEN # simple case: the single line #
IF first THEN first := FALSE; draw move point ELSE draw line point FI (window, next specimen)
Line 281 ⟶ 282:
FI
# OD#));
(end options OF (
);
PROC add curve array point of graph 2d = (REF GRAPHDD self, []POINT curve, LINEOPTION option)VOID:(
PROC gen curve = (
FOR i TO UPB curve DO yield(curve[i]) OD;
(add curve gen point OF (
);
PROC add curve function interval of graph 2d = (REF GRAPHDD self, FUNCTIONINTERVAL function interval, LINEOPTION option)VOID:(
PROC gen curve = (
INT n steps = 100;
REAL x := lwb OF interval OF function interval;
Line 300 ⟶ 301:
OD
);
(add curve gen point OF (
),
PROC add curve of graph 2d = (REF GRAPHDD self, CURVE curve, LINEOPTION option)VOID:(
CASE curve IN
(
([]POINT array): (add curve array point OF (
(FUNCTIONINTERVAL function interval): (add curve function interval OF (
OUT
raise undefined("add curve type")
Line 321 ⟶ 322:
OP INIT = (REF GRAPHDD object)REF GRAPHDD: init of graph 2d(object,~);
SKIP</syntaxhighlight>
|