-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvas2.html
More file actions
51 lines (46 loc) · 1.29 KB
/
canvas2.html
File metadata and controls
51 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<?=globals.functions.importHead({
input,
tabs:1,
title: "canvas draw line",
})?>
</head>
<body>
<h1>Ich bin Canvas</h1>
<canvas id="meinCanvas" width=300 height=100 style="border:1px solid #000000;"></canvas>
<p><button onclick="render()">render</button></p>
<p id=p_data>press render button</p>
<script>
function render(){
const canvas = document.getElementById("meinCanvas");
const {height,width}=canvas;
const ctx = canvas.getContext("2d");
ctx.clearRect(0,0,width,height);
const data=[];
for(let counter=0; counter<width/4; counter+=1){
data.push(Math.round(Math.min(Math.random()*height,height)));
}
ctx.beginPath();
ctx.moveTo(0,height);
let multiplayer=width/data.length;
if(multiplayer<1) multiplayer=1;
for(let index=0; index<data.length; index+=1){
const width_offset=Math.round(index*multiplayer);
const y=data[index];
if(width_offset>width) break;
ctx.lineTo(width_offset,y);
//console.log("Y X",width_offset,y);
}
ctx.stroke(); // Linie zeichnen
// Linie von x=10,y=10 nach x=200,y=100
//ctx.beginPath();
//ctx.moveTo(0,0); // Startpunkt
//ctx.lineTo(width,height); // Endpunkt
//ctx.stroke(); // Linie zeichnen
}
render();
</script>
</body>
</html>