Add multiple initial distributions, "griddy" distribution.
Chris Pressey
4 years ago
0 | 0 |
Latcarf
|
1 | 1 |
=======
|
2 | 2 |
|
|
3 |
_Try it online_ [@ catseye.tc](https://catseye.tc/installation/Latcarf)
|
|
4 |
| _See also:_ [Maze Clouds](https://github.com/catseye/Maze-Clouds)
|
|
5 |
∘ [Erratic Turtle Graphics](https://github.com/catseye/Erratic-Turtle-Graphics)
|
|
6 |
|
3 | 7 |

|
4 | |
|
5 | |
_Try it online [here](https://catseye.tc/installation/Latcarf)._
|
6 | 8 |
|
7 | 9 |
This is a gewgaw from an idea I had in (I think) 2017 or 2018,
|
8 | 10 |
which was this:
|
15 | 15 |
|
16 | 16 |
var controlPanel = div(
|
17 | 17 |
div(
|
|
18 |
DAM.makeSelect({
|
|
19 |
title: "Initial distribution",
|
|
20 |
options: [
|
|
21 |
{
|
|
22 |
text: 'Random',
|
|
23 |
value: 'random'
|
|
24 |
},
|
|
25 |
{
|
|
26 |
text: 'Griddy',
|
|
27 |
value: 'griddy'
|
|
28 |
}
|
|
29 |
],
|
|
30 |
onchange: function(option) {
|
|
31 |
gewgaw.setInitialDistribution(option.value);
|
|
32 |
gewgaw.reset();
|
|
33 |
}
|
|
34 |
})
|
|
35 |
),
|
|
36 |
div(
|
18 | 37 |
button("Re-roll", {
|
19 | 38 |
onclick: function() {
|
20 | 39 |
gewgaw.reset();
|
4 | 4 |
this.init = function(cfg) {
|
5 | 5 |
this.canvas = cfg.canvas;
|
6 | 6 |
this.ctx = this.canvas.getContext('2d');
|
|
7 |
this.initialDistribution = cfg.initialDistribution || 'random';
|
7 | 8 |
this.start();
|
|
9 |
};
|
|
10 |
|
|
11 |
this.setInitialDistribution = function(initialDistribution) {
|
|
12 |
this.initialDistribution = initialDistribution;
|
8 | 13 |
};
|
9 | 14 |
|
10 | 15 |
this.start = function() {
|
|
12 | 17 |
|
13 | 18 |
// add many small objects
|
14 | 19 |
for (var i = 0; i < 100; i++) {
|
15 | |
var nobj = {
|
16 | |
x: Math.floor(Math.random() * this.canvas.width),
|
17 | |
y: Math.floor(Math.random() * this.canvas.height),
|
18 | |
r: 2,
|
19 | |
connection: null
|
20 | |
};
|
|
20 |
var nobj;
|
|
21 |
if (this.initialDistribution === 'random') {
|
|
22 |
nobj = {
|
|
23 |
x: Math.floor(Math.random() * this.canvas.width),
|
|
24 |
y: Math.floor(Math.random() * this.canvas.height),
|
|
25 |
r: 2,
|
|
26 |
connection: null
|
|
27 |
};
|
|
28 |
} else if (this.initialDistribution === 'griddy') {
|
|
29 |
var widthU = this.canvas.width * 0.10;
|
|
30 |
var heightU = this.canvas.height * 0.10;
|
|
31 |
var xerror = Math.floor(Math.random() * widthU / 2) - (widthU / 4);
|
|
32 |
var yerror = Math.floor(Math.random() * heightU / 2) - (heightU / 4);
|
|
33 |
nobj = {
|
|
34 |
x: (i % 10) * widthU + widthU / 2 + xerror,
|
|
35 |
y: Math.floor(i / 10) * heightU + heightU / 2 + yerror,
|
|
36 |
r: 2,
|
|
37 |
connection: null
|
|
38 |
};
|
|
39 |
}
|
21 | 40 |
this.objects.push(nobj);
|
22 | 41 |
}
|
23 | 42 |
|