<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> circle { width: 35px; height: 35px; background-color: red; border-radius: 50%; position: absolute; font: 900 1.3em / 4px sans-serif; text-align: center; line-height: 35px; } </style> </head> <body> <script> function fn(x) { return Math.abs(Math.floor(Math.sqrt(x)) - Math.abs(x - Math.floor(Math.sqrt(x)) ** 2)); } for(let from = 0, to = 300, x = from; x < to; x++) { const circle = document.createElement("circle"); const y = 20 * fn(x / 20); circle.textContent = Math.round(y); Object.assign(circle.style, { left: `${x * 15}px`, top: `${y * 30}px` }); document.body.append(circle); } </script> </body> </html>