fractalkitty looking for math? fractalkitty.com

Mathober 2024

modulo

#trig#grid#color#text#math#geometry#number-theory#polar#mathober

bgColgColnGridgSpacepisanoPeriodsequencedrawGrid


const bgCol = "#447abd";
const gCol = "#a2c2e8";
const nGrid = 20;
let w;
let gSpace;

function setup() {
  w = max(400, min(windowWidth, windowHeight) * 0.9);
  gSpace = (w / nGrid) * 0.95;
  describe(
    "the pisano periods shown as a shell where each degree is the modulo dividing the fibonacci sequence with dots drawn at a radius of the remainder - on a blueprint design"
  );
  createCanvas(w, w);
  rectMode(CENTER);

  d = w;
  angleMode(DEGREES);
  textSize(16);
  m = 7;
  s = [];
  s = pisanoPeriod(m);
  g = (w - 2 * gSpace) / 2 / 300;
}

function draw() {
  background(bgCol);
  translate(w / 2, w / 2);
  drawGrid();
  t = frameCount / 3;
  noStroke();
  fill(255);
  for (let i = 1; i < 390; i++) {
    let s = [];
    s = pisanoPeriod(i);
    for (let k = 0; k < s.length; k++) {
      circle(-w / 9 + g * s[k] * cos(i), w / 9 + g * s[k] * sin(i), 1);
    }
  }
  fill(255, 255, 255, 20);
  noStroke();
  fill(gCol);
  text("modulo", -w / 2 + 10, w / 2 - 5);
  noLoop();
}

function pisanoPeriod(m) {
  if (m <= 0) return [];
  if (m === 1) return [0];

  let sequence = [];
  let a = 0;
  let b = 1;

  do {
    sequence.push(a);
    let c = (a + b) % m;
    a = b;
    b = c;
  } while (!(a === 0 && b === 1) || sequence.length < 2);

  return sequence;
}

function drawGrid() {
  stroke(gCol);
  strokeWeight(0.3);
  for (let i = 1; i <= nGrid; i++) {
    for (let j = 1; j <= nGrid; j++) {
      line(
        -w / 2 + gSpace * i,
        -w / 2 + gSpace,
        -w / 2 + gSpace * i,
        w / 2 - gSpace
      );
      line(
        -w / 2 + gSpace,
        -w / 2 + gSpace * i,
        w / 2 - gSpace,
        -w / 2 + gSpace * i
      );
    }
  }
  noFill();
  strokeWeight(3);
  rect(0, 0, w - 2 * gSpace);
}