D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
NelsonMinar
Full window
Github gist
Cantor pairing function
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <title>Cantor pairing function</title> <style> td { min-width: 2em; text-align: right; } </style> </head> <body> <p>Mapping tuples (n, m) to the integers, see <a href="https://en.wikipedia.org/wiki/Cantor_pairing_function#Cantor_pairing_function">Cantor pairing function</a>. <table id="cantor"></table> <script> function f(x, y) { return ((x + y) * (x + y + 1)) / 2 + y; } for (var y = 0; y < 100; y++) { var line = ['<tr>']; for (var x = 0; x < 30; x++) { line.push("<td>" + f(y, x) + "</td>"); } line.push("</tr>") $("#cantor").append(line.join('')); } </script> </body> </html>
https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js