fractalkitty looking for math? fractalkitty.com

Coded Poems

theIntuition

#random#trig#poem#math

drop a needle does it cross the circle?

whatIsChosenwhatExiststheIntuitiontheNegativeSpacetheDiameterOfSighttheExperimenttheSpaceBetweentoTreadLightlyneedleaMemorystring1

let whatIsChosen = 0;
let whatExists = 0;
let theIntuition = 0;
let theNegativeSpace;
let theDiameterOfSight;
let theExperiment;
let theSpaceBetween;
function setup() {
  theNegativeSpace = createCanvas(
    (c = max(600, min(windowWidth, windowHeight))),
    c
  );
  theDiameterOfSight = width;
  theExperiment = theDiameterOfSight / 5;
  theSpaceBetween = theDiameterOfSight / 10;
  toTreadLightly();
  function toTreadLightly() {
    noFill();
    strokeWeight(0.01);
    pixelDensity(20);
  }
}
function draw() {
  translate(width / 2, height / 2);
  for (let i = 0; i < c * 2; i++) {
    needle();
  }
  theIntuition = whatIsChosen / whatExists;
  if (whatExists > 5999999) {
    noLoop();
  }
}
function needle() {
  whatExists++;
  thefirstTouchDist = random(0, width / 2);
  theFirstTouchAngle = random(0, PI * 2);
  theFirstTouchAcross = thefirstTouchDist * cos(theFirstTouchAngle);
  theFirstTouchVertical = thefirstTouchDist * sin(theFirstTouchAngle);
  theta = random(0, 2 * PI);
  theLastTouchAcross = theFirstTouchAcross + theExperiment * cos(theta);
  y2 = theFirstTouchVertical + theExperiment * sin(theta);

  cond1 =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <= theSpaceBetween;
  cond2 = dist(theLastTouchAcross, y2, 0, 0) <= theSpaceBetween;
  cond1b =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <=
    2 * theSpaceBetween;
  cond2b = dist(theLastTouchAcross, y2, 0, 0) <= 2 * theSpaceBetween;
  cond1c =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <=
    3 * theSpaceBetween;
  cond2c = dist(theLastTouchAcross, y2, 0, 0) <= 3 * theSpaceBetween;
  cond1d =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <=
    4 * theSpaceBetween;
  cond2d = dist(theLastTouchAcross, y2, 0, 0) <= 4 * theSpaceBetween;
  cond1e =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <=
    5 * theSpaceBetween;
  cond2e = dist(theLastTouchAcross, y2, 0, 0) <= 5 * theSpaceBetween;
  cond1f =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <=
    6 * theSpaceBetween;
  cond2f = dist(theLastTouchAcross, y2, 0, 0) <= 6 * theSpaceBetween;
  cond1g =
    dist(theFirstTouchAcross, theFirstTouchVertical, 0, 0) <=
    7 * theSpaceBetween;
  cond2g = dist(theLastTouchAcross, y2, 0, 0) <= 7 * theSpaceBetween;

  if (
    (cond1 && !cond2) ||
    (cond2 && !cond1) ||
    (cond1b && !cond2b) ||
    (cond2b && !cond1b) ||
    (cond1c && !cond2c) ||
    (cond2c && !cond1c) ||
    (cond1d && !cond2d) ||
    (cond2d && !cond1d) ||
    (cond1e && !cond2e) ||
    (cond2e && !cond1e) ||
    (cond1f && !cond2f) ||
    (cond2f && !cond1f) ||
    (cond1g && !cond2g) ||
    (cond2g && !cond1g)
  ) {
    whatIsChosen++;
    stroke(random(150, 255), random(220, 255), 255);
  } else {
    stroke(10);
  }
  line(theFirstTouchAcross, theFirstTouchVertical, theLastTouchAcross, y2);
}

function aMemory() {
  let string1 = str(theIntuition);
  save(theNegativeSpace, string1, "png");
}