Skip to content

Instantly share code, notes, and snippets.

@findli
Last active October 1, 2019 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save findli/c6b981d93f7c5d86959d6b868b712849 to your computer and use it in GitHub Desktop.
Save findli/c6b981d93f7c5d86959d6b868b712849 to your computer and use it in GitHub Desktop.
Буртовой Ян skype: yanchik366
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Буртовой Ян skype: yanchik366</title>
</head>
<body>
<input type="text" id="expr" value="x*x">
<input type="text" id="range-start" value="1">
<input type="text" id="range-end" value="300">
<button id="run">run</button>
<script>
var canvas = document.createElement("canvas");
canvas.setAttribute("width", 1000);
canvas.setAttribute("height", 1000);
canvas.setAttribute("style", "position: absolute; x:0; y:0;border:thin solid red;");
document.body.appendChild(canvas);
var ctx = canvas.getContext("2d");
let elementById = document.getElementById("run");
elementById.addEventListener("click", () => {
let expr = document.getElementById("expr").value;
let rStart = Number(document.getElementById("range-start").value);
let rEnd = Number(document.getElementById("range-end").value);
for (let i = rStart; i <= rEnd; i++) {
try {
ctx.fillRect(i, 1000 - eval('x=' + i / 10 + ';' + expr), 2, 2);
} catch (e) {
}
}
});
elementById.dispatchEvent(new Event('click'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment