xxxxxxxxxx
38
const checkboxes = []
let textArea = null
setup = () => {
createCanvas(w = 200, w)
textArea = createInput('').position(5 + w, 130)
for (let y = 0; y < 8; y++) {
for (let x = 0; x < 8; x++) {
checkboxes.push(createCheckbox().position(x * 15 + w, y * 15).changed(onCheck))
}
}
}
draw = () => {
background(255)
fill(0)
noStroke()
const S = 20
const str = textArea.value()
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
str.charCodeAt(i) & 1 << j && rect(j * S+S, i * S+S, S);
}
}
}
onCheck = e => {
let chars = checkboxes.map(c => c.checked() ? 1 : 0)
let str = ""
while (chars.length > 0) {
let oct = chars.splice(0, 8)
oct.push(1)
oct = oct.reverse().join("")
const num = parseInt(oct, 2)
str += char(num)
}
textArea.value(str)
}