Created
June 2, 2017 12:58
-
-
Save Rishav159/5d61dd2205bc452be4c2b85baf464076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let states = []; | |
for(let i = 0; i < 100; i++) { | |
states.push(50); | |
} | |
let peaks = [0,20,40,60,75,85,99]; | |
for(let i = 1; i < peaks.length-1; i++) { | |
peaks[i] += (Math.floor(Math.random()*14 -7)); | |
} | |
for(let i =0; i < peaks.length; i++) { | |
let peak = peaks[i]; | |
states[peak] = Math.floor(Math.random()*(100-5+1) + 5); | |
} | |
for(let i = 0; i < peaks.length-1 ;i++) { | |
let currPeak = peaks[i]; | |
let nextPeak = peaks[i+1]; | |
let currPeakVal = states[currPeak]; | |
let nextPeakVal = states[nextPeak]; | |
let scale = d3.scaleLinear().domain([currPeak,nextPeak]) | |
.range([currPeakVal,nextPeakVal]); | |
for(let j = currPeak; j <= nextPeak; j++) { | |
let scaleValue = Math.floor(scale(j)); | |
states[j] = scaleValue | |
} | |
} | |
return states; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment