Configuration parameters const numberOfNodes 6 const connectivityAmount 0 5 Proportion of nodes each node is connected to in the decentralized network Generate centralized network connections const centralizedConnections Array from length numberOfNodes _ i if i 0 return Array from length numberOfNodes 1 _ j j 1 return 0 Generate decentralized network connections const decentralizedConnections Array from length numberOfNodes for let i 0 i numberOfNodes i const numConnections Math round numberOfNodes 1 connectivityAmount const availableNodes Array from length numberOfNodes 1 _ j j 1 for let j 0 j numConnections j const randomIndex Math floor Math random availableNodes length decentralizedConnections i push availableNodes randomIndex availableNodes splice randomIndex 1 Generate random 2D node locations const nodePositions generateRandomNodePositions numberOfNodes 100 700 100 300 Draw network configurations const drawNetwork connections centralNodeIndex color const canvas document createElement canvas canvas width 800 canvas height 400 document body appendChild canvas const ctx canvas getContext 2d const nodeRadius 20 ctx fillStyle white ctx fillRect 0 0 canvas width canvas height Draw connections for let i 0 i numberOfNodes i const x y nodePositions i for let j 0 j connections i length j const connectionIndex connections i j const x connectedX y connectedY nodePositions connectionIndex ctx beginPath ctx moveTo x y ctx lineTo connectedX connectedY ctx stroke Draw nodes for let i 0 i numberOfNodes i const x y nodePositions i ctx beginPath ctx arc x y nodeRadius 0 2 Math PI ctx fillStyle i centralNodeIndex color black Draw nodes that are not connected in a different color if connections i length 0 ctx fillStyle gray ctx fill ctx stroke function generateRandomNodePositions numNodes minX maxX minY maxY const positions for let i 0 i numNodes i const x Math floor Math random maxX minX 1 minX const y Math floor Math random maxY minY 1 minY positions push x y return positions const centralNodeIndex 0 drawNetwork centralizedConnections centralNodeIndex red drawNetwork decentralizedConnections 1 black Configuration parameters const numberOfNodes 20 const connectivityAmount 0 1 Proportion of nodes each node is connected to in the decentralized network const nodeRadius 5 Radius of the nodes Generate centralized network connections const centralizedConnections Array from length numberOfNodes _ i if i 0 return Array from length numberOfNodes 1 _ j j 1 return 0 Generate decentralized network connections const decentralizedConnections Array from length numberOfNodes for let i 0 i numberOfNodes i const numConnections Math round numberOfNodes 1 connectivityAmount const availableNodes Array from length numberOfNodes 1 _ j j 1 for let j 0 j numConnections j const randomIndex Math floor Math random availableNodes length decentralizedConnections i push availableNodes randomIndex availableNodes splice randomIndex 1 Generate random 2D node locations const nodePositions generateRandomNodePositions numberOfNodes 100 700 100 300 Draw network configurations const drawNetwork connections centralNodeIndex color const canvas document createElement canvas canvas width 800 canvas height 400 document body appendChild canvas const ctx canvas getContext 2d ctx fillStyle white ctx fillRect 0 0 canvas width canvas height Draw connections for let i 0 i numberOfNodes i const x y nodePositions i for let j 0 j connections i length j const connectionIndex connections i j const x connectedX y connectedY nodePositions connectionIndex ctx beginPath ctx moveTo x y ctx lineTo connectedX connectedY ctx stroke Draw nodes for let i 0 i numberOfNodes i const x y nodePositions i ctx beginPath ctx arc x y nodeRadius 0 2 Math PI ctx fillStyle i centralNodeIndex color black Draw nodes that are not connected in a different color if connections i length 0 ctx fillStyle gray ctx fill ctx stroke function generateRandomNodePositions numNodes minX maxX minY maxY const positions for let i 0 i numNodes i const x Math floor Math random maxX minX 1 minX const y Math floor Math random maxY minY 1 minY positions push x y return positions drawNetwork centralizedConnections 0 red drawNetwork decentralizedConnections 1 black Configuration parameters const numberOfNodes 60 const connectivityAmount 0 01 Proportion of nodes each node is connected to in the decentralized network const nodeRadius 5 Radius of the nodes Generate centralized network connections const centralizedConnections Array from length numberOfNodes _ i if i 0 return Array from length numberOfNodes 1 _ j j 1 return 0 Generate decentralized network connections const decentralizedConnections Array from length numberOfNodes for let i 0 i numberOfNodes i const numConnections Math round numberOfNodes 1 connectivityAmount const availableNodes Array from length numberOfNodes 1 _ j j 1 for let j 0 j numConnections j const randomIndex Math floor Math random availableNodes length decentralizedConnections i push availableNodes randomIndex availableNodes splice randomIndex 1 Generate random 2D node locations const nodePositions generateRandomNodePositions numberOfNodes 100 700 100 300 Draw network configurations const drawNetwork connections centralNodeIndex centralNodeColor disconnectedNodeColor const canvas document createElement canvas canvas width 800 canvas height 400 document body appendChild canvas const ctx canvas getContext 2d ctx fillStyle white ctx fillRect 0 0 canvas width canvas height Draw connections for let i 0 i numberOfNodes i const x y nodePositions i for let j 0 j connections i length j const connectionIndex connections i j const x connectedX y connectedY nodePositions connectionIndex ctx beginPath ctx moveTo x y ctx lineTo connectedX connectedY ctx stroke Draw nodes for let i 0 i numberOfNodes i const x y nodePositions i ctx beginPath ctx arc x y nodeRadius 0 2 Math PI if i centralNodeIndex ctx fillStyle centralNodeColor else if connections i length 0 ctx fillStyle disconnectedNodeColor else ctx fillStyle black ctx fill ctx stroke function generateRandomNodePositions numNodes minX maxX minY maxY const positions for let i 0 i numNodes i const x Math floor Math random maxX minX 1 minX const y Math floor Math random maxY minY 1 minY positions push x y return positions drawNetwork centralizedConnections 0 red black drawNetwork decentralizedConnections 1 black orange Configuration parameters const numberOfNodes 20 const connectivityAmount 0 05 Proportion of nodes each node is connected to in the decentralized network const nodeRadius 5 Radius of the nodes Generate centralized network connections const centralizedConnections Array from length numberOfNodes _ i if i 0 return Array from length numberOfNodes 1 _ j j 1 return 0 Generate decentralized network connections const decentralizedConnections Array from length numberOfNodes for let i 0 i numberOfNodes i const numConnections Math round numberOfNodes 1 connectivityAmount const connectedNodes Array from length numberOfNodes 1 _ j j 1 connectedNodes splice i 1 Remove current node from the list of connected nodes for let j 0 j numConnections j const randomIndex Math floor Math random connectedNodes length decentralizedConnections i push connectedNodes randomIndex connectedNodes splice randomIndex 1 Generate random 2D node locations const nodePositions generateRandomNodePositions numberOfNodes 100 700 100 300 Draw network configurations const drawNetwork connections centralNodeIndex centralNodeColor disconnectedNodeColor const canvas document createElement canvas canvas width 800 canvas height 400 document body appendChild canvas const ctx canvas getContext 2d ctx fillStyle white ctx fillRect 0 0 canvas width canvas height Draw connections for let i 0 i numberOfNodes i const x y nodePositions i for let j 0 j connections i length j const connectionIndex connections i j const x connectedX y connectedY nodePositions connectionIndex ctx beginPath ctx moveTo x y ctx lineTo connectedX connectedY ctx stroke Draw nodes for let i 0 i numberOfNodes i const x y nodePositions i ctx beginPath ctx arc x y nodeRadius 0 2 Math PI if connections i length 0 ctx fillStyle disconnectedNodeColor else if i centralNodeIndex ctx fillStyle centralNodeColor else ctx fillStyle black ctx fill ctx stroke function generateRandomNodePositions numNodes minX maxX minY maxY const positions for let i 0 i numNodes i const x Math floor Math random maxX minX 1 minX const y Math floor Math random maxY minY 1 minY positions push x y return positions drawNetwork centralizedConnections 0 red black drawNetwork decentralizedConnections 1 black orange
f nodes each node is connected to in the decentralized network const nodeRadius 5 Radius of the nodes Generate centralized network connections const centralizedConnections Array from length numberOfNodes _ i if i 0 return Array from length numberOfNodes 1 _ j j 1 return 0 Generate decentralized network connections const decentralizedConnections Array from length numberOfNodes for let i 0 i numberOfNodes i const numConnections Math round numberOfNodes 1 connectivityAmount const availableNodes Array from length numberOfNodes 1 _ j j 1 for let j 0 j numConnections j const randomIndex Math floor Math random availableNodes length decentralizedConnections i push availableNodes randomIndex availableNodes splice randomIndex 1 Generate random 2D node locations const nodePositions generateRandomNodePositions numberOfNodes 100 700 100 300 Draw network configurations const drawNetwork connections centralNodeIndex centralNodeColor disconnectedNodeColor const canvas document createElement canvas canvas width 800 canvas height 400 document body appendChild canvas const ctx canvas getContext 2d ctx fillStyle white ctx fillRect 0 0 canvas width canvas height Draw connections for let i 0 i numberOfNodes i const x y nodePositions i for let j 0 j connections i length j const connectionIndex connections i j const x connectedX y connectedY nodePositions connectionIndex ctx beginPath ctx moveTo x y ctx lineTo connectedX connectedY ctx stroke Draw nodes for let i 0 i numberOfNodes i const x y nodePositions i ctx beginPath ctx arc x y nodeRadius 0 2 Math PI if i centralNodeIndex ctx fillStyle centralNodeColor else if connections i length 0 ctx fillStyle disconnectedNodeColor else ctx fillStyle black ctx fill ctx stroke function generateRandomNodePositions numNodes minX maxX minY maxY const positions for let i 0 i numNodes i const x Math floor Math random maxX minX 1 minX const y Math floor Math random maxY minY 1 minY positions push x y return positions drawNetwork centralizedConnections 0 red black drawNetwork decentralizedConnections 1 black orange Configuration parameters const numberOfNodes 20 const connectivityAmount 0 05 Proportion of nodes each node is connected to in the decentralized network const nodeRadius 5 Radius of the nodes Generate centralized network connections const centralizedConnections Array from length numberOfNodes _ i if i 0 return Array from length numberOfNodes 1 _ j j 1 return 0 Generate decentralized network connections const decentralizedConnections Array from length numberOfNodes for let i 0 i numberOfNodes i const numConnections Math round numberOfNodes 1 connectivityAmount const connectedNodes Array from length numberOfNodes 1 _ j j 1 connectedNodes splice i 1 Remove current node from the list of connected nodes for let j 0 j numConnections j const randomIndex Math floor Math random connectedNodes length decentralizedConnections i push connectedNodes randomIndex connectedNodes splice randomIndex 1 Generate random 2D node locations const nodePositions generateRandomNodePositions numberOfNodes 100 700 100 300 Draw network configurations const drawNetwork connections centralNodeIndex centralNodeColor disconnectedNodeColor const canvas document createElement canvas canvas width 800 canvas height 400 document body appendChild canvas const ctx canvas getContext 2d ctx fillStyle white ctx fillRect 0 0 canvas width canvas height Draw connections for let i 0 i numberOfNodes i const x y nodePositions i for let j 0 j connections i length j const connectionIndex connections i j const x connectedX y connectedY nodePositions connectionIndex ctx beginPath ctx moveTo x y ctx lineTo connectedX connectedY ctx stroke Draw nodes for let i 0 i numberOfNodes i const x y nodePositions i ctx beginPath ctx arc x y nodeRadius 0 2 Math PI if connections i length 0 ctx fillStyle disconnectedNodeColor else if i centralNodeIndex ctx fillStyle centralNodeColor else ctx fillStyle black ctx fill ctx stroke function generateRandomNodePositions numNodes minX maxX minY maxY const positions for let i 0 i numNodes i const x Math floor Math random maxX minX 1 minX const y Math floor Math random maxY minY 1 minY positions push x y return positions drawNetwork centralizedConnections 0 red black drawNetwork decentralizedConnections 1 black orange