-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
executable file
·175 lines (110 loc) · 3.15 KB
/
sketch.js
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
function drawGrass(x1, y1, maxLength) {
var totalLength = 0;
var currentLength = 0;
while (totalLength < maxLength) {
var height = random(2, 10);
currentLength = random(2, 6);
if (currentLength + totalLength > maxLength) {
currentLength = maxLength - totalLength;
}
fill(color(55, random(150, 255), 55));
rect(x1 + totalLength, y1 - height, currentLength, height, 2, 2, 0, 0, 0);
totalLength += currentLength;
}
}
function drawTopsoil(x1, y1, maxLength) {
var maxX = x1 + maxLength;
var width = random(1, 3);
var totalLength = x1 + width;
push();
noStroke();
fill(_.sample(greens));
while (totalLength < maxX) {
ellipse(totalLength, y1, width, random(1, 3));
totalLength += random(1, 3);
}
pop();
}
function speckleBlock(x1, y1, width, height, density) {
var totalArea = 0;
var maxArea = width * height;
var spots = [];
var maxX = x1 + width;
var maxY = y1 + height;
var count = 50;
function overlap(rect1, rect2) {
var overlapper = rect1.x1 <= rect2.x2 & rect1.x2 >= rect2.x1 & rect1.y1 <= rect2.y2 & rect1.y2 >= rect2.y1;
return overlapper;
}
push();
noStroke();
while (totalArea / maxArea <= density) {
count--;
fill(_.sample(dirts));
width = random(4, 20);
height = random(4, 20);
var originX = random(x1, maxX - width - 4);
var originY = random(y1, maxY - height - 4);
var spot = {
x1: originX,
x2: originX + width,
y1: originY,
y2: originY + height
}
//var doesItOverlap = _.some(spots, function(r) {
//return overlap(spot, r);
//});
//if (doesItOverlap) {
//continue;
//}
rect(spot.x1, spot.y1, width, height, 2, 2, 2, 2);
totalArea += width * height;
//spots.push(spot);
}
pop();
}
function drawBlock(x1, y1, width, height) {
push();
fill(_.sample(tileBackgrounds));
rect(x1, y1, width, height);
pop();
}
function drawTile(x1, y1, width, height, density) {
noStroke();
drawBlock(x1, y1, width, height);
speckleBlock(x1, y1, width, height, density);
speckleBlock(x1, y1, width, height, density);
drawGrass(x1, y1, width);
// drawTopsoil(x1, y1, width);
//drawTopsoil(x1, y1, width);
drawGrass(x1, y1, width);
}
function setup() {
createCanvas(windowWidth, windowHeight);
background("#7ec0ee");
greens = [
color("#316516"),
color("#557D24"),
color("#D9F895"),
color("#B8F348"),
color("#65AE2D")
]
tileBackgrounds = [
color(53, 49, 13, 255)
]
dirts = [
color(53, 49, 13, 122),
color(98, 73, 33, 122),
color(37, 39, 25, 122)
];
for (var i = 300; i >= 0; i-=20) {
drawTile(i,100,20,20,.75);
};
}
function mouseClicked() {
console.log(mouseX,mouseY);
console.log(Math.ceil(mouseX/20)*20,Math.ceil(mouseY/20));
drawTile(Math.floor(mouseX/20)*20,Math.floor(mouseY/20)*20,20,20,.75);
}
function draw() {
}