Public
Edited
Jul 9, 2023
1 fork
1 star
Insert cell
Insert cell
georgette = { // Fractal pine trees on a mountain lake
const col_top = ['#000','#f60','#cff','#f6f','#f0f','#060','#099','#f33','#aef','#3c0'];
const col_down = ['#000','#333','#666','#f0f','#000','#930','#c63','#000','#f00','#c00'];
const u = 7; // unit
const wu = 500; // no. units on width
const hu = 100; // no. units on height
const width = wu*u*2; // double the units to have spaces between squares
const height = hu*u*2; // double the units to have bottom & top piangles
const margin = 2*20;
const board_height = height; //1000*5.5;
const board_width = width; //1414*5.5;
let data_top, data_down, new_top, new_down, r, l, x, y, digit_top, digit_down;
let ray = 0.7;
let trans_x = (board_width - width)/2;
let trans_y = (board_height - height)/2;
// Background
const { canvas, context } = createCanvas();
const pixelRatio = resize(canvas, board_width + 2*margin, board_height + 2*margin, );
context.globalAlpha = 1;
context.scale(pixelRatio, pixelRatio);
context.fillStyle = '#fff';
context.fillRect(0, 0, board_width+2*margin, board_height+2*margin);
///////////////// 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; ++w) {
if(w < h){
new_top = 0;
new_down = 0;
} else {
r = data_top[h-1][w];
l = data_top[h-1][w-1];
new_top = alg_top(l, r);
r = data_down[h-1][w];
l = data_down[h-1][w-1];
new_down = alg_top(l, r);
}
data_top[h][w] = new_top;
data_down[h][w] = new_down;
}
}

//////////////////// DRAW ////////////////
for (let h = 0; h < hu; ++h){
for (let w = 0; w < wu; ++w) {
///// TOP
context.globalAlpha = 1;
digit_top = data_top[h][w];
if(digit_top != 0){
x = u*w*2 - h*u + margin/2 + trans_x;
y = (hu-h)*u + margin/2 + trans_y;
context.fillStyle = col_top[digit_top];
context.fillRect(x, y, u, u);
}
///// DOWN
context.globalAlpha = 0.4;
digit_down = data_down[h][w];
if(digit_down != 0 & h != 0){
x = u*w*2 - h*u + margin/2 + trans_x;
y = h*u + margin/2 + hu*u + trans_y;
context.fillStyle = col_down[digit_down];
context.fillRect(x, y, u, u);
}
}
}
return canvas;
}
Insert cell
alg_top = (l, r) => {
let power = 3;
let thres = 10;
let modulo = 10;
let new_d = (r**power)%modulo + (l**power)%modulo;
new_d = Math.min( new_d, thres);
return new_d % modulo;
}
Insert cell
alg_down = (l, r) => {
let thres = 10;
let modulo = 10;
return Math.min(l + r, thres)%modulo;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
get_pi_txt(10)
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