-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
61 lines (54 loc) · 2.33 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
<html>
<head>
<title>Swatch Square</title>
<link rel="stylesheet" type="text/css" href="./main.css" >
<meta property="og:title" content="Swatch Square" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://i.imgur.com/rhTvkPb.png" />
<meta property="og:image:height" content="320" />
<meta property="og:image:width" content="320" />
<meta property="og:description" content="A simple interactive art piece. Click a swatch to invert its color." />
<script src="./angular.min.js"></script>
<script>
var app= angular.module('swatchSquare', []);
app.controller('swatchCtrl', function($scope) {
$scope.SWATCH_COUNT = 16;
$scope.loadColors = function() {
$scope.colors = [];
for (var i = 0; i < $scope.SWATCH_COUNT; i++) {
var newColor = {
red: Math.floor(Math.random() * 16),
green: Math.floor(Math.random() * 16),
blue: Math.floor(Math.random() * 16)
};
$scope.colors.push(newColor);
}
}
$scope.writeColor = function(color) {
return "#" + color.red.toString(16) + color.green.toString(16) + color.blue.toString(16);
};
$scope.invertColor = function(color) {
color.red = 15 - color.red;
color.green = 15 - color.green;
color.blue = 15 - color.blue;
}
$scope.loadColors();
});
</script>
</head>
<body ng-app="swatchSquare">
<div id="header">
<h1>Swatch Square</h1>
<p>Click a swatch to invert its color.</p>
</div>
<div id="square" ng-controller="swatchCtrl">
<div class="tile"
ng-repeat="c in colors"
ng-click="invertColor(c)"
style="background-color:{{writeColor(c)}}"></div>
</div>
<div id="footer">
<p>Made by <a href="http://mckathlin.wordpress.com/">McKathlin</a></p>
</div>
</body>
</html>