/* ------------------ */ /* index.js */ /* ------------------ */ // STATE var stateRing = {} var widthPct = '80%' //'100%' // 640 // var heightPct = '80%' // '100%' // 480 // var animationStep = 500; var centerx = widthPct / 2 var centery = heightPct / 2 var moving = 1 var mousePosition = [] // RENDER var svgContainer = d3.select("body").selectAll('svg').data(['svg']) var svgElement = svgContainer.enter().append("svg").attr("id", "svg").attr("class", "svg").call(drawSvg) // relative per one factors var hpct = parseInt(svgElement.style("width"), 10) / 100 var vpct = parseInt(svgElement.style("height"), 10) / 100 var mpct = hpct + vpct / 2 // rel to abs coordinantes var xa = function xa (d) { return d * hpct } var ya = function ya (d) { return d * vpct } var ma = function ma (d) { return d * mpct } // abs coordinantes var width = parseInt(svgElement.style("width"), 10) var height = parseInt(svgElement.style("height"), 10) stateRing.radiusMax = 0 stateRing.radiusMin = 0 stateRing.color = d3.interpolatePlasma // console.log(color(3)) // 256 // color( ((3*r)%10 / 10) + (Math.random()* 3 /10)) // ==================================================================== simulationRolls drawLanesDiagram() var simulationRolls = d3.forceSimulation() .alpha(1) // tick increments the current alpha by (alphaTarget - alpha) � alphaDecay // tick then invokes each registered force, passing the new alpha // tick decrements each node�s velocity by velocity � velocityDecay // tick increments each node�s position by velocity .alphaMin(0.001) // (0.001) .alphaDecay(0.000228) // (0.0228) .alphaTarget(0) .velocityDecay(0.000) // (0.4) // each node�s velocity is multiplied by 1 - decay simulationRolls .nodes(nodes) // .force("link", d3.forceLink().id(function(d) { return d.index; })) // .force("charge", d3.forceManyBody().strength(-20)) // positive: attraction .force("charge", d3.forceManyBody().strength(function(d) { return d.charge })) // positive: attraction .force("collide", d3.forceCollide(function(d) {return 2 * d.r}).iterations(4)) // // .force("center", d3.forceCenter(50, 50)) // simulationRolls .force("link") // .links(links).strength(0) // .iterations(1).distance(5) drawLanesSimulation() // ==================================================================== voro sites // ==================================================================== voro sites // var voro = d3.voronoi().extent([[nodes[0].x, 1], [nodes[0].y, height - 1]]) var voro // voronoi var dia // voronoi diagram var polygons // polygons on dia sites var rings // circumscribed circles in polygons var extent = [] // extend of diagram var seedsArea = {} // {x0, y0, x1, y1} area where the seeds are located var n = 100, // number of sites seeds = new Array(n), // also seeds or generators) color = "blue", // color of the ... radius = 10 // radius of the ... seedsArea = {x0: nodes[0].x, y0: 0, x1:nodes[1].x, y1: 100} extent = [[seedsArea.x0 + 1, seedsArea.y0 + 1], [seedsArea.x1 + 1 , seedsArea.y1 - 1]] voro = d3.voronoi().extent(extent) seeds = getSeeds(seedsArea.x0, seedsArea.y0, seedsArea.x1, seedsArea.y1, 0, 0) // get seeds {x, y, vx, vy} // in data for simulation dia = voro(seeds.map(function(d) {return [d.x, d.y]})) // pass an array of coordinates [[,], [,]] polygons = dia.triangles() rings = polygons.map(function(d) {return inscribeTriangle(d[0][0], d[0][1],d[1][0], d[1][1],d[2][0], d[2][1])}) drawVoroDiagam() var simulationVoro = d3.forceSimulation() .alpha(1) // tick increments the current alpha by (alphaTarget - alpha) � alphaDecay // tick then invokes each registered force, passing the new alpha // tick decrements each node�s velocity by velocity � velocityDecay // tick increments each node�s position by velocity .alphaMin(0.001) // (0.001) .alphaDecay(0.000228) // (0.0228) .alphaTarget(0) .velocityDecay(0.000) // (0.4) // each node�s velocity is multiplied by 1 - decay // .initialize() simulationVoro .nodes(seeds) .force("link", d3.forceLink().id(function(d) { return d.index; })) // .force("charge", d3.forceManyBody().strength(-5)) // positive: attraction // .force("charge", d3.forceManyBody().strength(function(d) { return d.charge })) // positive: attraction .force("collide", d3.forceCollide(function(d) {return 2 * d.r}).iterations(4)) // // .force("center", d3.forceCenter(50, 50)) // simulationVoro .force("link") // .links(links).strength(0.5).iterations(1).distance(15) drawVoroSimulation()