-
Notifications
You must be signed in to change notification settings - Fork 0
/
lines.html
67 lines (58 loc) · 2 KB
/
lines.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<head>
<style type="text/css">
#canvas {
border: solid;
width: 50%;
height: 50%;
margin: 25%;
background-color: white;
}
body {
background-color: lightgrey;
}
</style>
<script src="point.js"></script>
<script src="rotation.js"></script>
<script src="tile.js"></script>
<script>
function bodyOnLoad() {
let directionOffset = 45;
let numberOfDirections = 2;
let baseFunction = straightLine;
let tileCount = 16;
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
tile(ctx, tileCount, baseFunction, directionOffset, numberOfDirections);
}
function tile(ctx, tileCount, callback, directionOffset, numberOfDirections) {
let tileWidth = ctx.canvas.width / tileCount;
let tileHeight = ctx.canvas.height / tileCount;
let rotation = new Rotation(numberOfDirections, directionOffset);
for(let dx = 0; dx <= tileCount; dx += 1) {
for(let dy = 0; dy <= tileCount; dy += 1) {
let upperLeft = new Point(dx * tileWidth, dy * tileHeight)
let lowerRight = new Point((dx + 1) * tileWidth, (dy + 1) * tileHeight);
let tile = new Tile(upperLeft, lowerRight)
callback(ctx, tile, rotation.random());
}
}
}
function drawLine(ctx, ...points) {
points[0].moveTo(ctx);
for ( i = 1; i < points.length; i++) {
points[i].lineTo(ctx);
}
ctx.stroke();
}
function straightLine(ctx, tile, degree = 0) {
let point1 = new Point(tile.leftBorder(), tile.midHeight()).rotate(degree, tile.center());
let point2 = new Point(tile.rightBorder(), tile.midHeight()).rotate(degree, tile.center());
drawLine(ctx, point1, point2)
}
</script>
</head>
<body onload="bodyOnLoad();">
<canvas id="canvas" height="1000" width="1000"></canvas>
</body>
</html>