git @ Cat's Eye Technologies Latcarf / d7108c7
Add multiple initial distributions, "griddy" distribution. Chris Pressey 4 years ago
3 changed file(s) with 48 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
00 Latcarf
11 =======
22
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
37 ![screenshot](images/latcarf1.png?raw=true)
4
5 _Try it online [here](https://catseye.tc/installation/Latcarf)._
68
79 This is a gewgaw from an idea I had in (I think) 2017 or 2018,
810 which was this:
1515
1616 var controlPanel = div(
1717 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(
1837 button("Re-roll", {
1938 onclick: function() {
2039 gewgaw.reset();
44 this.init = function(cfg) {
55 this.canvas = cfg.canvas;
66 this.ctx = this.canvas.getContext('2d');
7 this.initialDistribution = cfg.initialDistribution || 'random';
78 this.start();
9 };
10
11 this.setInitialDistribution = function(initialDistribution) {
12 this.initialDistribution = initialDistribution;
813 };
914
1015 this.start = function() {
1217
1318 // add many small objects
1419 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 }
2140 this.objects.push(nobj);
2241 }
2342