forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHslColor.html
More file actions
53 lines (51 loc) · 1.57 KB
/
Copy pathHslColor.html
File metadata and controls
53 lines (51 loc) · 1.57 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HslColor</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
var steps = {
hue: 100,
saturation: 20,
lightness: 3
};
for (var i = 0; i < steps.lightness; i++) {
var radius = view.size.width / steps.lightness * 0.45;
var offset = new Point(view.size.width / steps.lightness, 0);
var position = view.bounds.leftCenter + offset * (i + 0.5);
var lightness = 1 - (i + 1) / (steps.lightness + 1);
createWheel(position, radius, steps, lightness);
};
function createWheel(center, radius, steps, lightness) {
var hUnit = 360 / steps.hue;
for (var h = 0; h < steps.hue; h++) {
var hue = h * hUnit;
var vector = new Point({
angle: hue - 90,
length: radius
});
path = new Path(new Point(), vector.rotate(hUnit / 2));
path.closed = true;
path.arcTo(vector, vector.rotate(hUnit / -2));
path.position += center;
var colors = [];
for (var i = 0; i < steps.saturation; i++) {
var saturation = i / steps.saturation;
var color = { hue: hue, saturation: saturation, lightness: lightness };
colors.push(color);
}
var gradient = new Gradient(colors, true);
var from = center;
var to = center + vector;
var gradientColor = new Color(gradient, from, to);
path.fillColor = path.strokeColor = gradientColor;
}
}
</script>
</head>
<body>
<canvas id="canvas" resize style="background:black"></canvas>
</body>
</html>