x^2+y^2
palindrome result of x^2+y^2unknown
html
3 years ago
1.1 kB
9
Indexable
<html> <body> <canvas id="myCanvas" width="501" height="501" style="border:1px solid #000000;"> </canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); //applico lo sfondo nero ctx.fillStyle = 'black'; ctx.fillRect(0,0, c.width, c.height); //da qui in avanto metto pixel bianchi ctx.fillStyle = 'white'; //il valore di x e y più basso var start = -250; for (var x=start; x<Math.abs(start); x++) { for (var y=start; y<Math.abs(start); y++) { var asd = (Math.pow(x,2) + Math.pow(y,2)).toString(); //qui giro il risultato per poi vedere se il numero è palindromo var reverse = ""; for (var i=asd.length-1; i>=0; i--) reverse += asd[i]; if (asd === reverse){ ctx.fillRect(x+Math.abs(start), y+Math.abs(start), 1, 1); } } } </script> </body> </html>
Editor is loading...