diff --git a/colours.js b/colours.js index f08e3f6..225a3b5 100644 --- a/colours.js +++ b/colours.js @@ -2,6 +2,13 @@ import ColorScheme from 'color-scheme'; import Color from 'color'; export const get_colours = (basis) => { + const colours = get_colours_spectrum(basis); + console.log(colours); + return colours; +} + + +const get_colours_tetrade = (basis) => { const basis_c = Color(basis); const hslb = basis_c.hsl(); const hue = hslb['color'][0]; @@ -10,13 +17,29 @@ export const get_colours = (basis) => { const scheme = new ColorScheme; scheme.from_hue(hue).scheme("tetrade").distance(0.75); const colours = scheme.colors(); - colours.reverse(); + //colours.reverse(); const hsl = colours.map((c) => Color("#" + c).hsl()); const resaturated = hsl.map((hslc) => hslc.saturationl(saturation).rgbNumber()); resaturated.unshift(basis); return resaturated; } + +const get_colours_spectrum = (basis) => { + const basis_c = Color(basis); + const hslb = basis_c.hsl(); + const hue = hslb['color'][0]; + const saturation = hslb['color'][1]; + const luminance = hslb['color'][2]; + const SPECTRUM = 10; + const hsl = []; + for( let i = 0; i < SPECTRUM; i++ ) { + const h = (hue + i * 360 / SPECTRUM) % 360; + hsl.push(Color.hsl(h, saturation, luminance)); + } + return hsl.map((hslc) => hslc.rgbNumber()); +} + // basic colours where 0 = blue // 1 - dark blue // 2 - white diff --git a/polytopes.js b/polytopes.js index 4af268d..1defa51 100644 --- a/polytopes.js +++ b/polytopes.js @@ -89,16 +89,16 @@ export const cell5 = () => { {id:5, label: 5, x: 0, y: 0, z: 0, w: 1 }, ], links: [ - { id:1, source:1, target: 2}, - { id:2, source:1, target: 3}, - { id:3, source:1, target: 4}, - { id:4, source:1, target: 5}, - { id:5, source:2, target: 3}, - { id:6, source:2, target: 4}, - { id:7, source:2, target: 5}, - { id:8, source:3, target: 4}, - { id:9, source:3, target: 5}, - { id:10, source:4, target: 5}, + { id:1, source:1, target: 2, label:0}, + { id:2, source:1, target: 3, label:0}, + { id:3, source:1, target: 4, label:0}, + { id:4, source:1, target: 5, label:0}, + { id:5, source:2, target: 3, label:0}, + { id:6, source:2, target: 4, label:0}, + { id:7, source:2, target: 5, label:0}, + { id:8, source:3, target: 4, label:0}, + { id:9, source:3, target: 5, label:0}, + { id:10, source:4, target: 5, label:0}, ], options: [ { name: '--' }], description: `Five tetrahedra joined at ten faces with three @@ -126,6 +126,7 @@ export const cell16 = () => { index_nodes(nodes); scale_nodes(nodes, 0.5); const links = auto_detect_edges(nodes, 6); + links.map((l) => l.label = 0); return { name: '16-cell', @@ -513,29 +514,41 @@ export const cell120_inscribed_cell5 = () => { const nodes = make_120cell_vertices(); const links = auto_detect_edges(nodes, 4); + for( const cstr in CELLINDEX.INDEX120 ) { + label_nodes(nodes, CELLINDEX.INDEX120[cstr], Number(cstr)); + } + links.map((l) => l.label = 0); const CELL5S = CELLINDEX.CELL120_CELL5; + const nodesc5s = []; + const linksc5s = []; + const nids = []; + for( const c5 in CELL5S ) { - const nodes5 = nodes.filter((n) => CELL5S[c5].nodes.includes(n.id)); - const links5 = auto_detect_edges(nodes5, 5); - links5.map((l) => l.label = CELL5S[c5].label); - links.push(...links5); - nodes5.map((n) => n.label = CELL5S[c5].label); + if( CELL5S[c5].label === 3 ) { + const nodes5 = nodes.filter((n) => CELL5S[c5].nodes.includes(n.id)); + const links5 = auto_detect_edges(nodes5, 5); + links5.map((l) => l.label = CELL5S[c5].label); + linksc5s.push(...links5); + nodesc5s.push(...nodes5); + nids.push(...nodes5.map((n) => n.id)); + } } + const links120 = links.filter((l) => nids.includes(l.source) && nids.includes(l.target)); return { name: '120-cell with 5-cells', - nodes: nodes, - links: links, + nodes: nodesc5s, + links: [...linksc5s, ...links120], options: [ - { name: "all", links: [0, 1, 2, 3, 4, 5] }, - { name: "24", links: [0, 1 ] }, - { name: "48", links: [0, 1, 2 ] }, - { name: "72", links: [0, 1, 2, 3 ] }, +// { name: "all", links: [0, 1, 2, 3, 4, 5] }, + { name: "24", links: [0, 3 ] }, +// { name: "48", links: [0, 1, 2 ] }, +// { name: "72", links: [0, 1, 2, 3 ] }, { name: "96", links: [0, 1, 2, 3, 4 ] }, - { name: "hide 1200-cell", links: [ 1, 2, 3, 4, 5 ] }, +// { name: "hide 1200-cell", links: [ 1, 2, 3, 4, 5 ] }, ], description: `The vertices of the 120-cell can also be partitioned into 120 5-cells: each 5-cell has one vertex in each of the five @@ -946,12 +959,12 @@ export const tetrahedron = () => { {id:4, label: 4, x: 0, y: 0, z: 1, w: 0 }, ], links: [ - { id:1, source:1, target: 2}, - { id:2, source:1, target: 3}, - { id:3, source:1, target: 4}, - { id:4, source:2, target: 3}, - { id:5, source:2, target: 4}, - { id:6, source:3, target: 4}, + { id:1, source:1, target: 2, label: 0}, + { id:2, source:1, target: 3, label: 0}, + { id:3, source:1, target: 4, label: 0}, + { id:4, source:2, target: 3, label: 0}, + { id:5, source:2, target: 4, label: 0}, + { id:6, source:3, target: 4, label: 0}, ], options: [ { name: '--' }], description: `The simplest three-dimensional polytope, consisting of four triangles joined at six edges. The 5-cell is its four-dimensional analogue.`, @@ -1081,6 +1094,15 @@ export const build_all = () => { ]; } +export const count_labels = (shape) => { + const labels = {}; + shape.nodes.map((n) => labels[n.label] = true); + shape.links.map((n) => labels[n.label] = true); + return Object.keys(labels); +}; + export const radii = (shape) => { return shape.nodes.map(n => Math.sqrt(n.x * n.x + n.y * n.y + n.z * n.z + n.w * n.w)) } + +