I made an algorithm for creating circles, but for some reason the pixels start skipping in the middle. Here's the code:
I've been working on this for a week now, and I still don't understand why it's "skipping". It's hard to say what I mean by "skipping", but if you test the code I think you'll understand.Code:<html> <head> <script type="text/javascript"> function draw(x,y) { var div = document.createElement("DIV") div.className = "px" div.style.left = x div.style.top = y document.body.appendChild(div) } var x, y, r2; var radius = 25 var xCenter = 155 var yCenter = 155 r2 = radius * radius; window.onload = function() { for (x = -radius; x <= radius; x++) { y = Math.sqrt(r2 - x*x) + 0.5 draw(xCenter + x, yCenter + y); draw(xCenter + x, yCenter - y); } } </script> <style type="text/css"> .px { width:1px; height:1px; overflow:hidden; position:absolute; background:black } </style> </head> <body> </body> </html>



Reply With Quote


Bookmarks