-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator rectangles - drip and blend.monkey
126 lines (119 loc) · 3.16 KB
/
Generator rectangles - drip and blend.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
Import mojo
Class themap
Field mapwidth:Int
Field mapheight:Int
Field tilewidth:Float
Field tileheight:Float
Field map:Float[][]
Method New( mapwidth:Int,
mapheight:Int)
Self.mapwidth = mapwidth
Self.mapheight = mapheight
tilewidth = DeviceWidth()/Float(mapwidth)
tileheight = DeviceHeight()/Float(mapheight)
map = New Float[mapwidth][]
For Local i = 0 Until mapwidth
map[i] = New Float[mapheight]
Next
fillwithrects()
dripmap()
blur()
End Method
Method fillwithrects()
For Local i=0 Until mapwidth/15
Local w:Int=Rnd((mapwidth/7),(mapwidth/3))
Local h:Int=Rnd((mapheight/7),(mapheight/3))
Local x:Int=Rnd(0,mapwidth-w)
Local y:Int=Rnd(0,mapheight-h)
makerect(x,y,w,h)
Next
End Method
Method makerect(x:Int,y:Int,w:Int,h:Int)
For Local y1=y To y+h
For Local x1=x To x+w
If x1>0 And x1<mapwidth
If y1>0 And y1<mapheight
map[x1][y1] = 50
End If
End If
Next
Next
End Method
Method blur()
For Local i=0 Until 95000
Local x:Int=Rnd(0,mapwidth)
Local y:Int=Rnd(0,mapheight)
If x+1<mapwidth
If y+1<mapheight
Local a=map[x+1][y]
Local b=map[x][y+1]
Local c=map[x+1][y+1]
map[x][y] = (a+b+c)/3
End If
End If
Next
End Method
Method dripmap()
For Local x=0 Until mapwidth
Local dp:Int=Rnd(mapwidth/15,mapwidth/5)
For Local do = 0 Until dp
For Local y=mapheight-1 Until 1 Step -1
map[x][y] = map[x][y-1]
Next
Next
Next
For Local y=0 Until mapheight
Local dp:Int=Rnd(mapheight/15,mapheight/5)
For Local do = 0 Until dp
For Local x=mapwidth-1 Until 1 Step -1
map[x][y] = map[x-1][y]
Next
Next
Next
End Method
Method drawmap()
Local dm:Int=Rnd(0,2)
For Local y:Float=0 Until mapheight Step 1
For Local x:Float=0 Until mapwidth Step 1
If dm = 0 Then
SetColor map[x][y],map[x][y],map[x][y]
Else
If map[x][y] >0 Then SetColor 125,125,125
If map[x][y] >20 Then SetColor 250,250,250
If map[x][y] = 0 Then SetColor 0,0,0
End if
DrawRect x*tilewidth,
y*tileheight,
tilewidth+1,
tileheight+1
Next
Next
End Method
Method clearheightmap()
End Method
End Class
Global mymap:themap
Class MyGame Extends App
Method OnCreate()
SetUpdateRate(1)
Local date := GetDate()
Seed = date[5]
mymap = New themap( 100,
100)
End Method
Method OnUpdate()
mymap = New themap(100,100)
End Method
Method OnRender()
Cls 40,40,40
mymap.drawmap
SetColor 255,255,255
DrawText "MonkeyX",
(DeviceWidth()/2),10,.5,.5
DrawText "Dripping/Blurring rectangles",
(DeviceWidth()/2),25,.5,.5
End Method
End Class
Function Main()
New MyGame()
End Function