-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagegen.html
70 lines (65 loc) · 1.75 KB
/
imagegen.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
<!DOCTYPE html>
<html>
<head>
<title>Imagegen</title>
<style>
.hoverclass {
width: 500px;
height: 500px;
border: 1px dashed grey;
}
.polygon {
-webkit-transition: -webkit-transform 5s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transform: scale(1) rotate(180deg) translate(0, 0);
-webkit-transform-origin: 50% 50%;
}
.hoverclass:hover .polygon {
-webkit-transform: rotate(0deg);
}
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js"></script>
<script>
function getRandom(max) {
return Math.floor(Math.random() * (max + 1));
}
angular.module('imagegen', [])
.factory('randomPolygon', function() {
return function(w, h) {
function getPoint() { return [getRandom(w), getRandom(h)]; }
var n = getRandom(3) + 3;
var points = []
for (var i = 0; i < n; i++) {
points.push(getPoint());
};
return {
points: points,
color: [getRandom(255), getRandom(255), getRandom(255), Math.random()]
}
}
})
.controller('SvgController', function($scope, randomPolygon) {
$scope.polygons = [];
for (var i = 0; i < 50; i++) {
$scope.polygons.push(randomPolygon(500,500))
}
})
.filter('rgba', function() {
return function(c) {
return 'rgba(' + [c].join(',') + ')';
}
})
.filter('path', function() {
return function(points) {
var path = [];
points.forEach(function(p) { path.push(p.join(',')); });
return path.join(' ');
}
});
</script>
</head>
<body ng-app="imagegen">
<svg ng-controller="SvgController" class="hoverclass" xmlns="http://www.w3.org/2000/svg" version="1.1">
<polygon ng-repeat="poly in polygons" class="polygon" ng-attr-points="{{poly.points | path}}" fill="{{poly.color | rgba}}" />
</svg>
</body>
</html>