ALGOL 68/prelude/graph 2d.a68: Difference between revisions
Content added Content deleted
(A simple tookit for producing basic 2d graphs available for various RC tasks) |
m (rename some objects) |
||
Line 17: | Line 17: | ||
INT axis 2d = 2, axis 3d = 3, flex axis = 0; |
INT axis 2d = 2, axis 3d = 3, flex axis = 0; |
||
MODE NOARG=BITS; |
MODE NOARG=BITS; # required when partial parameterisation is not supported # |
||
MODE POINT = [axis 2d]GREAL; |
MODE POINT = [axis 2d]GREAL; |
||
Line 90: | Line 90: | ||
); |
); |
||
# A crude CLASS declaration # |
|||
MODE GRAPHDD = STRUCT ( |
MODE GRAPHDD = STRUCT ( |
||
PROC(NOARG) |
PROC(NOARG)GRAPHDDMETHODOF method, |
||
WINDOW window, |
WINDOW window, |
||
GREAL border, |
GREAL border, |
||
Line 104: | Line 105: | ||
MODE CURVE = UNION(GENPOINT, []POINT, FUNCTIONINTERVAL); |
MODE CURVE = UNION(GENPOINT, []POINT, FUNCTIONINTERVAL); |
||
MODE |
MODE GRAPHDDMETHODOF = STRUCT( |
||
PROC (NOARG)REF GRAPHDD init, |
PROC (NOARG)REF GRAPHDD init, |
||
PROC (LINEOPTION #options#)VOID begin options, |
PROC (LINEOPTION #options#)VOID begin options, |
||
Line 119: | Line 120: | ||
); |
); |
||
OP |
OP METHODOF = (GRAPHDD graph)GRAPHDDMETHODOF: (method OF graph)(~); |
||
GREAL zoom = 1; |
GREAL zoom = 1; |
||
Line 127: | Line 128: | ||
# Bind the Attributes to the Instance # |
# Bind the Attributes to the Instance # |
||
PROC |
PROC method of graph 2d = (REF GRAPHDD self, NOARG skip)GRAPHDDMETHODOF:( |
||
init of graph 2d(self,#~#), |
|||
begin options of graph 2d(self,), |
|||
end options of graph 2d(self,#~#), |
|||
init pan and zoom of graph 2d(self,#~#), |
|||
pan and zoom of graph 2d(self,), |
|||
decorate of graph 2d(self,#~#), |
|||
begin curve of graph 2d(self,#~#), |
|||
add curve gen point of graph 2d(self,,), |
|||
add curve array point of graph 2d(self,,), |
|||
add curve function interval of graph 2d(self,,), |
|||
add curve of graph 2d(self,,), |
|||
end curve of graph 2d(self,#~#) |
|||
); |
|||
PROC init of graph 2d = (REF GRAPHDD self, NOARG skip)REF GRAPHDD: ( |
PROC init of graph 2d = (REF GRAPHDD self, NOARG skip)REF GRAPHDD: ( |
||
method OF self := method of graph 2d(self,#~#); # Hmmm... # |
|||
title OF self := sub title OF self := EMPTY; |
title OF self := sub title OF self := EMPTY; |
||
Line 216: | Line 217: | ||
# label x axis axis # |
# label x axis axis # |
||
point := (pan and zoom OF ( |
point := (pan and zoom OF (METHODOF self))((x axis LWB self, x axis offset)); |
||
draw move (window, label start, point[y axis]-pan); |
draw move (window, label start, point[y axis]-pan); |
||
draw text (window, "c", "c", (label OF axis OF self)[x axis] ORELSE "X Axis"); |
draw text (window, "c", "c", (label OF axis OF self)[x axis] ORELSE "X Axis"); |
||
Line 224: | Line 225: | ||
# draw x axis axis # |
# draw x axis axis # |
||
point := (pan and zoom OF ( |
point := (pan and zoom OF (METHODOF self))((x axis UPB self, x axis offset)); |
||
draw line point (window, point); |
draw line point (window, point); |
||
draw move (window, point[x axis], point[y axis]-pan); |
draw move (window, point[x axis], point[y axis]-pan); |
||
Line 230: | Line 231: | ||
# label y axis axis # |
# label y axis axis # |
||
point := (pan and zoom OF ( |
point := (pan and zoom OF (METHODOF self))((y axis offset, y axis LWB self)); |
||
draw text angle (window, 90); |
draw text angle (window, 90); |
||
draw move (window, point[x axis]-pan, label start); |
draw move (window, point[x axis]-pan, label start); |
||
Line 239: | Line 240: | ||
# draw y axis axis # |
# draw y axis axis # |
||
draw move point(window, point); |
draw move point(window, point); |
||
point := (pan and zoom OF ( |
point := (pan and zoom OF (METHODOF self))((y axis offset, y axis UPB self)); |
||
draw line point(window, point); |
draw line point(window, point); |
||
draw move (window, point[x axis]-pan, point[y axis]); |
draw move (window, point[x axis]-pan, point[y axis]); |
||
Line 255: | Line 256: | ||
draw device (window, type OF window OF self, sprintf(($g(0)"x axis"g(0)$, pixels OF window OF self))); |
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 ( |
(init pan and zoom OF (METHODOF self))(~); |
||
(decorate OF ( |
(decorate OF (METHODOF self))(~) |
||
); |
); |
||
Line 263: | Line 264: | ||
BOOL first := TRUE; |
BOOL first := TRUE; |
||
POINT prev specimen; |
POINT prev specimen; |
||
(begin options OF ( |
(begin options OF (METHODOF self))(option); |
||
#FOR POINT point IN # gen point #DO#( |
#FOR POINT point IN # gen point #DO#( |
||
## (POINT point)VOID: ( |
## (POINT point)VOID: ( |
||
POINT next specimen = (pan and zoom OF ( |
POINT next specimen = (pan and zoom OF (METHODOF self))(point); |
||
IF UPB next specimen = 2 AND FALSE THEN # simple case: the single line # |
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) |
IF first THEN first := FALSE; draw move point ELSE draw line point FI (window, next specimen) |
||
Line 281: | Line 282: | ||
FI |
FI |
||
# OD#)); |
# OD#)); |
||
(end options OF ( |
(end options OF (METHODOF self))(~) |
||
); |
); |
||
Line 287: | Line 288: | ||
PROC gen curve = (YIELDPOINT yield)VOID: |
PROC gen curve = (YIELDPOINT yield)VOID: |
||
FOR i TO UPB curve DO yield(curve[i]) OD; |
FOR i TO UPB curve DO yield(curve[i]) OD; |
||
(add curve gen point OF ( |
(add curve gen point OF (METHODOF self))(gen curve, option) |
||
); |
); |
||
Line 300: | Line 301: | ||
OD |
OD |
||
); |
); |
||
(add curve gen point OF ( |
(add curve gen point OF (METHODOF self))(gen curve, option) |
||
), |
), |
||
PROC add curve of graph 2d = (REF GRAPHDD self, CURVE curve, LINEOPTION option)VOID:( |
PROC add curve of graph 2d = (REF GRAPHDD self, CURVE curve, LINEOPTION option)VOID:( |
||
CASE curve IN |
CASE curve IN |
||
(GENPOINT gen): (add curve gen point OF ( |
(GENPOINT gen): (add curve gen point OF (METHODOF self))(gen, option), |
||
([]POINT array): (add curve array point OF ( |
([]POINT array): (add curve array point OF (METHODOF self))(array, option), |
||
(FUNCTIONINTERVAL function interval): (add curve function interval OF ( |
(FUNCTIONINTERVAL function interval): (add curve function interval OF (METHODOF self))(function interval, option) |
||
OUT |
OUT |
||
raise undefined("add curve type") |
raise undefined("add curve type") |
||
Line 321: | Line 322: | ||
OP INIT = (REF GRAPHDD object)REF GRAPHDD: init of graph 2d(object,~); |
OP INIT = (REF GRAPHDD object)REF GRAPHDD: init of graph 2d(object,~); |
||
SKIP |
SKIP</lang> |