fractalkitty looking for math? fractalkitty.com

Mathober 2024

integer partitions

#grid#color#text#interactive#animation#math#number-theory#mathober

bgColgColnGridgSpacefillRectdrawGrid

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

function setup() {
  w = max(500, min(windowWidth, windowHeight) * 0.9);
  describe(
    "Integer partitions from 1 to 5 are shown connected at corners with one ant the top and branching out. The sketch is a blueprint design."
  );
  createCanvas(w, w);
  rectMode(CENTER);
  angleMode(DEGREES);
  textSize(16);
}

function draw() {
  background(bgCol);
  translate(w / 2, w / 2);
  drawGrid();
  t = frameCount / 3;
  stroke(255);
  strokeWeight(1);
  push();
  translate(0, 3 * gSpace);
  fillRect(0, -8 * gSpace, 1);

  fillRect(-1 * gSpace, -7 * gSpace, -1);
  fillRect(-1 * gSpace, -6 * gSpace, -1);
  fillRect(1 * gSpace, -7 * gSpace, -1);
  fillRect(2 * gSpace, -7 * gSpace, -1);

  fillRect(-2 * gSpace, -5 * gSpace, 1);
  fillRect(-3 * gSpace, -5 * gSpace, 1);
  fillRect(-4 * gSpace, -5 * gSpace, 1);
  fillRect(3 * gSpace, -6 * gSpace, 1);
  fillRect(3 * gSpace, -5 * gSpace, 1);
  fillRect(3 * gSpace, -4 * gSpace, 1);
  fillRect(0, -5 * gSpace, 1);
  fillRect(0, -4 * gSpace, 1);
  fillRect(1 * gSpace, -4 * gSpace, 1);

  fillRect(4 * gSpace, -3 * gSpace, -1);
  fillRect(5 * gSpace, -3 * gSpace, -1);
  fillRect(6 * gSpace, -3 * gSpace, -1);
  fillRect(7 * gSpace, -3 * gSpace, -1);
  fillRect(-5 * gSpace, -4 * gSpace, -1);
  fillRect(-5 * gSpace, -3 * gSpace, -1);
  fillRect(-5 * gSpace, -2 * gSpace, -1);
  fillRect(-5 * gSpace, -1 * gSpace, -1);
  fillRect(2 * gSpace, -3 * gSpace, -1);
  fillRect(2 * gSpace, -2 * gSpace, -1);
  fillRect(2 * gSpace, -1 * gSpace, -1);
  fillRect(3 * gSpace, -1 * gSpace, -1);
  fillRect(-7 * gSpace, -7 * gSpace, -1);
  fillRect(-5 * gSpace, -7 * gSpace, -1);
  fillRect(-5 * gSpace, -6 * gSpace, -1);
  fillRect(-6 * gSpace, -7 * gSpace, -1);

  fillRect(-1 * gSpace, -3 * gSpace, -1);
  fillRect(-2 * gSpace, -3 * gSpace, -1);
  fillRect(-1 * gSpace, -2 * gSpace, -1);
  fillRect(-2 * gSpace, -2 * gSpace, -1);

  fillRect(8 * gSpace, -8 * gSpace, 1);
  fillRect(8 * gSpace, -7 * gSpace, 1);
  fillRect(8 * gSpace, -6 * gSpace, 1);
  fillRect(8 * gSpace, -5 * gSpace, 1);
  fillRect(8 * gSpace, -4 * gSpace, 1);
  fillRect(8 * gSpace, -2 * gSpace, 1);
  fillRect(8 * gSpace, -1 * gSpace, 1);
  fillRect(8 * gSpace, 0 * gSpace, 1);
  fillRect(8 * gSpace, 1 * gSpace, 1);
  fillRect(7 * gSpace, 1 * gSpace, 1);
  fillRect(4 * gSpace, 0 * gSpace, 1);
  fillRect(4 * gSpace, 1 * gSpace, 1);
  fillRect(4 * gSpace, 2 * gSpace, 1);
  fillRect(4 * gSpace, 3 * gSpace, 1);
  fillRect(5 * gSpace, 3 * gSpace, 1);
  fillRect(-8 * gSpace, -6 * gSpace, 1);
  fillRect(-8 * gSpace, -5 * gSpace, 1);
  fillRect(-8 * gSpace, -4 * gSpace, 1);
  fillRect(-8 * gSpace, -3 * gSpace, 1);
  fillRect(-8 * gSpace, -2 * gSpace, 1);
  fillRect(-8 * gSpace, 2 * gSpace, 1);
  fillRect(-7 * gSpace, 2 * gSpace, 1);
  fillRect(-6 * gSpace, 2 * gSpace, 1);
  fillRect(-6 * gSpace, 1 * gSpace, 1);
  fillRect(-6 * gSpace, 0 * gSpace, 1);
  fillRect(-3 * gSpace, -1 * gSpace, 1);
  fillRect(-3 * gSpace, 0 * gSpace, 1);
  fillRect(-3 * gSpace, 1 * gSpace, 1);
  fillRect(-4 * gSpace, 1 * gSpace, 1);
  fillRect(-4 * gSpace, 0 * gSpace, 1);
  fillRect(0 * gSpace, -1 * gSpace, 1);
  fillRect(0 * gSpace, 0 * gSpace, 1);
  fillRect(0 * gSpace, 1 * gSpace, 1);
  fillRect(1 * gSpace, 1 * gSpace, 1);
  fillRect(1 * gSpace, 0 * gSpace, 1);

  pop();

  noStroke();
  fill(gCol);
  text("integer partitions", -w / 2 + 10, w / 2 - 10);
}

function fillRect(x, y, s) {
  push();
  translate(x, y);
  stroke(gCol);
  strokeWeight(2);
  if (s === 1) {
    scale(1, 1);
  } else {
    scale(1, -1);
  }
  for (let i = 0; i <= 6; i++) {
    line(
      -gSpace / 2 + (gSpace / 6) * i,
      -gSpace / 2,
      -gSpace / 2,
      -gSpace / 2 + (gSpace / 6) * i
    );
    line(
      gSpace / 2 - (gSpace / 6) * i,
      gSpace / 2,
      gSpace / 2,
      gSpace / 2 - (gSpace / 6) * i
    );
  }
  pop();
}

function drawGrid() {
  gSpace = (w / nGrid) * 0.95;
  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);
}

function mousePressed() {
  setup();
  draw();
}
function windowResized() {
  setup();
  draw();
}