GREEN 64 1 208 1.91 KB 86
-
1.
//Diamond Patchwork
-
2.
function generateSites(width, height, count) {
-
3.
const ratio = width / height;
-
4.
const cols = Math.max(1, Math.round(Math.sqrt((count / 1.25) * ratio)));
-
5.
const rows = Math.max(1, Math.round((count / 1.25) / cols));
-
6.
-
7.
const sites = [];
-
8.
const stepX = width / cols;
-
9.
const stepY = height / rows;
-
10.
-
11.
for (let y = 0; y < rows; y++) {
-
12.
for (let x = 0; x < cols; x++) {
-
13.
sites.push([
-
14.
(x + 0.5) * stepX,
-
15.
(y + 0.5) * stepY
-
16.
]);
-
17.
-
18.
if (x % 2 === 1 && y % 2 === 1) {
-
19.
sites.push([
-
20.
x * stepX,
-
21.
y * stepY
-
22.
]);
-
23.
}
-
24.
}
-
25.
}
-
26.
-
27.
return sites;
-
28.
}
-
29.
-
30.
//Double Diamond Patchwork
-
31.
function generateSites(width, height, count) {
-
32.
const ratio = width / height;
-
33.
const cols = Math.max(1, Math.round(Math.sqrt((count / 1.5) * ratio)));
-
34.
const rows = Math.max(1, Math.round((count / 1.5) / cols));
-
35.
-
36.
const sites = [];
-
37.
const stepX = width / cols;
-
38.
const stepY = height / rows;
-
39.
-
40.
for (let y = 0; y < rows; y++) {
-
41.
for (let x = 0; x < cols; x++) {
-
42.
sites.push([
-
43.
(x + 0.5) * stepX,
-
44.
(y + 0.5) * stepY
-
45.
]);
-
46.
-
47.
if (x > 0 && y > 0 && x % 2 === y % 2) {
-
48.
sites.push([
-
49.
x * stepX,
-
50.
y * stepY
-
51.
]);
-
52.
}
-
53.
}
-
54.
}
-
55.
-
56.
return sites;
-
57.
}
-
58.
-
59.
//Oops! All Diamonds
-
60.
function generateSites(width, height, count) {
-
61.
const ratio = width / height;
-
62.
const cols = Math.max(1, Math.round(Math.sqrt((count / 2) * ratio)));
-
63.
const rows = Math.max(1, Math.round((count / 2) / cols));
-
64.
-
65.
const sites = [];
-
66.
const stepX = width / cols;
-
67.
const stepY = height / rows;
-
68.
-
69.
for (let y = 0; y < rows; y++) {
-
70.
for (let x = 0; x < cols; x++) {
-
71.
sites.push([
-
72.
(x + 0.5) * stepX,
-
73.
(y + 0.5) * stepY
-
74.
]);
-
75.
-
76.
if (x > 0 && y > 0) {
-
77.
sites.push([
-
78.
x * stepX,
-
79.
y * stepY
-
80.
]);
-
81.
}
-
82.
}
-
83.
}
-
84.
-
85.
return sites;
-
86.
}
by Trixie_Voronoi