Public
Edited
Aug 1, 2024
Insert cell
Insert cell
pi_41 = {
let col_down = ['#003','#fff','#cdf','#f0f','#c9c','#0ff','#ff0','#0f0','#666','#333'];
let col_top = ['#003','#fff','#cdf','#0c0','#666','#f96','#000','#f00','#ff6','#f60'];
col_top = col_down = ['#0fe',
'#000', //
'#f00',
'#afb', ////
'#9f9',
'#3a3',
'#900', //
'#ff0',
'#fdd', ////
'#0da'];
const u = 0.1; // unit
const wu = 6000; //1934; // no. units on width // 1000 is good!
const hu = 6000; //1934; // no. units on height
const margin = 20;
const board_height = hu*u + 2*margin;
const board_width = wu*u + 2*margin;
let data_top, data_down, new_top, new_down, r, l, x, y, digit_top, digit_down;
// Background
const { canvas, context } = createCanvas(board_width, board_height);
const pixelRatio = resize(canvas, board_width, board_height, );
context.scale(pixelRatio, pixelRatio);
context.globalAlpha = 1;
context.fillStyle = '#fff';
context.fillRect(0, 0, board_height, board_width);
///////////////// DATA /////////////////
const base = get_pi_txt(wu+1);
data_top = [[]];
data_down = [[]];
data_top[0] = base;
data_down[0] = base;

for (let h = 1; h < hu; ++h){
data_top[h] = [];
data_down[h] = [];
for (let w = 0; w < wu-h; ++w) {
l = data_top[h-1][w];
r = data_top[h-1][w+1];
if(w < h){
new_top = 0;
} else {
new_top = algo(l, r);
}
new_top = algo(l, r);
//l = data_down[h-1][w];
//r = data_down[h-1][w+1];
//new_down = algo(l, r, 10);
data_top[h][w] = new_top;
data_down[h][w] = new_top;
}
}
//////////////////// DRAW ////////////////
for (let h = 0; h < hu; ++h){
for (let w = 0; w < wu-h; ++w) {
///// TOP
digit_top = data_top[h][w];
x = w*u + margin;
y = w*u + h*u + margin;
context.fillStyle = col_top[digit_top];
context.fillRect(x, y, u, u);
///// DOWN
if(h!=0){
digit_down = data_down[h][w];
x = w*u + h*u + margin;
y = w*u + margin;
context.fillStyle = col_down[digit_down];
context.fillRect(x, y, u, u);
}
}
}
return canvas;
}
Insert cell
algo = (l, r) => {
return ((l**2 + r**2) % 10);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
get_pi_txt(10)
Insert cell
12%1
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