-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.tu
More file actions
123 lines (100 loc) · 3.03 KB
/
grid.tu
File metadata and controls
123 lines (100 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
unit
class Grid
export drawGridLines, initialize, getXCoordinate, getYCoordinate, setGridBoxText
var x1 : int
var x2 : int
var y1 : int
var y2 : int
var colorv : int
var xinterval : int
var yinterval : int
procedure initialize (x1_, y1_, x2_, y2_, xinterval_, yinterval_, color_ : int)
x1 := x1_
y1 := y1_
x2 := x2_
y2 := y2_
xinterval := xinterval_
yinterval := yinterval_
colorv := color_
end initialize
function getLastLine (x1 : int, x2 : int, xinterval : int) : int
var x : int := x1
loop
if x + xinterval <= x2 then
x := x + xinterval
else
exit
end if
end loop
result x
end getLastLine
function getXCoordinate (sX : int) : int
var counter := 0
var x : int := x1
loop
if counter >= sX then
result x
end if
if x + xinterval <= x2 then
x := x + xinterval
else
exit
end if
counter := counter + 1
end loop
result x
end getXCoordinate
function getYCoordinate (sY : int) : int
var counter := 0
var y : int := y1
loop
if counter >= sY then
result y
end if
if y + yinterval <= y2 then
y := y + yinterval
else
exit
end if
counter := counter + 1
end loop
result y
end getYCoordinate
/**********************
name: setGridBoxText
parameters:
sX is an integer, sX represents the vertical column (starting from the left)
sX is an integer, sY represents the horizontal row(starting from the bottom)
**********************/
procedure setGridBoxText (sX : int, sY : int, text : string, colr : int)
var font : int := -1
font := Font.New ("courier:15:bold")
var xcoord : int := getXCoordinate (sY)
var ycoord : int := getYCoordinate (sX)
Draw.Text (text, xcoord + (xinterval div 3), ycoord + (yinterval div 3), font, colr)
Font.Free (font)
end setGridBoxText
%Draws a grid a set interval
procedure drawGridLines
var x : int := x1
var y : int := y1
var lastXLine := getLastLine (x1, x2, xinterval)
var lastYLine := getLastLine (y1, y2, yinterval)
%Draws vertical lines
loop
if x > x2 then
exit
end if
drawline (x, y1, x, lastYLine, colorv)
x := x + xinterval
end loop
%Draws horizontal lines
loop
if y > y2 then
exit
end if
drawline (x1, y, lastXLine, y, colorv)
y := y + yinterval
end loop
end drawGridLines
end Grid