aktuelle.kurse/m152/auftraege/x_gitressourcen/Animationen/HTML5_Canvas/Canvas_45.html

35 lines
654 B
HTML
Raw Normal View History

2021-06-25 16:17:59 +02:00
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Canvas</title>
</head>
<body>
<h1>HTML5 Canvas (Sinuskurve)</h1>
<canvas id="myCanvas" width="1000" height="1000"/>
<script>
const rectSize = 500;
let x = 0;
function zeichne()
{
let ctx = document.getElementById("myCanvas").getContext("2d");
x+=1;
if (x > rectSize){
ctx.clearRect(0, 0, rectSize, rectSize);
x = 0;
}
let y = (Math.sin(x/10) + 1); // + 1 => dadurch immer positive Werte
ctx.fillRect(x, y*50, 1, 1);
window.requestAnimationFrame(zeichne);
}
zeichne();
</script>
</body>
</html>