// Consecutive Calculations // Shows graph of consecutive numbers // from serial stream stream of 1s and 0s. // Real random numbers are black, on top. // Pseudo random numbers are red on bottom. // John Clavin - August 8, 2017 var qArray = []; var pArray = []; var qyArray = []; var pyArray = []; var qxyIndex; var pxyIndex; var real_string; var sWidth; var loopCount; var restartFlag; function preload() { // Load 2MB Real Random File real_string = loadStrings("realrand2mb.txt"); } function setup() { createCanvas(1840, 600); noStroke(); background(220); loopCount = 0; qxyIndex = 0; pxyIndex = 0; sWidth = 3800; restartFlag = false; for (var aq = 0; aq < 2000000; aq++) { // Create Real Random Array qArray[aq] = parseInt(real_string[0].substr(aq, 1), 10); } for (var ap = 0; ap < 2000000; ap++) { pArray[ap] = int(random(2)); // Create Pseudo Random Array } qyArray = calculate_consecutive(qArray); pyArray = calculate_consecutive(pArray); } function draw() { strokeWeight(1); fill(20); stroke(20); if(qyArray[qxyIndex] === 0) { point(qxyIndex, height/2.1); } else { line(qxyIndex, height/2.1, qxyIndex, (height/2.1 - (qyArray[qxyIndex] * 20))); } qxyIndex++; fill(210, 0, 0); stroke(210, 0, 0); if(pyArray[pxyIndex] === 0) { point(pxyIndex, height/1.1); } else { line(pxyIndex, height/1.1, pxyIndex, (height/1.1 - (pyArray[pxyIndex] * 20))); } pxyIndex++; if (loopCount < 1900) { loopCount++; } else { restartFlag = true; noLoop(); } } function mousePressed() { if(restartFlag === true) { background(220); loopCount = 0; qxyIndex = 0; pxyIndex = 0; qyArray = calculate_consecutive(qArray); pyArray = calculate_consecutive(pArray); restartFlag = false; loop(); } return false; } function calculate_consecutive(riverOfLife) { var rArray = riverOfLife; var displayArray = []; var displayIndex = 0; var displayAmount; var temp1; var temp2; var rndIndex = int(random(1996000)); var conIndex = rndIndex; while(conIndex < (sWidth + rndIndex)) { displayAmount = 0; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; if(temp1 == temp2) { displayAmount += 1; temp1 = rArray[conIndex]; conIndex++; temp2 = rArray[conIndex]; } } } } } } } } } } } } displayArray[displayIndex] = displayAmount; displayIndex++; } return displayArray; }