-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
154 lines (136 loc) · 5.58 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spirograph Generator</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.5/lumen/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.6/semantic.min.css">
<link rel="stylesheet" href="static/spirograph.css">
</style>
</head>
<body>
<br>
<br>
<div class="well col-md-8 col-md-offset-2" id="well">
<div class="col-md-8">
<h2 class="center">Spirograph Generator</h2>
<canvas id="spirograph"></canvas>
</div>
<div class="col-md-2">
<br>Radius 1: <input id="radius1" oninput="create(false)" class="form-control"></div>
<div class="col-md-2">
<br>Rate 2: <input id="increment2" oninput="create(false)" class="form-control"></div>
<div class="col-md-2">
<br>Radius 2: <input id="radius2" oninput="create(false)" class="form-control"></div>
<div class="col-md-2" id="h1" hidden>
<br>Rate 3: <input id="increment3" oninput="create(false)" class="form-control"></div>
<div class="col-md-2" id="h2" hidden>
<br>Radius 3: <input id="radius3" oninput="create(false)" class="form-control"></div>
<div class="col-md-2">
<br>Complexity:
<div class="ui basic buttons">
<div id="complexity1" onclick="sel(1)" data-picked="true" class="ui button active">One</div>
<div id="complexity2" onclick="sel(2)" data-picked="false" class="ui button">Two</div>
</div>
</div>
<div class="col-md-2">
<br><button id="custom" onclick="create(false)" class="form-control btn btn-primary">Re-Spawn!</button></div>
<div class="col-md-2">
<br><button id="random" onclick="create(true)" class="form-control btn btn-primary">Randomize!</button>
<label><i>Keep clicking me for fun!</i></label></div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.6/semantic.min.js"></script>
<script>
$(document).ready(function(){
if($(window).width() <= 1560){
console.log("hi");
complexity1.innerHTML = '1';
complexity2.innerHTML = '2';
}
width = $('#well').width()/3*2;
height = $(window).height()-200;
spirograph.width = width;
spirograph.height = height;
for(i = 0; i < 50; i++){
create(true);
}
});
window.onresize = function(){
width = $('#well').width()/3*2;
height = $(window).height()-200;
spirograph.width = width;
spirograph.height = height;
}
function sel(complexity){
if(complexity == 1){
$("#complexity1").attr("class", "ui button active");
$("#complexity2").attr("class", "ui button");
h1.style.display = 'none';
h2.style.display = 'none';
} else{
$("#complexity1").attr("class", "ui button");
$("#complexity2").attr("class", "ui button active");
h1.style.display = 'block';
h2.style.display = 'block';
}
create(false);
}
function create(bool){
if(bool){
radius1.value = String(Math.floor((Math.random() * 150) + 1));
radius2.value = String(Math.floor((Math.random() * 100) + 1));
radius3.value = String(Math.floor((Math.random() * 100) + 1));
increment2.value = String(Math.floor((Math.random() * 100) + 1));
increment3.value = String(Math.floor((Math.random() * 100) + 1));
}
var canvas = document.getElementById("spirograph").getContext("2d");
spirograph.width = spirograph.width;
spirograph.height = spirograph.height;
var color1 = '#'+Math.floor(Math.random()*16777215).toString(16);
var color2 = '#'+Math.floor(Math.random()*16777215).toString(16);
var color3 = '#'+Math.floor(Math.random()*16777215).toString(16);
colors = color1.replace("#","").match(/.{1,2}/g);
while((colors[0]==colors[1] && colors[0]==colors[2]) || color1.length < 7){
color1 = '#'+Math.floor(Math.random()*16777215).toString(16);
colors = color1.replace("#","").match(/.{1,2}/g);
}
colors = color2.replace("#","").match(/.{1,2}/g);
while((colors[0]==colors[1] && colors[0]==colors[2]) || color2.length < 7){
color2 = '#'+Math.floor(Math.random()*16777215).toString(16);
colors = color2.replace("#","").match(/.{1,2}/g);
}
colors = color3.replace("#","").match(/.{1,2}/g);
while((colors[0]==colors[1] && colors[0]==colors[2]) || color3.length < 7){
color3 = '#'+Math.floor(Math.random()*16777215).toString(16);
colors = color3.replace("#","").match(/.{1,2}/g);
}
var gradient = canvas.createRadialGradient(spirograph.width/2, spirograph.height/2, spirograph.width/16,
spirograph.width/2, spirograph.height/2, spirograph.width/2);
gradient.addColorStop(0,color1);
gradient.addColorStop(0.2,color2);
gradient.addColorStop(0.6,color3);
canvas.strokeStyle = gradient;
angle = 0;
var interval = setInterval(function(){
if (angle>=Math.PI*4){
clearInterval(interval);
}
angle+=0.005;
x = (radius1.value-radius2.value)*Math.cos(angle) + increment2.value*Math.cos((radius1.value-radius2.value)*angle/2);
y = (radius1.value-radius2.value)*Math.sin(angle) - increment2.value*Math.sin((radius1.value-radius2.value)*angle/2);
if($("#complexity2").attr("class") == "ui button active"){
x += increment3.value*Math.cos((radius2.value-radius3.value)*angle/2);
y -= increment3.value*Math.sin((radius2.value-radius3.value)*angle/2);
}
canvas.lineTo(spirograph.width/2-3+x,spirograph.height/2-3+y);
canvas.moveTo(spirograph.width/2-3+x,spirograph.height/2-3+y);
canvas.stroke();
}, 1);
}
</script>
</body>
</html>