-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlollipop.html
91 lines (77 loc) · 2.55 KB
/
lollipop.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.2.1/d3.min.js"></script>
<script type="text/javascript" src="underscore.js"></script>
<style type="text/css">
body { background: #666; }
</style>
</head>
<body>
<script type="text/javascript">
var colors = ["132537", "006C80", "EBCAB8", "FE8315", "FA3113"];
var bg = "#efefef";
var w = 800,
h = 800;
var svg = d3.select("body")
.append("svg:svg")
.attr("width", w)
.attr("height", h)
svg.append("svg:rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", bg)
drawCircles();
function drawCircles() {
var sc = 70;
for(var i = 0; i < sc; i++) {
var p = pointWithinCircle(350);
var x = p[0];
var y = p[1];
var xTransformed = x + w/2;
var yTransformed = y + h/2;
var r = getRandomInt(4, 35);
drawLine(w/2, h/2, xTransformed, yTransformed);
drawCircle(xTransformed, yTransformed, r );
}
}
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function pointWithinCircle(r) {
var radius = r;
x = Math.random() * 2 * radius - radius;
ylim = Math.sqrt(radius * radius - x * x);
y = Math.random() * 2 * ylim - ylim;
return [x, y];
}
function pointOnCircle (r) {
var angle = Math.random()*Math.PI*2;
return [Math.cos(angle)*r, y = Math.sin(angle)*r]
}
function drawCircle(x, y, r) {
svg.append("svg:circle")
// .attr("fill", '#'+(Math.floor(Math.random()*16777215) + 8000).toString(16))
.attr("fill", '#'+colors[Math.floor(Math.random()*colors.length)])
.attr("opacity", Math.random() + 0.4)
.attr("stroke", "#ccc")
// .attr("stroke-opacity", 0.5)
.attr("cx", x)
.attr("cy", y)
.attr("r", r)
}
function drawLine(start_x, start_y, end_x, end_y) {
svg.append("svg:line")
.attr("stroke", '#666')
.attr("x1", start_x)
.attr("y1", start_y)
.attr("x2", end_x)
.attr("y2", end_y)
.attr("opacity", 0.3)
}
</script>
</body>
</html>