html
html
1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html>
<head>
<title>Fancy Lines</title>
</head>
<body>
<center><h3 style="color:lightgrey;">Fancy Lines JavaScript version</h3>
<a href="https://try.kotlinlang.org/#/Examples/Canvas/Fancy%20lines/Fancy%20lines.kt">Original Kotlin Code</a></center>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
body {
background-color: black;
}
Enter to Rename, Shift+Enter to Preview
js
js
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
alert("This code is not mine!\nIt's a JS version (with few modifications) adapted from the Kotlin code that can be found by clicking the 'Original Kotlin Code' link\n\nPress on the animation to Pause/Play\n");
function FancyLines() {
function initalizeCanvas() {
// create new canvas element, set it up (width,height,etc..), add it to the document body
var canvas = document.createElement("canvas");
canvas.style.backgroundColor = "black";
canvas.style.border = "1px solid red";
canvas.style.borderRadius = "10%";
context = canvas.getContext("2d");
context.canvas.width = window.innerWidth*0.95;
context.canvas.height = window.innerHeight*0.75;
document.body.appendChild(canvas);
canvas.onclick = function(){
// attach onclick listener to the canvas (toggle pause/play of animation)
pause = !pause;
run();
}
return canvas;
}
var canvas = initalizeCanvas();
var context = canvas.getContext("2d");
var height = canvas.height;
var width = canvas.width;
var x = width * Math.random();
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run