-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdragon.html
More file actions
38 lines (37 loc) · 1.26 KB
/
dragon.html
File metadata and controls
38 lines (37 loc) · 1.26 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ドラゴンカーブ</title>
<script>
window.onload = function(){
var canvas = document.getElementById("mycanvas");
var ctx = canvas.getContext("2d");
ctx.beginPath();
dragon(ctx,10,400,320,100,0,1);
ctx.stroke();
//ドラゴンカーブを描く
// c:描画するコンテキスト
// i:長さ
// x,y:現在座標
// dx,dy:増加分
// sign:符号
function dragon(c, i, x, y, dx, dy, sign){
if(i === 0){
c.stroke();
}else{
c.moveTo(x, y);
c.lineTo(x + (dx-sign*dy)/2, y + (dy + sign*dx)/2);
dragon(c, i-1, x+(dx-sign*dy)/2, y+(dy+sign*dx)/2, (dx-sign*dy)/2, (dy+sign*dx)/2,1);
c.moveTo(x, y);
c.lineTo(x+(dx+sign*dy)/2, y+(dy-sign*dx)/2);
dragon(c, i-1, x+(dx+sign*dy)/2, y+(dy-sign*dx)/2, (dx+sign*dy)/2, (dy-sign*dx)/2, -1);
}
}
};
</script>
</head>
<body>
<canvas id = "mycanvas" width = "800" height="640"></canvas>
</body>
</html>