-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·155 lines (145 loc) · 4.98 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
155
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<script src="lib/jquery.ui.touch-punch.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" />
<style>
body {
height: 100vh;
margin: 0px;
padding: 0px;
}
#canvas-container {
height: 66%;
}
canvas {
padding: 0;
margin: 0;
border-bottom: solid grey 1px;
}
#sliders {
width: 50%;
margin: 0 auto;
}
#sliders p {
margin: 10px 0 5px 0;
}
label {
font-family: monospace;
}
.value {
color: rgb(235, 113, 0);
font-weight: bold;
}
#refresh {
float: right;
margin: 10px 10px 0 0;
}
#refresh a {
text-decoration: none;
color: rgb(95, 95, 95);
}
</style>
</head>
<body>
<div id="canvas-container">
<canvas id="canvas"></canvas>
</div>
<div id="refresh">
<a href="#" id="refresh-link"><i class="fa fa-refresh fa-lg"></i></a>
</div>
<div id="sliders">
<p>
<label for="number-of-trees">Number of trees: <span class="value" id="value-number-of-trees"></label>
<input type="text" id="number-of-trees" style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-number-of-trees"></div>
<p>
<label for="slider-angle">Angle between branches: <span class="value" id="value-angle"></span></label>
<input type="text" id="angle" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-angle"></div>
<p>
<label for="slider-wind">Wind: <span class="value" id="value-wind"></span></label>
<input type="text" id="wind" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-wind"></div>
<p>
<label for="randomness">Randomness (angles, length of branches): <span class="value" id="value-randomness"></label>
<input type="text" id="randomness" style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-randomness"></div>
</div>
</body>
<script type="text/javascript" src="tree.js"></script>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
forest.setCanvas(canvas);
$(document).ready(function(){
$(window).resize(resizeCanvas);
//Initial call
resizeCanvas();
$("#refresh-link").on('click', function(){forest.init()});
// sliders
$("#slider-number-of-trees").slider({
value: forest.defaults.numberOfTrees,
min: 1,
max: 20,
slide: function( event, ui ) {
numberOfTrees = ui.value;
$("#value-number-of-trees").text(numberOfTrees);
forest.setParam('numberOfTrees', numberOfTrees);
forest.init();
}
}).prev().find(".value").text(forest.defaults.numberOfTrees);
$("#slider-randomness").slider({
value: forest.defaults.randomness,
min: 0,
max: 100,
step: 1,
slide: function( event, ui ) {
randomness = ui.value;
$("#value-randomness").text(randomness);
forest.setParam('randomness', randomness);
forest.init();
}
}).prev().find(".value").text(forest.defaults.randomness);
$("#slider-angle").slider({
value: forest.defaults.angle,
min: 0,
max: 90,
slide: function( event, ui ) {
angle = ui.value;
$("#value-angle").text(angle + "°");
forest.setParam('angle', angle);
forest.init();
}
}).prev().find(".value").text(forest.defaults.angle + "°");
$("#slider-wind").slider({
value: forest.defaults.wind,
min: -100,
max: 100,
step: 10,
slide: function( event, ui ) {
wind = ui.value;
$("#value-wind").text(wind);
forest.setParam('wind', wind);
forest.init();
}
}).prev().find(".value").text(forest.defaults.wind);
function resizeCanvas() {
console.log("new width=", $("#canvas-container").outerWidth(), "new height=", $("#canvas-container").outerHeight());
canvasElement = $("#canvas");
canvasElement.attr('width', $("#canvas-container").width());
canvasElement.attr('height', $("#canvas-container").height());
//re-draw trees
forest.clear();
forest.init();
}
});
</script>
</html>