-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.cla
155 lines (91 loc) · 2.63 KB
/
grid.cla
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
unit
class Grid
export drawGrid, eraseGrid, fromPoints, setRC, getRow, getCol, getHeight, getWidth, setHW, setColor, setStartxy, setBG, inside, centerCell
var startx, starty : int := 1
var row, col : int := 4
var xsize, ysize : int := 50
starty := 1
var colorv : int := 1
var bgcolor : int := 31
function getRow : int
result row
end getRow
function getCol: int
result col
end getCol
function getHeight : int
result ysize
end getHeight
function getWidth : int
result xsize
end getWidth
procedure setRC (r, c : int)
row := r
col := c
end setRC
procedure setBG (c : int)
bgcolor := c
end setBG
procedure setHW (h, w : int)
xsize := w
ysize := h
end setHW
procedure setColor (color : int)
colorv := color
end setColor
procedure setStartxy (x, y : int)
startx := x
starty := y
end setStartxy
procedure drawGrid
var x, y : int
x := startx
y := starty
var counter : int := 0
var counter2 : int := 0
Draw.FillBox (startx, starty, startx + (xsize * col), starty + (ysize * col), bgcolor)
loop
exit when counter2 = row
counter := 0
loop
exit when counter = col
Draw.Box (x, y, x + xsize, y + ysize, colorv)
x := x + xsize
counter := counter + 1
end loop
y := y + ysize
x := startx
counter2 := counter2 + 1
end loop
end drawGrid
procedure eraseGrid
colorv := colorbg
drawGrid
end eraseGrid
function inside (x, y : int) : boolean
var inside : boolean := true
var xrangetop: int := startx + (xsize * col)
var xrangebot: int := startx
var yrangebot : int := starty
var yrangetop : int := starty + (ysize * row)
if x < xrangebot or x > xrangetop then
inside := false
end if
if y < yrangebot or y > yrangetop then
inside := false
end if
result inside
end inside
procedure fromPoints (x, y : int, var row1, col1 : int)
var yrange : int := y - starty
var xrange : int := x - startx
row1 := yrange div ysize + 1
col1 := xrange div xsize + +1
end fromPoints
procedure centerCell (r, c : int, var x, y : int)
var xdistance : int := xsize * (c) - (xsize div 2)
var ydistance : int := ysize * (r) - (xsize div 2)
x := startx + xdistance
y := starty + ydistance
end centerCell
end Grid