<
PrototypeJungle
>

Web

This module builds webs, where a web is defined as a set of lines drawn between given points, in such a way that intersections do not occur.

As customary, webs will be introduced via annotated code, which generates this image:

Here's the code:

import {rs as linePP} from '/shape/line.mjs';
import {rs as basicP} from '/generators/basics.mjs';
import {rs as addPointMethods} from '/mlib/pointGen.mjs';	
import {rs as addWebMethods} from '/mlib/web.mjs';	

let rs = basicP.instantiate();
addPointMethods(rs);
addWebMethods(rs);
rs.setName('web_wheel');
let rd= 3000;

let  topParams = {width:rd,height:rd,framePadding:1.2*rd};
let  webParams = {webTries:1000,minConnectorLength:0,maxConnectorLength:2000};
let ringParams = {numRings:20,radius:rd,numPointsPerRing:20};
Object.assign(rs,topParams);

rs.initProtos = function () {	
  let lineP = this.lineP = linePP.instantiate();
  this.lineP.stroke = 'white';
  this.lineP['stroke-width'] = .1;
  this.lineP['stroke-width'] = 5;
}  

rs.initialize = function () {
  this.initProtos();
  let points = this.ringPoints(ringParams);
  this.generateWeb(Object.assign(webParams,{points}));
  this.addFrame();
}

export {rs};

A web is a set of lines ("connectors") obeying the length constraints which connect given points without intersecting. generateWeb successively adds new connectors until it impossible to add a connector without intersection. generateWeb has this type:

generateWeb({points:arrayOf(Point),minConnectorLength:number,maxConnectorLength,lineP:line});

generateWeb will take its parameters from this if they are not found in the parameter object.