Result Size: 300 x 150
x
 
<!DOCTYPE html>
<html>
<script src="../scripts/myplotlib.js"></script>
<body>
<canvas id="myCanvas" width="400px" height="400px" style="width:100%;max-width:400px;border:1px solid black"></canvas>
<script>
// Створити плотер
const plotter = new XYPlotter("myCanvas");
plotter.transformXY();
const xMax = plotter.xMax;
const yMax = plotter.yMax;
const xMin = plotter.xMin;
const yMin = plotter.yMin;
// Створити рандомні XY точки
const numPoints = 500;
const xPoints = [];
const yPoints = [];
for (let i = 0; i < numPoints; i++) {
  xPoints[i] = Math.random() * xMax;
  yPoints[i] = Math.random() * yMax;
}
// Лінійна функція
function f(x) {
  return x * 1.2 + 50;
}
// Накреслити лінію
plotter.plotLine(xMin, f(xMin), xMax, f(xMax), "black");
// Обчислити бажані відповіді
const desired = [];
for (let i = 0; i < numPoints; i++) {
  desired[i] = 0;
  if (yPoints[i] > f(xPoints[i])) {desired[i] = 1}
}
// Показати бажаний результат
for (let i = 0; i < numPoints; i++) {
  let color = "blue";
  if (desired[i]) color = "green";
  plotter.plotPoint(xPoints[i], yPoints[i], color);
}
</script>
</body>
</html>