-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath Patterns.html
More file actions
156 lines (123 loc) · 3.07 KB
/
Copy pathMath Patterns.html
File metadata and controls
156 lines (123 loc) · 3.07 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html>
<head>
<title>Mathematical Flowers</title>
<!-- Font -->
<link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">
<style>
* {
overflow: hidden;
font-family: 'Ubuntu', sans-serif;
}
body {
background-color: #235;
}
p {
position: absolute;
color: white;
font-size: 3vh;
left: 40%;
margin-top: 1%;
}
p:nth-of-type(3) {
top: 92%;
left: 4%;
}
p:nth-of-type(5) {
top: 87%;
}
p:nth-of-type(6) {
top: 92%;
}
#d {
top: 87%;
left: 4%;
}
#n {
top:82%;
left: 4%;
}
#k {
top: 82%;
}
canvas {
position: absolute;
top: 0;
left: 0;
border-bottom: 3px double #568;
background-color: #013;
}
#wm {
display:inline-block;
color: white;
margin-top:1%;
padding-left:100%;
animation:move 8s linear infinite;
}
@keyframes move {
from { transform:translate(0, 0);}
20% {color: pink; text-shadow:3px 6px 5px red;}
40% {color: red; text-shadow:3px 4px 3px yellow;}
60% {color: green; text-shadow:3px 2px 3px blue;}
80% {color: gray; text-shadow:6px 4px 2px pink;}
to { transform:translate(-100%, 0);}
}
</style>
<script>
var canvas, g, iv, angle = 0, d, n, scale, lastK;
onload = function() {
canvas = document.getElementsByTagName("canvas")[0];
canvas.width = window.innerWidth;
canvas.height = window.innerHeight * 0.8;
scale = canvas.width < canvas.height ? canvas.width / 3 : canvas.height / 3;
g = canvas.getContext("2d");
g.translate(canvas.width / 2, canvas.height / 2);
g.strokeStyle = "white";
canvas.onclick = start;
start();
}
function start() {
d = Math.floor(Math.random() * 14) + 1;
n = Math.floor(Math.random() * 20) + 1;
var k = n / d;
if(k == 1 || lastK == k) {
start();
return;
}
g.clearRect(-canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);
g.beginPath();
var string = k % 1 === 0 ? k : n +"/"+ d;
for(var i = 2; i < 10; i++) {
if((n / i) % 1 === 0 && (d / i) % 1 === 0)
string = ((n / i) + "/" + (d / i));
}
document.getElementById("d").innerHTML = "d = " + d;
document.getElementById("n").innerHTML = "n = " + n;
document.getElementById("k").innerHTML = "k = " + string;
iv = setInterval(draw, 5);
}
function draw() {
var k = n / d;
var x = Math.cos(k * angle) * Math.cos(angle) * scale;
var y = Math.cos(k * angle) * Math.sin(angle) * scale;
g.lineTo(x, y);
g.stroke();
if(angle > Math.PI * d * n * 2) {
lastK = k;
clearInterval(iv);
}
angle += Math.PI / 100;
}
</script>
</head>
<body>
<canvas></canvas>
<p id="n">n = 1</p>
<p id="d">d = 1</p>
<p>k = n / d</p>
<p id="k">k = 1/1</p>
<p>x = cos(k * θ) * cos(θ)</p>
<p>y = cos(k * θ) * sin(θ)</p>
<pre id="wm">Tap to generate a different flower [Created by: VIKAS CAHAHAL]</pre>
</body>
</html>