Published
Edited
Oct 3, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataP2 = FileAttachment("message.csv").csv({typed: true})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataP3 = FileAttachment("message.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
part4 = FileAttachment("calmcode-part4").text()
Insert cell
words = part4.split(",").map(d => ({word: d, length: d.length}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// from https://observablehq.com/@amitkaps/image-pixel-render-with-vega-lite
imageData = {
// Get a reference to the image you want the pixels of and its dimensions
const w = image.width;
const h = image.height;
// Create a Canvas element
let canvas = document.createElement('canvas');
// Size the canvas to the element
canvas.width = w;
canvas.height = h;

// Draw image onto the canvas
let ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);

// Finally, get the image data as a Uint8ClampedArray
// ('data' is an array of RGBA pixel values for each pixel)
const raw = ctx.getImageData(0, 0, w, h);
// Let us get a normal array back to maniputate
const flatArray = Array.from(raw.data)
return flatArray;
}
Insert cell
dataP5 = _.chunk(imageData, 4).map((d,i) => ({
x: i % image.width,
y: Math.floor(i / image.width),
r: d[0],
g: d[1],
b: d[2],
a: d[3]
}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
replacements = ({
l: "a", a: "l",
e: "i", i: "e",
k: "s", s: "k",
y: "t", t: "y",
w: "o", o: "w",
f: "h", h: "f",
u: "r", r: "u",
m: "z", z: "m",
x: "n", n: "x",
b: "c", c: "b",
q: "p", p: "q",
j: "d", d: "j",
g: "g",
v: "v"
})
Insert cell
decoded = toggleP6 ? letters.split("").map(l => {
if (Object.keys(replacements).includes(l)) {
return replacements[l]
} else if (l.match(/[a-z]/g)) {
return "-"
} else {
return l
}
}).join("") : "decoded"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// toolbox()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more