-
Notifications
You must be signed in to change notification settings - Fork 9
/
epicycles.html
77 lines (74 loc) · 2.18 KB
/
epicycles.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
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<title>Epicycles - PicturElements</title>
<link rel="icon" href="pelement.png">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,700" rel="stylesheet" type="text/css">
<style>
body{
background-color:white;
margin:0;
}
#paintcanvas,#epicyclecanvas{
display:block;
position:fixed;
width:100%;
height:100%;
}
</style>
<script>
var epiR=[100,80,60,40,20],epiP=[0,0,0,0,0];
var ctx,ctx2;
var thread=null;
var started=false;
var originX,originY;
function init(){
var canvas=document.getElementById("paintcanvas");
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
ctx=canvas.getContext("2d");
ctx.lineWidth=2;
ctx.strokeStyle="red";
canvas=document.getElementById("epicyclecanvas");
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
ctx2=canvas.getContext("2d");
ctx2.lineWidth=2;
ctx2.strokeStyle="#707";
ctx2.fillStyle="#707";
thread=setInterval(paint,25);
}
function paint(){
ctx2.clearRect(0,0,10000,10000);
if (started){
ctx.beginPath();
ctx.moveTo(originX,originY);
}
originX=window.innerWidth/2,originY=window.innerHeight/2;
for (var i=0;i<epiR.length;i++){
ctx2.beginPath();
ctx2.arc(originX,originY,5,0,2*Math.PI);
ctx2.fill();
ctx2.beginPath();
ctx2.arc(originX,originY,epiR[i],0,2*Math.PI);
ctx2.stroke();
originX=originX+Math.cos(epiP[i]*2*Math.PI)*epiR[i];
originY=originY+Math.sin(epiP[i]*2*Math.PI)*epiR[i];
epiP[i]+=(0.005*(epiR[0]/epiR[i]));
}
if (started){
ctx.lineTo(originX,originY);
ctx.stroke();
}
ctx2.beginPath();
ctx2.arc(originX,originY,5,0,2*Math.PI);
ctx2.fill();
started=true;
}
</script>
</head>
<body onload=init()>
<canvas id="paintcanvas"></canvas>
<canvas id="epicyclecanvas"></canvas>
</body>
</html>