-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mesh Surface packer,bb
192 lines (181 loc) · 3.51 KB
/
Mesh Surface packer,bb
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
; Big Surfaces Maker
Graphics 800,600,32,2
SetBuffer BackBuffer()
SeedRnd 1
AppTitle "Press escape to end."
Global mapw = 50
Global maph = 50
Dim map(mapw,maph)
Type r
Field x,y,w,h
End Type
Dim cmap(mapw,maph)
initmap()
ms = MilliSecs()
initsurfaces()
ms = MilliSecs() - ms
timer = CreateTimer(60)
While KeyDown(1) = False
WaitTimer timer
Cls
drawmap()
drawrects()
;
If cnt > 60*3
initmap()
ms = MilliSecs()
initsurfaces()
ms = MilliSecs() - ms
cnt=0
End If
cnt=cnt+1
Text GraphicsWidth()-196,10,"Took:"+ms+" ms"
Flip
Wend
End
Function initsurfaces()
Delete Each r
For y=0 To maph
For x=0 To mapw
cmap(x,y) = 0
Next
Next
;
; Pass 1 - Fit increasingly smaller blocks into the space and add to list
;
cnt=0
exitloop = False
rad = mapw
x1 = 0
y1 = 0
While exitloop = False
fits = True
x2 = -rad
y2 = -rad
If map(x1,y1) = 1
For y2=-rad To rad
For x2=-rad To rad
x3 = x1+x2
y3 = y1+y2
If RectsOverlap(x3,y3,1,1,0,0,mapw+1,maph+1) = True
If map(x3,y3) = 0 Then fits = False:Exit
If cmap(x3,y3) = 1 Then fits = False:Exit
Else
fits = False :Exit
EndIf
Next
Next
If fits = True Then
For y2 = -rad To rad
For x2 = -rad To rad
x3 = x1 + x2
y3 = y1 + y2
cmap(x3,y3) = 1
Next
Next
r1.r = New r
r1\x = x1-rad
r1\y = y1-rad
r1\w = rad*2
r1\h = rad*2
End If
End If
x1 = x1 + 1
If x1 > mapw
y1 = y1 + 1
x1 = 0
End If
If x1 => mapw And y1=>maph Then
x1 = 0
y1 = 0
rad = rad - 1
End If
If rad < 0 Then exitloop = True
Wend
;
; Pass 2 - check the list for 4x4 rectangles to create one off
;
For y=0 To maph
For x=0 To mapw
If map(x,y) = 1
For this.r = Each r
If this\x = x And this\y = y And this\w = 0
aset = False
For a.r = Each r
If a\x = this\x+1 And a\y = this\y And a\w = 0 Then aset = True
Next
bset = False
For b.r = Each r
If b\x = this\x And b\y = this\y+1 And b\w = 0 Then bset = True
Next
cset = False
For c.r = Each r
If c\x = this\x+1 And c\y = this\y+1 And c\w = 0 Then cset = True
Next
If aset = True And bset = True And cset = True
that.r = New r
that\x = this\x
that\y = this\y
that\w = 1
that\h = 1
For a.r = Each r
del = False
If a\x = this\x+1 And a\y = this\y And a\w = 0 Then Del = True
If a\x = this\x And a\y = this\y+1 And a\w = 0 Then del = True
If a\x = this\x+1 And a\y = this\y+1 And a\w = 0 Then del = True
If del = True Then Delete a
Next
Delete this
End If
End If
Next
End If
Next
Next
End Function
Function drawrects()
Color 255,255,255
For this.r = Each r
Rect this\x*10,this\y*10,(this\w+1)*10,(this\h+1)*10,False
Next
End Function
Function drawmap()
For y=0 To maph
For x=0 To mapw
Select map(x,y)
Case 0:Color 0,0,0
Case 1:Color 100,100,100
End Select
Rect x*10,y*10,10,10,True
Next
Next
End Function
Function initmap()
For y=0 To maph
For x=0 To mapw
map(x,y) = 0
Next
Next
exitloop = False
While exitloop = False
x1 = Rand(mapw)
y1 = Rand(maph)
rad = Rand(3,6)
For y2 = -rad To rad
For x2 = -rad To rad
x3 = x1+x2
y3 = y1+y2
If x3 => 0 And y3 >= 0 And x3 =< mapw And y3 <= maph
map(x3,y3) = map(x3,y3) + 1
If map(x3,y3) > 10 Then exitloop = True
End If
Next
Next
Wend
For y = 0 To maph
For x = 0 To mapw
If map(x,y) < 5 Then map(x,y) = 0
If map(x,y) > 4 Then map(x,y) = 1
Next
Next
End Function