-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator - Tiles - Grow - angle light shade Edges.monkey
208 lines (196 loc) · 4.33 KB
/
Generator - Tiles - 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
'
' 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[][]
' 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
createtile()
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
'
' 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
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:Int=angle Until angle+360
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(.5,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 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
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/3,g/3,b/3
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/1.5,g/1.5,b/1.5
Case 5'base color slightly lighter
Local r2:Int,g2:Int,b2:Int
r2 = r*1.7 ; If r2>255 Then r2=255
g2 = g*1.7 ; If g2>255 Then g2=255
b2 = b*1.7 ; If b2>255 Then b2=255
SetColor r2,g2,b2
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 0,0,0
SetColor 255,255,255
Local cnt:Int=0
For Local y:Int=0 Until 4
For Local x:Int=0 Until 4
tile[cnt].drawarray(x*130,y*100)
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