File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ .vscode /
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < body >
4+
5+ < table border ="0 " cellpadding ="0 " cellspacing ="0 " spacing ="0 " padding ="0 ">
6+ < tr >
7+ < td bgcolor ="#FF0000 " width ="1 " height ="1 "> </ td >
8+ < td bgcolor ="#FF0000 " width ="1 " height ="1 "> </ td >
9+ </ tr >
10+ < tr >
11+ < td bgcolor ="#FF0000 " width ="1 " height ="1 "> </ td >
12+ < td bgcolor ="#FF0000 " width ="1 " height ="1 "> </ td >
13+ </ tr >
14+ </ table >
15+
16+ </ body >
17+ </ html >
Original file line number Diff line number Diff line change 1+ // @ts -check
2+
3+ /**
4+ * @typedef {[number,number,number] } vec3
5+ *
6+ */
7+
8+ /**
9+ * @type {vec3 }
10+ */
11+ const red = [ 255 , 0 , 0 ] ;
12+
13+ /**
14+ * @type {vec3[][] }
15+ */
16+ const color_grid = [ [ red ] ] ;
17+
18+
19+ /**
20+ *
21+ * @param {vec3 } color
22+ * @returns {string }
23+ */
24+ function to_hexcode ( color ) {
25+ let output = "" ;
26+ for ( const component of color ) {
27+ output += component . toString ( 16 ) ;
28+ }
29+ return output ;
30+ }
31+
32+ /**
33+ *
34+ * @param {vec3[][] } grid
35+ *
36+ */
37+ function normalize_grid_size ( grid ) {
38+ let line_size = 0 ;
39+ for ( const line of grid ) {
40+ line_size = Math . max ( line . length ) ;
41+ }
42+ for ( let line of grid ) {
43+ if ( line . length == line_size ) continue ;
44+ const dif = line_size - line . length ;
45+ for ( let i = 0 ; i < dif ; ++ i ) {
46+ line . push ( [ 0 , 0 , 0 ] ) ;
47+ }
48+ }
49+ }
50+
51+ /**
52+ * @param {vec3[][] } color_grid
53+ * @returns {string }
54+ */
55+ export function build_color_grid ( color_grid ) {
56+ normalize_grid_size ( color_grid ) ;
57+ let html = '<table border="0" cellpadding="0" cellspacing="0" spacing="0" padding="0">' ;
58+ for ( const row of color_grid ) {
59+ html += "<tr>" ;
60+ for ( const color of row ) {
61+ html += '<td bgcolor="' + to_hexcode ( color ) + '"width="1" height="1"></td>' ;
62+ }
63+ html += "</tr>" ;
64+ }
65+ return html ;
66+ }
67+
You can’t perform that action at this time.
0 commit comments