Library/Module Code Development

So far I've been working on a PLOTLIB library of subroutines to add more graphic functionality to True BASIC. Is any one else involved in working on their own library/module code?

Comments

Hi

Good info!!

Hello

Thanks for sharing!

Scrolling graph

I needed a scrolling graph much like the one you see in the Microsoft Task Window Performance. You create a new window and set up the grid, then plot continuously and the graph scrolls to the left. Here is the routine. In the future I may add labels for to the grid but these lie outside the window so it's more complicated.

! MGraphLib.tru
!
! Moving graph (continuous stream)

! initialize
SET BACK "blue"
CLEAR
SET BACK "white"
! set up windows
OPEN #1: screen 0,.5,0,.5 ! graph window
OPEN #2: screen .51,1,0,.5 ! comment window

WINDOW #2
PRINT "pixels = ";px,py

WINDOW #1
CLEAR

RANDOMIZE

CALL MGraphSet(1,100,-.01,1.01,20,.2,#1)

FOR i=1 to 300
LET y = .5+.5*sin(i/10)
CALL MGraphDraw(1,y,#1)
WINDOW #2
SET COLOR "blue"
PRINT "i,y: ";i,y

PAUSE 0.005
NEXT i

WINDOW #2
SET COLOR "blue"
PLOT 0,0;1,1

END

EXTERNAL

MODULE MGraph
SHARE MGraphWidth(10) ! number of time steps to show
SHARE MGraphY1(10) ! bottom y scale
SHARE MGraphY2(10) ! top y scale
SHARE MGraphX1(10)
SHARE MGraphX2(10)
SHARE MGraphMajorGridX(10)
SHARE MGraphMajorGridY(10)
SHARE MGraphFirstCall(10)

SHARE x(10,2),y(10,2)

SUB MGraphSet(graph,width,y1,y2,majorgridx,majorgridy,#98)

LET MGraphWidth(graph) = width
LET MGraphY1(graph) = y1
LET MGraphY2(graph) = y2
LET MGraphX1(graph) = -width
LET MGraphX2(graph) = 0
LET MGraphMajorGridX(graph) = majorgridx
LET MGraphMajorGridY(graph) = majorgridy

WINDOW #98
SET WINDOW MGraphX1(graph),MGraphX2(graph),MGraphY1(graph),MGraphY2(graph)
END SUB

SUB MGraphDraw(graph,newy,#98)
DIM values(1)
WINDOW #98
BOX KEEP MGraphX1(graph)+1,MGraphX2(graph),MGraphY1(graph),MGraphY2(graph) in b$
LET MGraphX1(graph) = MGraphX1(graph) + 1
LET MGraphX2(graph) = MGraphX1(graph) + MGraphWidth(graph)
SET WINDOW MGraphX1(graph),MGraphX2(graph),MGraphY1(graph),MGraphY2(graph)
BOX CLEAR MGraphX2(graph)-1,MGraphX2(graph),MGraphY1(graph),MGraphY2(graph)
BOX SHOW b$ at MGraphX1(graph),MGraphY1(graph)

SET COLOR "green"
LET values(1) = 1
CALL Object(2,0,"WIDTH","",values)
IF REMAINDER(MGraphX2(graph),MGraphMajorGridX(graph)) = 0 then
PLOT MGraphX2(graph),MGraphY1(graph);MGraphX2(graph),MGraphY2(graph)
END IF

FOR i = MGraphY1(graph) to MGraphY2(graph) step MGraphMajorGridY(graph)
PLOT MGraphX2(graph)-1,i;MGraphX2(graph),i
NEXT i

SET COLOR "black"
LET values(1) = 2
CALL Object(2,0,"WIDTH","",values)
IF MGraphFirstCall(graph) = 0 then
LET y(graph,1) = newy
LET y(graph,2) = newy
LET MGraphFirstCall(graph) = 1
ELSE
LET x(graph,1) = x(graph,2)
LET x(graph,2) = x(graph,2)+1
LET y(graph,1) = y(graph,2)
LET y(graph,2) = newy
PLOT MGraphX2(graph)-1,y(graph,1);MGraphX2(graph),y(graph,2)
END IF
LET values(1) = 1
CALL Object(2,0,"WIDTH","",values)
END SUB

END MODULE