Public
Edited
Feb 27
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sampleColor = function (i) {
let r =
red.offset +
red.amplitude * Math.sin((red.frequency / 8) * i + red.phase * Math.PI * 2);
let g =
green.offset +
green.amplitude *
Math.sin((green.frequency / 8) * i + green.phase * Math.PI * 2);
let b =
blue.offset +
blue.amplitude *
Math.sin((blue.frequency / 8) * i + blue.phase * Math.PI * 2);

return [
clamp(Math.round(r * 255) & ~0b111, 0, 255),
clamp(Math.round(g * 255) & ~0b11, 0, 255),
clamp(Math.round(b * 255) & ~0b111, 0, 255)
];
}
Insert cell
241 & ~0b111
Insert cell
rgbToHex([255, 200, 0])
Insert cell
Insert cell
Insert cell
swatch565 = function (x, y) {
let red = Math.floor(x / 32) + Math.floor(y / 64) * 8;
let blue = Math.floor(x) % 32;
let green = Math.floor(y) % 64;
return rgbToHex([red * 8, green * 4, blue * 8]);
}
Insert cell
from565toXY = function (arr) {
let r = arr[0];
let g = arr[1];
let b = arr[2];

let x = r + b;
let y = r + g;
return [x, y];
}
Insert cell
viewof redtest = Inputs.range([0, 255], { label: "Y", step: 1 })
Insert cell
getX = function (n) {
return (Math.floor(n / 8) % 8) * 32;
// return Math.floor(n / 64) * 64;
}
Insert cell
getY = function (n) {
// return (Math.floor(n / 32) % 8) * 32;
return Math.floor(n / 64) * 64;
}
Insert cell
[getX(redtest), getY(redtest)]
Insert cell
canvas1 = {
const context = DOM.context2d(width, 200);
context.fillStyle = swatch565(128, redtest);
context.fillRect(0, 0, width, 200);
return context.canvas;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more