Skip to content

Instantly share code, notes, and snippets.

@duskvirkus
Created July 2, 2019 00:40
Show Gist options
  • Save duskvirkus/4be54c23e5bad13c436d4c3ca230ff3e to your computer and use it in GitHub Desktop.
Save duskvirkus/4be54c23e5bad13c436d4c3ca230ff3e to your computer and use it in GitHub Desktop.
// Inital Truth Table Values
// By Fi Graham
// p5js sketch (editor.p5js.org)
// Sketch figuring out inital boolean values of a truth table.
function setup() {
createCanvas(windowWidth, windowHeight);
stroke(127);
}
function draw() {
background(220);
let cols = int(map(mouseX, 0, width, 1, 10));
let rows = pow(2, cols);
let colSize = width / cols;
let rowSize = height / rows;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
if ((row % (rows / pow(2, col))) < (pow(2, cols - (col + 1)))) { // true
fill(0);
} else { // false
fill(255);
}
rect(col * colSize, row * rowSize, colSize, rowSize);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment