source: main/trunk/model-sites-dev/von-sparql/js/paper/examples/Scripts/HslColor.html@ 28914

Last change on this file since 28914 was 28914, checked in by ak19, 10 years ago

Supporting javascript libraries and bespoke code written by Steffan to support the von-sparql user interface

File size: 1.6 KB
Line 
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <title>HslColor</title>
6 <link rel="stylesheet" href="../css/style.css">
7 <script type="text/javascript" src="../../dist/paper.js"></script>
8 <script type="text/paperscript" canvas="canvas">
9 var steps = {
10 hue: 100,
11 saturation: 20,
12 lightness: 3
13 };
14
15 for (var i = 0; i < steps.lightness; i++) {
16 var radius = view.size.width / steps.lightness * 0.45;
17 var offset = new Point(view.size.width / steps.lightness, 0);
18 var position = view.bounds.leftCenter + offset * (i + 0.5);
19 var lightness = 1 - (i + 1) / (steps.lightness + 1);
20 createWheel(position, radius, steps, lightness);
21 };
22
23 function createWheel(center, radius, steps, lightness) {
24 var hUnit = 360 / steps.hue;
25 for (var h = 0; h < steps.hue; h++) {
26 var hue = h * hUnit;
27 var vector = new Point({
28 angle: hue - 90,
29 length: radius
30 });
31 path = new Path(new Point(), vector.rotate(hUnit / 2));
32 path.closed = true;
33 path.arcTo(vector, vector.rotate(hUnit / -2));
34 path.position += center;
35 var colors = [];
36 for (var i = 0; i < steps.saturation; i++) {
37 var saturation = i / steps.saturation;
38 var color = { hue: hue, saturation: saturation, lightness: lightness };
39 colors.push(color);
40 }
41 var gradient = new Gradient(colors, true);
42 var from = center;
43 var to = center + vector;
44 var gradientColor = new Color(gradient, from, to);
45 path.fillColor = path.strokeColor = gradientColor;
46 }
47 }
48 </script>
49</head>
50<body>
51 <canvas id="canvas" resize style="background:black"></canvas>
52</body>
53</html>
Note: See TracBrowser for help on using the repository browser.