-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator - Tiles2 - Grow - angle light shade Edges.monkey
352 lines (330 loc) · 7.29 KB
/
Generator - Tiles2 - Grow - angle light shade Edges.monkey
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
'
' Tile generator
' Lighting/shadow from (angle) side
'
Import mojo
Class tiles
'base color
Field r:Int,g:Int,b:Int
'tile width and height
Field tw:Int,th:Int
' angle light
Field angle:Float
' image array
Field im:Int[][]
' double array
Field imd:Int[][]
' new tile
Method New(tw:Int,th:Int,r:Int,g:Int,b:Int,angle:Int)
Self.tw = tw
Self.th = th
Self.r = r
Self.g = g
Self.b = b
Self.angle = angle
im = New Int[tw][]
For Local i:Int=0 Until tw
im[i] = New Int[th]
Next
imd = New Int[(tw*2)][]
For Local i:Int=0 Until (tw*2)
imd[i] = New Int[(th*2)]
Next
createtile()
createdouble()
blackedge(Rnd(1,5))
'bars()
End Method
Method createdouble()
For Local y:Int=0 Until th
For Local x:Int=0 Until tw
For Local y2:Int=0 To 1
For Local x2:Int=0 To 1
imd[x*2+x2][y*2+y2] = im[x][y]
Next
Next
Next
Next
Local imt[][] = New Int[(tw*2)][]
For Local i:Int=0 Until (tw*2)
imt[i] = New Int[(th*2)]
Next
For Local y:Int=1 Until th*2-1
For Local x:Int=1 Until tw*2-1
If imd[x][y] > 1
Local v:Int=imd[x][y]
If imd[x+1][y+1] = 1
imt[x][y] = 1
End If
If imd[x-1][y-1] = 1
imt[x][y] = 1
End If
If imd[x+1][y-1] = 1
imt[x][y] = 1
End If
If imd[x-1][y+1] = 1
imt[x][y] = 1
End If
Endif
Next
Next
For Local y:Int=0 Until th*2
For Local x:Int=0 Until tw*2
If imt[x][y] = 1 Then imd[x][y] = 1
Next
Next
End Method
Method createtile()
'grow some area
im[Rnd(tw/2-tw/9,tw/2+tw/9)][Rnd(th/2-th/9,th/2+th/9)] = 1
im[Rnd(tw/2-tw/9,tw/2+tw/9)][Rnd(th/2-th/9,th/2+th/9)] = 1
grow
edgelight
edgenoise()
' bars()
End Method
'
Method blackedge(size:Int)
If size<=0 Or size>=10 Then Return
'make black edge around double im
Local imdt:Int[][]
imdt = New Int[tw*2][]
For Local i:Int=0 Until tw*2
imdt[i] = New Int[th*2]
Next
For Local y:Int=size Until th*2-size
For Local x:Int=size Until tw*2-size
If imd[x][y] = 0
For Local y2:Int=y-size To y+size
For Local x2:Int=x-size To x+size
If imd[x2][y2] > 0
imdt[x][y] = 1
End If
Next
Next
End If
Next
Next
For Local y:Int=0 Until th*2
For Local x:Int=0 Until tw*2
If imdt[x][y] > 0 Then imd[x][y] = 99
Next
Next
'make black edge around im
Local imt:Int[][]
imt = New Int[tw][]
For Local i:Int=0 Until tw
imt[i] = New Int[th]
Next
For Local y:Int=size Until th-size
For Local x:Int=size Until tw-size
If im[x][y] = 0
For Local y2:Int=y-size To y+size
For Local x2:Int=x-size To x+size
If im[x2][y2] > 0
imt[x][y] = 1
End If
Next
Next
End If
Next
Next
For Local y:Int=0 Until th
For Local x:Int=0 Until tw
If imt[x][y] > 0 Then im[x][y] = 99
Next
Next
End Method
'
' Add some light bars ontop of base color
'
Method bars()
For Local x:Int=-50 Until tw+50 Step 10
Local x2:Int=x+2
For Local y:Int=0 Until th
Local xa:Int=x2
Local ya:Int=y
x2+=1
If xa<0 Or ya<0 Or xa>=tw Or ya>=th Then Continue
For Local z:Int=0 Until 3
If xa+z<0 Or xa+z>=tw Then Continue
If im[xa+z][ya] = 1 Then im[xa+z][ya] = 3
Next
Next
Next
'
For Local x:Int=-tw Until (tw*2)+50 Step 16
Local x2:Int=x+2
For Local y:Int=0 Until th*2
Local xa:Int=x2
Local ya:Int=y
x2+=1
If xa<0 Or ya<0 Or xa>=tw*2 Or ya>=th*2 Then Continue
For Local z:Int=0 Until 8
If xa+z<0 Or xa+z>=tw*2 Then Continue
If z=7 And imd[xa+z][ya] = 1 Then imd[xa+z][ya] = 5
If imd[xa+z][ya] = 1 Then imd[xa+z][ya] = 3
Next
Next
Next
End Method
' grow the base a certain amount
Method grow()
For Local i:Int=0 Until tw*th*(tw/4)
Local x:Int=Rnd(7,tw-7)
Local y:Int=Rnd(7,th-7)
If im[x][y] = 1 Then
im[Rnd(x-1,x+2)][Rnd(y-1,y+2)] = 1
End If
Next
End Method
' add light and shadows to the sides
' starts from the center and goes to the outside
' in all angles and finds edge and creates lighter or
' darker value
'
'
Method edgelight()
Local tim:Int[][]
tim = New Int[tw][]
For Local i:Int=0 Until tw
tim[i] = New Int[th]
Next
For Local a:Float=angle Until angle+360 Step .1
Local x:Float=tw/2
Local y:Float=th/2
While x>1 And y>1 And x<=tw-2 And y<=th-2
x+=Cos(a)
y+=Sin(a)
If im[x][y] = 1
For Local ia:Int=-1 To 1
For Local ib:Int=-1 To 1
If im[x+ia][y+ib] = 0
If a>angle+180 Then tim[x][y] = 3 Else tim[x][y]=2
End If
Next
Next
End If
Wend
Next
For Local y:Int=0 Until th
For Local x:Int=0 Until tw
If tim[x][y]>0 Then im[x][y] = tim[x][y]
Next
Next
End Method
'
' Find the edges and adds randomly
' a extra light or dark value
'
Method edgenoise()
Local amountnoise:Float=Rnd(4,6)
For Local i:Int=0 Until tw*th*amountnoise
Local x:Int=Rnd(2,tw-3)
Local y:Int=Rnd(2,th-3)
Local v:Int=im[x][y]
If v=2 Or v=3
Local x2:Int=x+Rnd(-2,2)
Local y2:Int=y+Rnd(-2,2)
' if current position on array is base color
' then add noise(current light or dark color)
If im[x2][y2] = 1 'Or im[x2][y2] = v
im[x2][y2] = v+2
End If
End If
Next
End Method
Method drawdoublearray(sx:Int,sy:Int)
'0 = black
'1 = base color
'2 = base color dark
'3 = base color light
'4 = base color slightly darker
'5 = base color slightly ligher
For Local y:Int=0 Until th*2
For Local x:Int=0 Until tw*2
If imd[x][y] = 0 Then Continue
setcolor(imd[x][y])
' DrawRect sx+x*3,sy+y*3,3,3
DrawRect sx+x,sy+y,1,1
Next
Next
End Method
Method drawarray(sx:Int,sy:Int)
'0 = black
'1 = base color
'2 = base color dark
'3 = base color light
'4 = base color slightly darker
'5 = base color slightly ligher
For Local y:Int=0 Until th
For Local x:Int=0 Until tw
If im[x][y] = 0 Then Continue
setcolor(im[x][y])
' DrawRect sx+x*3,sy+y*3,3,3
DrawRect sx+x,sy+y,1,1
Next
Next
End Method
Method setcolor(col:Int)
Select col
Case 0;SetColor 0,0,0
Case 1;SetColor r,g,b
Case 2'base color dark
SetColor r/4,g/4,b/4
Case 3'base color light
Local r2:Int,g2:Int,b2:Int
r2 = r*1.2 ; If r2>255 Then r2=255
g2 = g*1.2 ; If g2>255 Then g2=255
b2 = b*1.2 ; If b2>255 Then b2=255
SetColor r2,g2,b2
Case 4'base color slighly darker
SetColor r/2,g/2,b/2
Case 5'base color slightly lighter
Local r2:Int,g2:Int,b2:Int
r2 = r*1.4 ; If r2>255 Then r2=255
g2 = g*1.4 ; If g2>255 Then g2=255
b2 = b*1.4 ; If b2>255 Then b2=255
SetColor r2,g2,b2
Case 99;SetColor 11,11,11
End Select
End Method
End Class
Class MyGame Extends App
Field tile:tiles[]
Field t:Int=0
Method OnCreate()
SetUpdateRate(1)
newtiles()
End Method
Method OnUpdate()
t+=1
If t>5
t=0
newtiles()
End If
End Method
Method OnRender()
Cls 125,125,125
SetColor 255,255,255
Local cnt:Int=0
For Local y:Int=1 Until 5
For Local x:Int=1 Until 5
tile[cnt].drawdoublearray(x*100,y*80)
tile[cnt].drawarray(x*100,y*80)
cnt+=1
Next
Next
End Method
Method newtiles()
tile = New tiles[16]
Local angle:Int=Rnd(360)
For Local i:Int=0 Until 16
Local s:Int=Rnd(32,100)
tile[i] = New tiles(s,s,100+Rnd(100),100+Rnd(100),100+Rnd(100),angle)
Next
End Method
End Class
Function Main()
New MyGame()
End Function