! Demo about line steps. ! Author: Francois Tonneau size 17 12 set font ss hei 0.6 ! GLE lets us define subroutines that work like procedures or functions. Here we ! will use a subroutine to create a panel with a triangle, a title, and a line ! drawn in a given style. Our 'panel' procedure will have three parameters: two ! numeric ('left' and 'bottom') and one string ('style$'). In GLE, the name of ! a string parameter or variable must end with a dollar sign. sub panel left bottom style$ amove left bottom begin origin set color #d5d5d5 set lwidth 0.03 box 4 4 ! A 'begin path ... end path' block allows us to draw and/or fill an ! arbitrary closed region. Here the region will be a triangle filled ! with the #d5d5d5 color. We only need to define two sides of the ! triangle, as GLE automatically connects the beginning and end of a ! path when doing the filling. If we had wanted a filled triangle with ! a visible contour, however, we should have added 'stroke' after 'fill' ! ('begin path fill #d5d5d5 stroke'), and we should have closed the path ! explicity with the 'closepath' command. amove 0 0 begin path fill #d5d5d5 rline 4 4 rline 0 -4 end path ! Using GLE's string concatenation operator ('+'), we compose the title ! of our panel from "line " and the style$ parameter: amove 0 4.5 set color #2c2c2c write "line "+style$ ! We use a graph block with hidden axes ('axis off') to draw a line ! inside the panel. 'fullsize' means that the plot will take up its ! full assigned area; ticks and labels, if any, will lie outside. amove 0 0 begin graph size 4 4 fullsize xaxis min 0.5 max 4.5 yaxis min 0.5 max 4.5 axis off ! To plot the line, we define a custom dataset with the 'let dn = ! x-expression from ... to ... step ...' syntax: let d1 = x from 1 to 4 step 1 ! We use the 'if ... then ... else if ... end if' syntax to plot ! our custom dataset. The drawing command differs, depending on ! the value of style$: d1 color #004e58 lwidth 0.05 marker square msize 0.35 if style$ = "" then d1 line else if style$ = "steps" then d1 line steps else if style$ = "hist" then d1 line hist else if style$ = "impulses" then d1 line impulses else if style$ = "fsteps" then d1 line fsteps else if style$ = "bar" then d1 line bar end if end graph end origin end sub ! Now is the time to use our 'panel' subroutine: panel 0.5 6.5 "" panel 6.5 6.5 "steps" panel 12.5 6.5 "hist" panel 0.5 0.5 "impulses" panel 6.5 0.5 "fsteps" panel 12.5 0.5 "bar" ! Done. We have learned about line/step styles in GLE, 'begin path ... end ! path' blocks, subroutines, and if-then-else control flow.