As I wanted it to be as flexible as possible I used a lot of variables, and now I've confused myself. Can someone review this code and see if it's doing what supposed to do. It seems to work as it supposed to; draw a grid filling the display no matter its size. But you never know, and surely there's a better more efficient way. Also, is there a way to retrieve the display width/heigh from the the @DISPLAY pre-processor set at the start?
Code: Select all
@VERSION 10,0
@DISPLAY{WIDTH = 640, HEIGHT = 480, MODE = "WINDOWED", TITLE = "GRID", COLOR = #BLACK} ;Create the window
SetFont(#MONOSPACE, 20) ; Inbuilt fonts are: SANS, SERIF, MONOSPACE
SetFontStyle(#BOLD|#ANTIALIAS) ; Styles: BOLD, ITALIC, NORMAL, UNDERLINED
SetFontColor(#WHITE)
/* === SET VARIABLES === */
GS = 32 ; GRID-SIZE
GC = $5f8b56 ; GRID-COLOR
LT = 1 ; LINE-THICKNESS
GW = 640 / GS ; GRID-WIDTH
GH = 480 / GS ; GRID-HEIGHT
Function p_DrawGrid_H()
for x = 1 to GH
block
for l = 1 to x
Line (0, GS*l, GW*GS, GS*l, GC, {Thickness = LT})
next
endblock
Next
EndFunction
Function p_DrawGrid_V()
for x = 1 to GW
block
for l = 1 to x
Line (GS*l, 0, GS*l, GW*GS, GC, {Thickness = LT})
next
endblock
Next
EndFunction
BeginDoubleBuffer()
EscapeQuit(True)
/* MAIN LOOP */
Repeat
Cls(#BLACK)
p_DrawGrid_H()
p_DrawGrid_V()
Flip()
Forever
EndDoubleBuffer()
End