source: main/trunk/model-sites-dev/von-sparql/js/paper/docs/classes/Color.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: 28.0 KB
Line 
1<!DOCTYPE html>
2<html>
3<head>
4<meta charset="UTF-8">
5<title>Color</title>
6<base target="class-frame">
7<link href="../assets/css/docs.css" rel="stylesheet" type="text/css">
8<script src="../assets/js/paper.js"></script>
9<script src="../assets/js/jquery.js"></script>
10<script src="../assets/js/codemirror.js"></script>
11<script src="../assets/js/docs.js"></script>
12</head>
13<body class="reference">
14<div class="reference-class">
15<h1>Color</h1>
16
17<p>All properties and functions that expect color values in the form
18of instances of Color objects, also accept named colors and hex values as
19strings which are then converted to instances of
20<a href="../classes/Color.html"><tt>Color</tt></a> internally.</p>
21<p>
22<b>Example</b> &mdash; Named color values:
23</p>
24
25<div class="paperscript split">
26
27<div class="buttons">
28<div class="button run">Run</div>
29</div>
30
31<script type="text/paperscript" canvas="canvas-0">
32// Create a circle shaped path at {x: 80, y: 50}
33// with a radius of 30.
34var circle = new Path.Circle(new Point(80, 50), 30);
35
36// Pass a color name to the fillColor property, which is internally
37// converted to a Color.
38circle.fillColor = 'green';
39</script>
40<div class="canvas"><canvas width="516" height="100" id="canvas-0"></canvas></div>
41</div>
42
43
44<p>
45<b>Example</b> &mdash; Hex color values:
46</p>
47
48<div class="paperscript split">
49
50<div class="buttons">
51<div class="button run">Run</div>
52</div>
53
54<script type="text/paperscript" canvas="canvas-1">
55// Create a circle shaped path at {x: 80, y: 50}
56// with a radius of 30.
57var circle = new Path.Circle(new Point(80, 50), 30);
58
59// Pass a hex string to the fillColor property, which is internally
60// converted to a Color.
61circle.fillColor = '#ff0000';
62</script>
63<div class="canvas"><canvas width="516" height="100" id="canvas-1"></canvas></div>
64</div>
65
66
67</div>
68
69<!-- ============================== constructors ========================= -->
70<div class="reference-members"><h2>Constructors</h2>
71
72
73<div id="color-red-green-blue" class="member">
74<div class="member-link">
75<a name="color-red-green-blue" href="#color-red-green-blue"><tt><b>Color</b>(red, green, blue[, alpha])</tt></a>
76</div>
77<div class="member-description hidden">
78<div class="member-text">
79<p>Creates a RGB Color object.</p>
80
81<ul><b>Parameters:</b>
82
83<li>
84<tt>red:</tt>
85<tt>Number</tt>
86&mdash;&nbsp;the amount of red in the color as a value
87between <tt>0</tt> and <tt>1</tt>
88
89</li>
90
91<li>
92<tt>green:</tt>
93<tt>Number</tt>
94&mdash;&nbsp;the amount of green in the color as a value
95between <tt>0</tt> and <tt>1</tt>
96
97</li>
98
99<li>
100<tt>blue:</tt>
101<tt>Number</tt>
102&mdash;&nbsp;the amount of blue in the color as a value
103between <tt>0</tt> and <tt>1</tt>
104
105</li>
106
107<li>
108<tt>alpha:</tt>
109<tt>Number</tt>
110&mdash;&nbsp;the alpha of the color as a value between
111<tt>0</tt> and <tt>1</tt>
112&mdash;&nbsp;optional
113</li>
114
115</ul>
116
117
118<p>
119<b>Example</b> &mdash; Creating a RGB Color:
120</p>
121
122<div class="paperscript split">
123
124<div class="buttons">
125<div class="button run">Run</div>
126</div>
127
128<script type="text/paperscript" canvas="canvas-2">
129// Create a circle shaped path at {x: 80, y: 50}
130// with a radius of 30:
131var circle = new Path.Circle(new Point(80, 50), 30);
132
133// 100% red, 0% blue, 50% blue:
134circle.fillColor = new Color(1, 0, 0.5);
135</script>
136<div class="canvas"><canvas width="516" height="100" id="canvas-2"></canvas></div>
137</div>
138
139
140
141</div>
142</div>
143</div>
144
145
146<div id="color-gray" class="member">
147<div class="member-link">
148<a name="color-gray" href="#color-gray"><tt><b>Color</b>(gray[, alpha])</tt></a>
149</div>
150<div class="member-description hidden">
151<div class="member-text">
152<p>Creates a gray Color object.</p>
153
154<ul><b>Parameters:</b>
155
156<li>
157<tt>gray:</tt>
158<tt>Number</tt>
159&mdash;&nbsp;the amount of gray in the color as a value
160between <tt>0</tt> and <tt>1</tt>
161
162</li>
163
164<li>
165<tt>alpha:</tt>
166<tt>Number</tt>
167&mdash;&nbsp;the alpha of the color as a value between
168<tt>0</tt> and <tt>1</tt>
169&mdash;&nbsp;optional
170</li>
171
172</ul>
173
174
175<p>
176<b>Example</b> &mdash; Creating a gray Color:
177</p>
178
179<div class="paperscript split">
180
181<div class="buttons">
182<div class="button run">Run</div>
183</div>
184
185<script type="text/paperscript" canvas="canvas-3">
186// Create a circle shaped path at {x: 80, y: 50}
187// with a radius of 30:
188var circle = new Path.Circle(new Point(80, 50), 30);
189
190// Create a GrayColor with 50% gray:
191circle.fillColor = new Color(0.5);
192</script>
193<div class="canvas"><canvas width="516" height="100" id="canvas-3"></canvas></div>
194</div>
195
196
197
198</div>
199</div>
200</div>
201
202
203<div id="color-object" class="member">
204<div class="member-link">
205<a name="color-object" href="#color-object"><tt><b>Color</b>(object)</tt></a>
206</div>
207<div class="member-description hidden">
208<div class="member-text">
209<p>Creates a HSB, HSL or gradient Color object from the properties of
210the provided object:</p>
211<p><b>HSB Color</b>:<br>
212<tt>hue: Number</tt> — the hue of the color as a value in
213degrees between <tt>0</tt> and <tt>360</tt><br>
214<tt>saturation: Number</tt> — the saturation of the color as a
215value between <tt>0</tt> and <tt>1</tt><br>
216<tt>brightness: Number</tt> — the brightness of the color as a
217value between <tt>0</tt> and <tt>1</tt><br>
218<tt>alpha: Number</tt> — the alpha of the color as a value between
219<tt>0</tt> and <tt>1</tt></p>
220<p><b>HSL Color</b>:<br>
221<tt>hue: Number</tt> — the hue of the color as a value in
222degrees between <tt>0</tt> and <tt>360</tt><br>
223<tt>saturation: Number</tt> — the saturation of the color as a
224value between <tt>0</tt> and <tt>1</tt><br>
225<tt>lightness: Number</tt> — the lightness of the color as a
226value between <tt>0</tt> and <tt>1</tt><br>
227<tt>alpha: Number</tt> — the alpha of the color as a value between
228<tt>0</tt> and <tt>1</tt></p>
229<p><b>Gradient Color</b>:<br>
230<tt>gradient: Gradient</tt> — the gradient object that describes the
231 color stops and type of gradient to be used.<br>
232<tt>origin: Point</tt> — the origin point of the gradient<br>
233<tt>destination: Point</tt> — the destination point of the gradient
234<tt>stops: Array of GradientStop</tt> — the gradient stops describing
235the gradient, as an alternative to providing a gradient object<br>
236<tt>radial: Boolean</tt> — controls whether the gradient is radial, as
237an alternative to providing a gradient object<br></p>
238
239<ul><b>Parameters:</b>
240
241<li>
242<tt>object:</tt>
243<tt>Object</tt>
244&mdash;&nbsp;an object describing the components and
245 properties of the color.
246
247</li>
248
249</ul>
250
251
252<p>
253<b>Example</b> &mdash; Creating a HSB Color:
254</p>
255
256<div class="paperscript split">
257
258<div class="buttons">
259<div class="button run">Run</div>
260</div>
261
262<script type="text/paperscript" canvas="canvas-4">
263// Create a circle shaped path at {x: 80, y: 50}
264// with a radius of 30:
265var circle = new Path.Circle(new Point(80, 50), 30);
266
267// Create an HSB Color with a hue of 90 degrees, a saturation
268// 100% and a brightness of 100%:
269circle.fillColor = { hue: 90, saturation: 1, brightness: 1 };
270</script>
271<div class="canvas"><canvas width="516" height="100" id="canvas-4"></canvas></div>
272</div>
273
274
275<p>
276<b>Example</b> &mdash; Creating a HSL Color:
277</p>
278
279<div class="paperscript split">
280
281<div class="buttons">
282<div class="button run">Run</div>
283</div>
284
285<script type="text/paperscript" canvas="canvas-5">
286// Create a circle shaped path at {x: 80, y: 50}
287// with a radius of 30:
288var circle = new Path.Circle(new Point(80, 50), 30);
289
290// Create an HSL Color with a hue of 90 degrees, a saturation
291// 100% and a lightness of 50%:
292circle.fillColor = { hue: 90, saturation: 1, lightness: 0.5 };
293</script>
294<div class="canvas"><canvas width="516" height="100" id="canvas-5"></canvas></div>
295</div>
296
297
298<p>
299<b>Example</b> &mdash; Creating a gradient color from an object literal:
300</p>
301
302<div class="paperscript split">
303
304<div class="buttons">
305<div class="button run">Run</div>
306</div>
307
308<script type="text/paperscript" canvas="canvas-6">
309// Define two points which we will be using to construct
310// the path and to position the gradient color:
311var topLeft = view.center - [80, 80];
312var bottomRight = view.center + [80, 80];
313
314var path = new Path.Rectangle({
315 topLeft: topLeft,
316 bottomRight: bottomRight,
317 // Fill the path with a gradient of three color stops
318 // that runs between the two points we defined earlier:
319 fillColor: {
320 stops: ['yellow', 'red', 'blue'],
321 origin: topLeft,
322 destination: bottomRight
323 }
324});
325</script>
326<div class="canvas"><canvas width="516" height="200" id="canvas-6"></canvas></div>
327</div>
328
329
330
331</div>
332</div>
333</div>
334
335
336<div id="color-gradient-origin-destination" class="member">
337<div class="member-link">
338<a name="color-gradient-origin-destination" href="#color-gradient-origin-destination"><tt><b>Color</b>(gradient, origin, destination[, highlight])</tt></a>
339</div>
340<div class="member-description hidden">
341<div class="member-text">
342<p>Creates a gradient Color object.</p>
343
344<ul><b>Parameters:</b>
345
346<li>
347<tt>gradient:</tt>
348<a href="../classes/Gradient.html"><tt>Gradient</tt></a>
349
350
351</li>
352
353<li>
354<tt>origin:</tt>
355<a href="../classes/Point.html"><tt>Point</tt></a>
356
357
358</li>
359
360<li>
361<tt>destination:</tt>
362<a href="../classes/Point.html"><tt>Point</tt></a>
363
364
365</li>
366
367<li>
368<tt>highlight:</tt>
369<a href="../classes/Point.html"><tt>Point</tt></a>
370
371&mdash;&nbsp;optional
372</li>
373
374</ul>
375
376
377<p>
378<b>Example</b> &mdash; Applying a linear gradient color containing evenly distributed color stops:
379</p>
380
381<div class="paperscript split">
382
383<div class="buttons">
384<div class="button run">Run</div>
385</div>
386
387<script type="text/paperscript" canvas="canvas-7">
388// Define two points which we will be using to construct
389// the path and to position the gradient color:
390var topLeft = view.center - [80, 80];
391var bottomRight = view.center + [80, 80];
392
393// Create a rectangle shaped path between
394// the topLeft and bottomRight points:
395var path = new Path.Rectangle(topLeft, bottomRight);
396
397// Create the gradient, passing it an array of colors to be converted
398// to evenly distributed color stops:
399var gradient = new Gradient(['yellow', 'red', 'blue']);
400
401// Have the gradient color run between the topLeft and
402// bottomRight points we defined earlier:
403var gradientColor = new Color(gradient, topLeft, bottomRight);
404
405// Set the fill color of the path to the gradient color:
406path.fillColor = gradientColor;
407</script>
408<div class="canvas"><canvas width="516" height="200" id="canvas-7"></canvas></div>
409</div>
410
411
412<p>
413<b>Example</b> &mdash; Applying a radial gradient color containing unevenly distributed color stops:
414</p>
415
416<div class="paperscript split">
417
418<div class="buttons">
419<div class="button run">Run</div>
420</div>
421
422<script type="text/paperscript" canvas="canvas-8">
423// Create a circle shaped path at the center of the view
424// with a radius of 80:
425var path = new Path.Circle({
426 center: view.center,
427 radius: 80
428});
429
430// The stops array: yellow mixes with red between 0 and 15%,
431// 15% to 30% is pure red, red mixes with black between 30% to 100%:
432var stops = [['yellow', 0], ['red', 0.15], ['red', 0.3], ['black', 0.9]];
433
434// Create a radial gradient using the color stops array:
435var gradient = new Gradient(stops, true);
436
437// We will use the center point of the circle shaped path as
438// the origin point for our gradient color
439var from = path.position;
440
441// The destination point of the gradient color will be the
442// center point of the path + 80pt in horizontal direction:
443var to = path.position + [80, 0];
444
445// Create the gradient color:
446var gradientColor = new Color(gradient, from, to);
447
448// Set the fill color of the path to the gradient color:
449path.fillColor = gradientColor;
450</script>
451<div class="canvas"><canvas width="516" height="200" id="canvas-8"></canvas></div>
452</div>
453
454
455
456</div>
457</div>
458</div>
459
460</div>
461
462
463
464<!-- ============================== properties ========================= -->
465 <div class="reference-members"><h2>Operators</h2>
466
467 <div id="add" class="member">
468<div class="member-link">
469<a name="add" href="#add"><tt><tt><b>+</b> Number</tt>, <tt><b>+</b> Color</tt></tt></a>
470</div>
471<div class="member-description hidden">
472
473
474 <div class="member-text">
475 <p>Returns the addition of the supplied value to both coordinates of
476the color as a new color.</p>
477<p>The object itself is not modified!</p>
478
479 <ul><b>Returns:</b>
480
481 <li>
482<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the addition of the color and the value as a new color
483</li>
484
485 </ul>
486
487
488 <p>
489<b>Example</b>
490</p>
491
492
493<pre class="code">var color = new Color(0.5, 1, 1);
494var result = color + 1;
495console.log(result); // { red: 1, blue: 1, green: 1 }</pre>
496
497 </div>
498
499
500
501 <div class="member-text">
502 <p>Returns the addition of the supplied color to the color as a new
503color.</p>
504<p>The object itself is not modified!</p>
505
506 <ul><b>Returns:</b>
507
508 <li>
509<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the addition of the two colors as a new color
510</li>
511
512 </ul>
513
514
515 <p>
516<b>Example</b>
517</p>
518
519
520<pre class="code">var color1 = new Color(0, 1, 1);
521var color2 = new Color(1, 0, 0);
522var result = color1 + color2;
523console.log(result); // { red: 1, blue: 1, green: 1 }</pre>
524
525 </div>
526
527
528</div>
529</div>
530
531
532 <div id="subtract" class="member">
533<div class="member-link">
534<a name="subtract" href="#subtract"><tt><tt><b>-</b> Number</tt>, <tt><b>-</b> Color</tt></tt></a>
535</div>
536<div class="member-description hidden">
537
538
539 <div class="member-text">
540 <p>Returns the subtraction of the supplied value to both coordinates of
541the color as a new color.</p>
542<p>The object itself is not modified!</p>
543
544 <ul><b>Returns:</b>
545
546 <li>
547<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the subtraction of the color and the value as a new
548 color
549</li>
550
551 </ul>
552
553
554 <p>
555<b>Example</b>
556</p>
557
558
559<pre class="code">var color = new Color(0.5, 1, 1);
560var result = color - 1;
561console.log(result); // { red: 0, blue: 0, green: 0 }</pre>
562
563 </div>
564
565
566
567 <div class="member-text">
568 <p>Returns the subtraction of the supplied color to the color as a new
569color.</p>
570<p>The object itself is not modified!</p>
571
572 <ul><b>Returns:</b>
573
574 <li>
575<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the subtraction of the two colors as a new color
576</li>
577
578 </ul>
579
580
581 <p>
582<b>Example</b>
583</p>
584
585
586<pre class="code">var color1 = new Color(0, 1, 1);
587var color2 = new Color(1, 0, 0);
588var result = color1 - color2;
589console.log(result); // { red: 0, blue: 1, green: 1 }</pre>
590
591 </div>
592
593
594</div>
595</div>
596
597
598 <div id="multiply" class="member">
599<div class="member-link">
600<a name="multiply" href="#multiply"><tt><tt><b>*</b> Number</tt>, <tt><b>*</b> Color</tt></tt></a>
601</div>
602<div class="member-description hidden">
603
604
605 <div class="member-text">
606 <p>Returns the multiplication of the supplied value to both coordinates
607of the color as a new color.</p>
608<p>The object itself is not modified!</p>
609
610 <ul><b>Returns:</b>
611
612 <li>
613<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the multiplication of the color and the value as a
614 new color
615</li>
616
617 </ul>
618
619
620 <p>
621<b>Example</b>
622</p>
623
624
625<pre class="code">var color = new Color(0.5, 1, 1);
626var result = color * 0.5;
627console.log(result); // { red: 0.25, blue: 0.5, green: 0.5 }</pre>
628
629 </div>
630
631
632
633 <div class="member-text">
634 <p>Returns the multiplication of the supplied color to the color as a
635new color.</p>
636<p>The object itself is not modified!</p>
637
638 <ul><b>Returns:</b>
639
640 <li>
641<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the multiplication of the two colors as a new color
642</li>
643
644 </ul>
645
646
647 <p>
648<b>Example</b>
649</p>
650
651
652<pre class="code">var color1 = new Color(0, 1, 1);
653var color2 = new Color(0.5, 0, 0.5);
654var result = color1 * color2;
655console.log(result); // { red: 0, blue: 0, green: 0.5 }</pre>
656
657 </div>
658
659
660</div>
661</div>
662
663
664 <div id="divide" class="member">
665<div class="member-link">
666<a name="divide" href="#divide"><tt><tt><b>/</b> Number</tt>, <tt><b>/</b> Color</tt></tt></a>
667</div>
668<div class="member-description hidden">
669
670
671 <div class="member-text">
672 <p>Returns the division of the supplied value to both coordinates of
673the color as a new color.</p>
674<p>The object itself is not modified!</p>
675
676 <ul><b>Returns:</b>
677
678 <li>
679<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the division of the color and the value as a new
680 color
681</li>
682
683 </ul>
684
685
686 <p>
687<b>Example</b>
688</p>
689
690
691<pre class="code">var color = new Color(0.5, 1, 1);
692var result = color / 2;
693console.log(result); // { red: 0.25, blue: 0.5, green: 0.5 }</pre>
694
695 </div>
696
697
698
699 <div class="member-text">
700 <p>Returns the division of the supplied color to the color as a new
701color.</p>
702<p>The object itself is not modified!</p>
703
704 <ul><b>Returns:</b>
705
706 <li>
707<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the division of the two colors as a new color
708</li>
709
710 </ul>
711
712
713 <p>
714<b>Example</b>
715</p>
716
717
718<pre class="code">var color1 = new Color(0, 1, 1);
719var color2 = new Color(0.5, 0, 0.5);
720var result = color1 / color2;
721console.log(result); // { red: 0, blue: 0, green: 1 }</pre>
722
723 </div>
724
725
726</div>
727</div>
728
729
730 </div>
731
732
733
734 <div class="reference-members"><h2>Properties</h2>
735
736
737<div id="type" class="member">
738<div class="member-link">
739<a name="type" href="#type"><tt><b>type</b></tt></a>
740</div>
741<div class="member-description hidden">
742
743<div class="member-text">
744 <p>The type of the color as a string.</p>
745
746
747 <ul><b>Type:</b>
748 <li>
749 <tt>String('rgb', 'hsb', 'gray')</tt>
750 </li>
751 </ul>
752
753 <p>
754<b>Example</b>
755</p>
756
757
758<pre class="code">var color = new Color(1, 0, 0);
759console.log(color.type); // 'rgb'</pre>
760
761</div>
762
763</div>
764</div>
765
766
767<div id="alpha" class="member">
768<div class="member-link">
769<a name="alpha" href="#alpha"><tt><b>alpha</b></tt></a>
770</div>
771<div class="member-description hidden">
772
773<div class="member-text">
774 <p>The color's alpha value as a number between <tt>0</tt> and <tt>1</tt>.</p>
775<p>All colors of the different subclasses support alpha values.</p>
776
777
778 <ul><b>Type:</b>
779 <li>
780 <tt>Number</tt>
781 </li>
782 </ul>
783
784 <p>
785<b>Example</b> &mdash; A filled path with a half transparent stroke:
786</p>
787
788<div class="paperscript split">
789
790<div class="buttons">
791<div class="button run">Run</div>
792</div>
793
794<script type="text/paperscript" canvas="canvas-9">
795var circle = new Path.Circle(new Point(80, 50), 30);
796
797// Fill the circle with red and give it a 20pt green stroke:
798circle.style = {
799 fillColor: 'red',
800 strokeColor: 'green',
801 strokeWidth: 20
802};
803
804// Make the stroke half transparent:
805circle.strokeColor.alpha = 0.5;
806</script>
807<div class="canvas"><canvas width="516" height="100" id="canvas-9"></canvas></div>
808</div>
809
810
811</div>
812
813</div>
814</div>
815
816
817<div id="blue" class="member">
818<div class="member-link">
819<a name="blue" href="#blue"><tt><b>blue</b></tt></a>
820</div>
821<div class="member-description hidden">
822
823<div class="member-text">
824 <p>The amount of blue in the color as a value between <tt>0</tt> and
825<tt>1</tt>.</p>
826
827
828 <ul><b>Type:</b>
829 <li>
830 <tt>Number</tt>
831 </li>
832 </ul>
833
834 <p>
835<b>Example</b> &mdash; Changing the amount of blue in a color:
836</p>
837
838<div class="paperscript split">
839
840<div class="buttons">
841<div class="button run">Run</div>
842</div>
843
844<script type="text/paperscript" canvas="canvas-10">
845var circle = new Path.Circle(new Point(80, 50), 30);
846
847// First we set the fill color to red:
848circle.fillColor = 'red';
849
850// Red + blue = purple:
851circle.fillColor.blue = 1;
852</script>
853<div class="canvas"><canvas width="516" height="100" id="canvas-10"></canvas></div>
854</div>
855
856
857</div>
858
859</div>
860</div>
861
862
863 <h3>Gray Components</h3>
864
865<div id="gray" class="member">
866<div class="member-link">
867<a name="gray" href="#gray"><tt><b>gray</b></tt></a>
868</div>
869<div class="member-description hidden">
870
871<div class="member-text">
872 <p>The amount of gray in the color as a value between <tt>0</tt> and
873<tt>1</tt>.</p>
874
875
876 <ul><b>Type:</b>
877 <li>
878 <tt>Number</tt>
879 </li>
880 </ul>
881
882
883</div>
884
885</div>
886</div>
887
888
889 <h3>HSB Components</h3>
890
891<div id="hue" class="member">
892<div class="member-link">
893<a name="hue" href="#hue"><tt><b>hue</b></tt></a>
894</div>
895<div class="member-description hidden">
896
897<div class="member-text">
898 <p>The hue of the color as a value in degrees between <tt>0</tt> and
899<tt>360</tt>.</p>
900
901
902 <ul><b>Type:</b>
903 <li>
904 <tt>Number</tt>
905 </li>
906 </ul>
907
908 <p>
909<b>Example</b> &mdash; Changing the hue of a color:
910</p>
911
912<div class="paperscript split">
913
914<div class="buttons">
915<div class="button run">Run</div>
916</div>
917
918<script type="text/paperscript" canvas="canvas-11">
919var circle = new Path.Circle(new Point(80, 50), 30);
920circle.fillColor = 'red';
921circle.fillColor.hue += 30;
922</script>
923<div class="canvas"><canvas width="516" height="100" id="canvas-11"></canvas></div>
924</div>
925
926
927<p>
928<b>Example</b> &mdash; Hue cycling:
929</p>
930
931<div class="paperscript split">
932
933<div class="buttons">
934<div class="button run">Run</div>
935</div>
936
937<script type="text/paperscript" canvas="canvas-12">
938// Create a rectangle shaped path, using the dimensions
939// of the view:
940var path = new Path.Rectangle(view.bounds);
941path.fillColor = 'red';
942
943function onFrame(event) {
944 path.fillColor.hue += 0.5;
945}
946</script>
947<div class="canvas"><canvas width="516" height="100" id="canvas-12"></canvas></div>
948</div>
949
950
951</div>
952
953</div>
954</div>
955
956
957<div id="saturation" class="member">
958<div class="member-link">
959<a name="saturation" href="#saturation"><tt><b>saturation</b></tt></a>
960</div>
961<div class="member-description hidden">
962
963<div class="member-text">
964 <p>The saturation of the color as a value between <tt>0</tt> and <tt>1</tt>.</p>
965
966
967 <ul><b>Type:</b>
968 <li>
969 <tt>Number</tt>
970 </li>
971 </ul>
972
973
974</div>
975
976</div>
977</div>
978
979
980<div id="brightness" class="member">
981<div class="member-link">
982<a name="brightness" href="#brightness"><tt><b>brightness</b></tt></a>
983</div>
984<div class="member-description hidden">
985
986<div class="member-text">
987 <p>The brightness of the color as a value between <tt>0</tt> and <tt>1</tt>.</p>
988
989
990 <ul><b>Type:</b>
991 <li>
992 <tt>Number</tt>
993 </li>
994 </ul>
995
996
997</div>
998
999</div>
1000</div>
1001
1002
1003 <h3>HSL Components</h3>
1004
1005<div id="lightness" class="member">
1006<div class="member-link">
1007<a name="lightness" href="#lightness"><tt><b>lightness</b></tt></a>
1008</div>
1009<div class="member-description hidden">
1010
1011<div class="member-text">
1012 <p>The lightness of the color as a value between <tt>0</tt> and <tt>1</tt>.</p>
1013
1014
1015 <ul><b>Type:</b>
1016 <li>
1017 <tt>Number</tt>
1018 </li>
1019 </ul>
1020
1021
1022</div>
1023
1024</div>
1025</div>
1026
1027
1028 <h3>Gradient Components</h3>
1029
1030<div id="gradient" class="member">
1031<div class="member-link">
1032<a name="gradient" href="#gradient"><tt><b>gradient</b></tt></a>
1033</div>
1034<div class="member-description hidden">
1035
1036<div class="member-text">
1037 <p>The gradient object describing the type of gradient and the stops.</p>
1038
1039
1040 <ul><b>Type:</b>
1041 <li>
1042 <a href="../classes/Gradient.html"><tt>Gradient</tt></a>
1043 </li>
1044 </ul>
1045
1046
1047</div>
1048
1049</div>
1050</div>
1051
1052
1053<div id="highlight" class="member">
1054<div class="member-link">
1055<a name="highlight" href="#highlight"><tt><b>highlight</b></tt></a>
1056</div>
1057<div class="member-description hidden">
1058
1059<div class="member-text">
1060 <p>The highlight point of the gradient.</p>
1061
1062
1063 <ul><b>Type:</b>
1064 <li>
1065 <a href="../classes/Point.html"><tt>Point</tt></a>
1066 </li>
1067 </ul>
1068
1069 <p>
1070<b>Example</b> &mdash; Create a circle shaped path at the center of the view, using 40% of the height of the view as its radius and fill it with a radial gradient color:
1071</p>
1072
1073<div class="paperscript split">
1074
1075<div class="buttons">
1076<div class="button run">Run</div>
1077</div>
1078
1079<script type="text/paperscript" canvas="canvas-13">
1080var path = new Path.Circle({
1081 center: view.center,
1082 radius: view.bounds.height * 0.4
1083});
1084
1085path.fillColor = {
1086 gradient: {
1087 stops: ['yellow', 'red', 'black'],
1088 radial: true
1089 },
1090 origin: path.position,
1091 destination: path.bounds.rightCenter
1092};
1093
1094function onMouseMove(event) {
1095 // Set the origin highlight of the path's gradient color
1096 // to the position of the mouse:
1097 path.fillColor.highlight = event.point;
1098}
1099</script>
1100<div class="canvas"><canvas width="516" height="300" id="canvas-13"></canvas></div>
1101</div>
1102
1103
1104</div>
1105
1106</div>
1107</div>
1108
1109
1110 <h3>RGB Components</h3>
1111
1112<div id="red" class="member">
1113<div class="member-link">
1114<a name="red" href="#red"><tt><b>red</b></tt></a>
1115</div>
1116<div class="member-description hidden">
1117
1118<div class="member-text">
1119 <p>The amount of red in the color as a value between <tt>0</tt> and
1120<tt>1</tt>.</p>
1121
1122
1123 <ul><b>Type:</b>
1124 <li>
1125 <tt>Number</tt>
1126 </li>
1127 </ul>
1128
1129 <p>
1130<b>Example</b> &mdash; Changing the amount of red in a color:
1131</p>
1132
1133<div class="paperscript split">
1134
1135<div class="buttons">
1136<div class="button run">Run</div>
1137</div>
1138
1139<script type="text/paperscript" canvas="canvas-14">
1140var circle = new Path.Circle(new Point(80, 50), 30);
1141circle.fillColor = 'blue';
1142
1143// Blue + red = purple:
1144circle.fillColor.red = 1;
1145</script>
1146<div class="canvas"><canvas width="516" height="100" id="canvas-14"></canvas></div>
1147</div>
1148
1149
1150</div>
1151
1152</div>
1153</div>
1154
1155
1156<div id="green" class="member">
1157<div class="member-link">
1158<a name="green" href="#green"><tt><b>green</b></tt></a>
1159</div>
1160<div class="member-description hidden">
1161
1162<div class="member-text">
1163 <p>The amount of green in the color as a value between <tt>0</tt> and
1164<tt>1</tt>.</p>
1165
1166
1167 <ul><b>Type:</b>
1168 <li>
1169 <tt>Number</tt>
1170 </li>
1171 </ul>
1172
1173 <p>
1174<b>Example</b> &mdash; Changing the amount of green in a color:
1175</p>
1176
1177<div class="paperscript split">
1178
1179<div class="buttons">
1180<div class="button run">Run</div>
1181</div>
1182
1183<script type="text/paperscript" canvas="canvas-15">
1184var circle = new Path.Circle(new Point(80, 50), 30);
1185
1186// First we set the fill color to red:
1187circle.fillColor = 'red';
1188
1189// Red + green = yellow:
1190circle.fillColor.green = 1;
1191</script>
1192<div class="canvas"><canvas width="516" height="100" id="canvas-15"></canvas></div>
1193</div>
1194
1195
1196</div>
1197
1198</div>
1199</div>
1200
1201 </div>
1202
1203
1204
1205<!-- ============================== methods ================================ -->
1206 <div class="reference-members"><h2>Methods</h2>
1207
1208
1209<div id="hasalpha" class="member">
1210<div class="member-link">
1211<a name="hasalpha" href="#hasalpha"><tt><b>hasAlpha</b>()</tt></a>
1212</div>
1213<div class="member-description hidden">
1214<div class="member-text">
1215 <p>Checks if the color has an alpha value.</p>
1216
1217
1218 <ul><b>Returns:</b>
1219
1220 <li>
1221<tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;<tt>true</tt> if the color has an alpha value, <tt>false</tt> otherwise
1222</li>
1223
1224 </ul>
1225
1226
1227
1228</div>
1229</div>
1230</div>
1231
1232
1233<div id="equals-color" class="member">
1234<div class="member-link">
1235<a name="equals-color" href="#equals-color"><tt><b>equals</b>(color)</tt></a>
1236</div>
1237<div class="member-description hidden">
1238<div class="member-text">
1239 <p>Checks if the component color values of the color are the
1240same as those of the supplied one.</p>
1241
1242<ul><b>Parameters:</b>
1243
1244<li>
1245<tt>color:</tt>
1246<a href="../classes/Color.html"><tt>Color</tt></a>
1247&mdash;&nbsp;the color to compare with
1248
1249</li>
1250
1251</ul>
1252
1253
1254 <ul><b>Returns:</b>
1255
1256 <li>
1257<tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;<tt>true</tt> if the colors are the same, <tt>false</tt> otherwise
1258</li>
1259
1260 </ul>
1261
1262
1263
1264</div>
1265</div>
1266</div>
1267
1268
1269<h3>String Representations</h3>
1270
1271<div id="tostring" class="member">
1272<div class="member-link">
1273<a name="tostring" href="#tostring"><tt><b>toString</b>()</tt></a>
1274</div>
1275<div class="member-description hidden">
1276<div class="member-text">
1277
1278
1279
1280 <ul><b>Returns:</b>
1281
1282 <li>
1283<tt><tt>String</tt></tt>&nbsp;&mdash;&nbsp;a string representation of the color
1284</li>
1285
1286 </ul>
1287
1288
1289
1290</div>
1291</div>
1292</div>
1293
1294
1295<div id="tocss-hex" class="member">
1296<div class="member-link">
1297<a name="tocss-hex" href="#tocss-hex"><tt><b>toCSS</b>(hex)</tt></a>
1298</div>
1299<div class="member-description hidden">
1300<div class="member-text">
1301 <p>Returns the color as a CSS string.</p>
1302
1303<ul><b>Parameters:</b>
1304
1305<li>
1306<tt>hex:</tt>
1307<tt>Boolean</tt>
1308&mdash;&nbsp;wether to return the color in hex-representation
1309or as a CSS rgb / rgba string.
1310
1311</li>
1312
1313</ul>
1314
1315
1316 <ul><b>Returns:</b>
1317
1318 <li>
1319<tt><tt>String</tt></tt>&nbsp;&mdash;&nbsp;a css string representation of the color.
1320</li>
1321
1322 </ul>
1323
1324
1325
1326</div>
1327</div>
1328</div>
1329
1330
1331<div id="transform-matrix" class="member">
1332<div class="member-link">
1333<a name="transform-matrix" href="#transform-matrix"><tt><b>transform</b>(matrix)</tt></a>
1334</div>
1335<div class="member-description hidden">
1336<div class="member-text">
1337 <p>Transform the gradient color by the specified matrix.</p>
1338
1339<ul><b>Parameters:</b>
1340
1341<li>
1342<tt>matrix:</tt>
1343<a href="../classes/Matrix.html"><tt>Matrix</tt></a>
1344&mdash;&nbsp;the matrix to transform the gradient color by
1345
1346</li>
1347
1348</ul>
1349
1350
1351
1352
1353</div>
1354</div>
1355</div>
1356
1357 </div>
1358
1359
1360
1361
1362<!-- =========================== copyright notice ========================= -->
1363<p class="footer">Copyright &#169; 2011 <a href="http://www.lehni.org" target="_blank">J&uuml;rg Lehni</a> &amp; <a href="http://www.jonathanpuckey.com" target="_blank">Jonathan Puckey</a>. All Rights Reserved.</p>
1364<div class="content-end"></div>
1365
1366</body>
Note: See TracBrowser for help on using the repository browser.