paper.js/dist/docs/classes/Color.html
2024-02-21 21:05:01 +00:00

2188 lines
No EOL
44 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Color</title>
<base target="class-frame">
<link href="../assets/css/docs.css" rel="stylesheet" type="text/css">
<script src="../assets/js/paper.js"></script>
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/codemirror.js"></script>
<script src="../assets/js/docs.js"></script>
</head>
<body>
<article class="reference">
<div class="reference-class">
<h1>Color</h1>
<p>All properties and functions that expect color values in the form of instances of Color objects, also accept named colors and hex values as strings which are then converted to instances of <a href="../classes/Color.html"><tt>Color</tt></a> internally.</p>
<h4>Example:<span class="description">Named color values:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-0">
// Create a circle shaped path at {x: 80, y: 50}
// with a radius of 30.
var circle = new Path.Circle(new Point(80, 50), 30);
// Pass a color name to the fillColor property, which is internally
// converted to a Color.
circle.fillColor = 'green';
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-0"></canvas></div>
</div>
<h4>Example:<span class="description">Hex color values:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-1">
// Create a circle shaped path at {x: 80, y: 50}
// with a radius of 30.
var circle = new Path.Circle(new Point(80, 50), 30);
// Pass a hex string to the fillColor property, which is internally
// converted to a Color.
circle.fillColor = '#ff0000';
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-1"></canvas></div>
</div>
</div>
<!-- =============================== constructors ========================== -->
<div class="reference-members">
<h2>Constructors</h2>
<div id="color-red-green-blue" class="member">
<div class="member-link">
<a name="color-red-green-blue" href="#color-red-green-blue"><tt><b>Color</b>(red, green, blue[, alpha])</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Creates a RGB Color object.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>red:</tt>
<tt>Number</tt>
&mdash;&nbsp;the amount of red in the color as a value between <code>0</code> and <code>1</code>
</li>
<li>
<tt>green:</tt>
<tt>Number</tt>
&mdash;&nbsp;the amount of green in the color as a value between <code>0</code> and <code>1</code>
</li>
<li>
<tt>blue:</tt>
<tt>Number</tt>
&mdash;&nbsp;the amount of blue in the color as a value between <code>0</code> and <code>1</code>
</li>
<li>
<tt>alpha:</tt>
<tt>Number</tt>
&mdash;&nbsp;the alpha of the color as a value between <code>0</code> and <code>1</code>
&mdash;&nbsp;optional
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>
</li>
</ul>
<h4>Example:<span class="description">Creating a RGB Color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-2">
// Create a circle shaped path at {x: 80, y: 50}
// with a radius of 30:
var circle = new Path.Circle(new Point(80, 50), 30);
// 100% red, 0% blue, 50% blue:
circle.fillColor = new Color(1, 0, 0.5);
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-2"></canvas></div>
</div>
</div>
</div>
</div>
<div id="color-gray" class="member">
<div class="member-link">
<a name="color-gray" href="#color-gray"><tt><b>Color</b>(gray[, alpha])</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Creates a gray Color object.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>gray:</tt>
<tt>Number</tt>
&mdash;&nbsp;the amount of gray in the color as a value between <code>0</code> and <code>1</code>
</li>
<li>
<tt>alpha:</tt>
<tt>Number</tt>
&mdash;&nbsp;the alpha of the color as a value between <code>0</code> and <code>1</code>
&mdash;&nbsp;optional
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>
</li>
</ul>
<h4>Example:<span class="description">Creating a gray Color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-3">
// Create a circle shaped path at {x: 80, y: 50}
// with a radius of 30:
var circle = new Path.Circle(new Point(80, 50), 30);
// Create a GrayColor with 50% gray:
circle.fillColor = new Color(0.5);
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-3"></canvas></div>
</div>
</div>
</div>
</div>
<div id="color-object" class="member">
<div class="member-link">
<a name="color-object" href="#color-object"><tt><b>Color</b>(object)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Creates a HSB, HSL or gradient Color object from the properties of the provided object:</p>
<ul class="member-list">
<h4>Options:</h4>
<li><tt>hsb.hue: <tt>Number</tt></tt> &mdash; the hue of the color as a value in degrees between <code>0</code> and <code>360</code></li>
<li><tt>hsb.saturation: <tt>Number</tt></tt> &mdash; the saturation of the color as a value between <code>0</code> and <code>1</code></li>
<li><tt>hsb.brightness: <tt>Number</tt></tt> &mdash; the brightness of the color as a value between <code>0</code> and <code>1</code></li>
<li><tt>hsb.alpha: <tt>Number</tt></tt> &mdash; the alpha of the color as a value between <code>0</code> and <code>1</code></li>
<li><tt>hsl.hue: <tt>Number</tt></tt> &mdash; the hue of the color as a value in degrees between <code>0</code> and <code>360</code></li>
<li><tt>hsl.saturation: <tt>Number</tt></tt> &mdash; the saturation of the color as a value between <code>0</code> and <code>1</code></li>
<li><tt>hsl.lightness: <tt>Number</tt></tt> &mdash; the lightness of the color as a value between <code>0</code> and <code>1</code><br></li>
<li><tt>hsl.alpha: <tt>Number</tt></tt> &mdash; the alpha of the color as a value between <code>0</code> and <code>1</code></li>
<li><tt>gradient.gradient: <a href="../classes/Gradient.html"><tt>Gradient</tt></a></tt> &mdash; the gradient object that describes the color stops and type of gradient to be used</li>
<li><tt>gradient.origin: <a href="../classes/Point.html"><tt>Point</tt></a></tt> &mdash; the origin point of the gradient</li>
<li><tt>gradient.destination: <a href="../classes/Point.html"><tt>Point</tt></a></tt> &mdash; the destination point of the gradient</li>
<li><tt>gradient.stops: Array of <a href="../classes/GradientStop.html"><tt>GradientStop</tt></a> objects</tt> &mdash; the gradient stops describing the gradient, as an alternative to providing a gradient object</li>
<li><tt>gradient.radial: <tt>Boolean</tt></tt> &mdash; controls whether the gradient is radial, as an alternative to providing a gradient object</li>
</ul>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>object:</tt>
<tt>Object</tt>
&mdash;&nbsp;an object describing the components and properties of the color
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>
</li>
</ul>
<h4>Example:<span class="description">Creating a HSB Color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-4">
// Create a circle shaped path at {x: 80, y: 50}
// with a radius of 30:
var circle = new Path.Circle(new Point(80, 50), 30);
// Create an HSB Color with a hue of 90 degrees, a saturation
// 100% and a brightness of 100%:
circle.fillColor = { hue: 90, saturation: 1, brightness: 1 };
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-4"></canvas></div>
</div>
<h4>Example:<span class="description">Creating a HSL Color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-5">
// Create a circle shaped path at {x: 80, y: 50}
// with a radius of 30:
var circle = new Path.Circle(new Point(80, 50), 30);
// Create an HSL Color with a hue of 90 degrees, a saturation
// 100% and a lightness of 50%:
circle.fillColor = { hue: 90, saturation: 1, lightness: 0.5 };
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-5"></canvas></div>
</div>
<h4>Example:<span class="description">Creating a gradient color from an object literal:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-6">
// Define two points which we will be using to construct
// the path and to position the gradient color:
var topLeft = view.center - [80, 80];
var bottomRight = view.center + [80, 80];
var path = new Path.Rectangle({
topLeft: topLeft,
bottomRight: bottomRight,
// Fill the path with a gradient of three color stops
// that runs between the two points we defined earlier:
fillColor: {
stops: ['yellow', 'red', 'blue'],
origin: topLeft,
destination: bottomRight
}
});
</script>
<div class="canvas"><canvas width="516" height="200" id="canvas-6"></canvas></div>
</div>
</div>
</div>
</div>
<div id="color-color" class="member">
<div class="member-link">
<a name="color-color" href="#color-color"><tt><b>Color</b>(color)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Creates a Color object from a CSS string. All common CSS color string formats are supported: - Named colors (e.g. <code>&#39;red&#39;</code>, <code>&#39;fuchsia&#39;</code>, …) - Hex strings (<code>&#39;#ffff00&#39;</code>, <code>&#39;#ff0&#39;</code>, …) - RGB strings (<code>&#39;rgb(255, 128, 0)&#39;</code>, <code>&#39;rgba(255, 128, 0, 0.5)&#39;</code>, …) - HSL strings (<code>&#39;hsl(180deg, 20%, 50%)&#39;</code>, <code>&#39;hsla(3.14rad, 20%, 50%, 0.5)&#39;</code>, …)</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<tt>String</tt>
&mdash;&nbsp;the color&rsquo;s CSS string representation
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>
</li>
</ul>
<h4>Example:</h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-7">
var circle = new Path.Circle({
center: [80, 50],
radius: 30,
fillColor: new Color('rgba(255, 255, 0, 0.5)')
});
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-7"></canvas></div>
</div>
</div>
</div>
</div>
<div id="color-gradient-origin-destination" class="member">
<div class="member-link">
<a name="color-gradient-origin-destination" href="#color-gradient-origin-destination"><tt><b>Color</b>(gradient, origin, destination[, highlight])</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Creates a gradient Color object.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>gradient:</tt>
<a href="../classes/Gradient.html"><tt>Gradient</tt></a>
</li>
<li>
<tt>origin:</tt>
<a href="../classes/Point.html"><tt>Point</tt></a>
</li>
<li>
<tt>destination:</tt>
<a href="../classes/Point.html"><tt>Point</tt></a>
</li>
<li>
<tt>highlight:</tt>
<a href="../classes/Point.html"><tt>Point</tt></a>
&mdash;&nbsp;optional
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>
</li>
</ul>
<h4>Example:<span class="description">Applying a linear gradient color containing evenly distributed color stops:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-8">
// Define two points which we will be using to construct
// the path and to position the gradient color:
var topLeft = view.center - [80, 80];
var bottomRight = view.center + [80, 80];
// Create a rectangle shaped path between
// the topLeft and bottomRight points:
var path = new Path.Rectangle(topLeft, bottomRight);
// Create the gradient, passing it an array of colors to be converted
// to evenly distributed color stops:
var gradient = new Gradient(['yellow', 'red', 'blue']);
// Have the gradient color run between the topLeft and
// bottomRight points we defined earlier:
var gradientColor = new Color(gradient, topLeft, bottomRight);
// Set the fill color of the path to the gradient color:
path.fillColor = gradientColor;
</script>
<div class="canvas"><canvas width="516" height="200" id="canvas-8"></canvas></div>
</div>
<h4>Example:<span class="description">Applying a radial gradient color containing unevenly distributed color stops:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-9">
// Create a circle shaped path at the center of the view
// with a radius of 80:
var path = new Path.Circle({
center: view.center,
radius: 80
});
// The stops array: yellow mixes with red between 0 and 15%,
// 15% to 30% is pure red, red mixes with black between 30% to 100%:
var stops = [
['yellow', 0],
['red', 0.15],
['red', 0.3],
['black', 0.9]
];
// Create a radial gradient using the color stops array:
var gradient = new Gradient(stops, true);
// We will use the center point of the circle shaped path as
// the origin point for our gradient color
var from = path.position;
// The destination point of the gradient color will be the
// center point of the path + 80pt in horizontal direction:
var to = path.position + [80, 0];
// Create the gradient color:
var gradientColor = new Color(gradient, from, to);
// Set the fill color of the path to the gradient color:
path.fillColor = gradientColor;
</script>
<div class="canvas"><canvas width="516" height="200" id="canvas-9"></canvas></div>
</div>
</div>
</div>
</div>
</div>
<!-- ================================ operators ============================ -->
<div class="reference-members">
<h2>Operators</h2>
<div id="add" class="member">
<div class="member-link">
<a name="add" href="#add"><tt><tt><b>+</b>number</tt>, <tt><b>+</b>color</tt></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the addition of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to add
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<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
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color + 1;
console.log(result); // { red: 1, blue: 1, green: 1 }</code></pre>
</div>
<div class="member-text">
<p>Returns the addition of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to add
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the addition of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(1, 0, 0);
var result = color1 + color2;
console.log(result); // { red: 1, blue: 1, green: 1 }</code></pre>
</div>
</div>
</div>
<div id="subtract" class="member">
<div class="member-link">
<a name="subtract" href="#subtract"><tt><tt><b>-</b>number</tt>, <tt><b>-</b>color</tt></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the subtraction of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to subtract
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<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 color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color - 1;
console.log(result); // { red: 0, blue: 0, green: 0 }</code></pre>
</div>
<div class="member-text">
<p>Returns the subtraction of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to subtract
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the subtraction of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(1, 0, 0);
var result = color1 - color2;
console.log(result); // { red: 0, blue: 1, green: 1 }</code></pre>
</div>
</div>
</div>
<div id="multiply" class="member">
<div class="member-link">
<a name="multiply" href="#multiply"><tt><tt><b>*</b>number</tt>, <tt><b>*</b>color</tt></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the multiplication of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to multiply
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the multiplication of the color and the value as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color * 0.5;
console.log(result); // { red: 0.25, blue: 0.5, green: 0.5 }</code></pre>
</div>
<div class="member-text">
<p>Returns the multiplication of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to multiply
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the multiplication of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(0.5, 0, 0.5);
var result = color1 * color2;
console.log(result); // { red: 0, blue: 0, green: 0.5 }</code></pre>
</div>
</div>
</div>
<div id="divide" class="member">
<div class="member-link">
<a name="divide" href="#divide"><tt><tt><b>/</b>number</tt>, <tt><b>/</b>color</tt></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the division of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to divide
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<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 color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color / 2;
console.log(result); // { red: 0.25, blue: 0.5, green: 0.5 }</code></pre>
</div>
<div class="member-text">
<p>Returns the division of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to divide
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the division of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(0.5, 0, 0.5);
var result = color1 / color2;
console.log(result); // { red: 0, blue: 0, green: 1 }</code></pre>
</div>
</div>
</div>
</div>
<!-- ================================ properties =========================== -->
<div class="reference-members">
<h2>Properties</h2>
<div id="type" class="member">
<div class="member-link">
<a name="type" href="#type"><tt><b>type</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The type of the color as a string.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>String</tt>
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(1, 0, 0);
console.log(color.type); // 'rgb'</code></pre>
</div>
</div>
</div>
<div id="components" class="member">
<div class="member-link">
<a name="components" href="#components"><tt><b>components</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The color components that define the color, including the alpha value if defined.</p>
<p>Read only.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
Array of <tt>Numbers</tt>
</li>
</ul>
</div>
</div>
</div>
<div id="alpha" class="member">
<div class="member-link">
<a name="alpha" href="#alpha"><tt><b>alpha</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The color&rsquo;s alpha value as a number between <code>0</code> and <code>1</code>. All colors of the different subclasses support alpha values.</p>
<ul class="member-list">
<h4>Default:</h4>
<li><tt>1</tt></li>
</ul>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
<h4>Example:<span class="description">A filled path with a half transparent stroke:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-10">
var circle = new Path.Circle(new Point(80, 50), 30);
// Fill the circle with red and give it a 20pt green stroke:
circle.style = {
fillColor: 'red',
strokeColor: 'green',
strokeWidth: 20
};
// Make the stroke half transparent:
circle.strokeColor.alpha = 0.5;
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-10"></canvas></div>
</div>
</div>
</div>
</div>
<h3>RGB Components</h3>
<div id="red" class="member">
<div class="member-link">
<a name="red" href="#red"><tt><b>red</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The amount of red in the color as a value between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
<h4>Example:<span class="description">Changing the amount of red in a color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-11">
var circle = new Path.Circle(new Point(80, 50), 30);
circle.fillColor = 'blue';
// Blue + red = purple:
circle.fillColor.red = 1;
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-11"></canvas></div>
</div>
</div>
</div>
</div>
<div id="green" class="member">
<div class="member-link">
<a name="green" href="#green"><tt><b>green</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The amount of green in the color as a value between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
<h4>Example:<span class="description">Changing the amount of green in a color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-12">
var circle = new Path.Circle(new Point(80, 50), 30);
// First we set the fill color to red:
circle.fillColor = 'red';
// Red + green = yellow:
circle.fillColor.green = 1;
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-12"></canvas></div>
</div>
</div>
</div>
</div>
<div id="blue" class="member">
<div class="member-link">
<a name="blue" href="#blue"><tt><b>blue</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The amount of blue in the color as a value between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
<h4>Example:<span class="description">Changing the amount of blue in a color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-13">
var circle = new Path.Circle(new Point(80, 50), 30);
// First we set the fill color to red:
circle.fillColor = 'red';
// Red + blue = purple:
circle.fillColor.blue = 1;
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-13"></canvas></div>
</div>
</div>
</div>
</div>
<h3>Gray Components</h3>
<div id="gray" class="member">
<div class="member-link">
<a name="gray" href="#gray"><tt><b>gray</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The amount of gray in the color as a value between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
</div>
</div>
</div>
<h3>HSB Components</h3>
<div id="hue" class="member">
<div class="member-link">
<a name="hue" href="#hue"><tt><b>hue</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The hue of the color as a value in degrees between <code>0</code> and <code>360</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
<h4>Example:<span class="description">Changing the hue of a color:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-14">
var circle = new Path.Circle(new Point(80, 50), 30);
circle.fillColor = 'red';
circle.fillColor.hue += 30;
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-14"></canvas></div>
</div>
<h4>Example:<span class="description">Hue cycling:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-15">
// Create a rectangle shaped path, using the dimensions
// of the view:
var path = new Path.Rectangle(view.bounds);
path.fillColor = 'red';
function onFrame(event) {
path.fillColor.hue += 0.5;
}
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-15"></canvas></div>
</div>
</div>
</div>
</div>
<div id="saturation" class="member">
<div class="member-link">
<a name="saturation" href="#saturation"><tt><b>saturation</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The saturation of the color as a value between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
</div>
</div>
</div>
<div id="brightness" class="member">
<div class="member-link">
<a name="brightness" href="#brightness"><tt><b>brightness</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The brightness of the color as a value between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
</div>
</div>
</div>
<h3>HSL Components</h3>
<div id="lightness" class="member">
<div class="member-link">
<a name="lightness" href="#lightness"><tt><b>lightness</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The lightness of the color as a value between <code>0</code> and <code>1</code>.</p>
<p>Note that all other components are shared with HSB.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<tt>Number</tt>
</li>
</ul>
</div>
</div>
</div>
<h3>Gradient Components</h3>
<div id="gradient" class="member">
<div class="member-link">
<a name="gradient" href="#gradient"><tt><b>gradient</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The gradient object describing the type of gradient and the stops.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<a href="../classes/Gradient.html"><tt>Gradient</tt></a>
</li>
</ul>
</div>
</div>
</div>
<div id="highlight" class="member">
<div class="member-link">
<a name="highlight" href="#highlight"><tt><b>highlight</b></tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>The highlight point of the gradient.</p>
<ul class="member-list">
<h4>Type:</h4>
<li>
<a href="../classes/Point.html"><tt>Point</tt></a>
</li>
</ul>
<h4>Example:<span class="description">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:</span></h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-16">
var path = new Path.Circle({
center: view.center,
radius: view.bounds.height * 0.4
});
path.fillColor = {
gradient: {
stops: ['yellow', 'red', 'black'],
radial: true
},
origin: path.position,
destination: path.bounds.rightCenter
};
function onMouseMove(event) {
// Set the origin highlight of the path's gradient color
// to the position of the mouse:
path.fillColor.highlight = event.point;
}
</script>
<div class="canvas"><canvas width="516" height="300" id="canvas-16"></canvas></div>
</div>
</div>
</div>
</div>
</div>
<!-- ============================== methods ================================ -->
<div class="reference-members">
<h2>Methods</h2>
<div id="set-values" class="member">
<div class="member-link">
<a name="set-values" href="#set-values"><tt><b>set</b>(...values)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Sets the color to the passed values. Note that any sequence of parameters that is supported by the various <a href="../classes/Color.html"><tt>Color</tt></a>() constructors also work for calls of <code>set()</code>.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>values:</tt>
<tt>any value</tt>
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>
</li>
</ul>
</div>
</div>
</div>
<div id="convert-type" class="member">
<div class="member-link">
<a name="convert-type" href="#convert-type"><tt><b>convert</b>(type)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Converts the color to another type.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>type:</tt>
<tt>String</tt>
&mdash;&nbsp;the color type to convert to. Possible values: <tt>&lsquo;rgb&rsquo;</tt>, <tt>&lsquo;gray&rsquo;</tt>, <tt>&lsquo;hsb&rsquo;</tt>, <tt>&lsquo;hsl&rsquo;</tt>
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the converted color as a new instance
</li>
</ul>
</div>
</div>
</div>
<div id="hasalpha" class="member">
<div class="member-link">
<a name="hasalpha" href="#hasalpha"><tt><b>hasAlpha</b>()</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Checks if the color has an alpha value.</p>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;<tt>true</tt> if the color has an alpha value, <tt>false</tt> otherwise
</li>
</ul>
</div>
</div>
</div>
<div id="equals-color" class="member">
<div class="member-link">
<a name="equals-color" href="#equals-color"><tt><b>equals</b>(color)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Checks if the component color values of the color are the same as those of the supplied one.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to compare with
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;<tt>true</tt> if the colors are the same, <tt>false</tt> otherwise
</li>
</ul>
</div>
</div>
</div>
<div id="clone" class="member">
<div class="member-link">
<a name="clone" href="#clone"><tt><b>clone</b>()</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;a copy of the color object
</li>
</ul>
</div>
</div>
</div>
<h3>String Representations</h3>
<div id="tostring" class="member">
<div class="member-link">
<a name="tostring" href="#tostring"><tt><b>toString</b>()</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><tt>String</tt></tt>&nbsp;&mdash;&nbsp;a string representation of the color
</li>
</ul>
</div>
</div>
</div>
<div id="tocss-hex" class="member">
<div class="member-link">
<a name="tocss-hex" href="#tocss-hex"><tt><b>toCSS</b>(hex)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the color as a CSS string.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>hex:</tt>
<tt>Boolean</tt>
&mdash;&nbsp;whether to return the color in hexadecimal representation or as a CSS RGB / RGBA string.
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><tt>String</tt></tt>&nbsp;&mdash;&nbsp;a CSS string representation of the color
</li>
</ul>
</div>
</div>
</div>
<div id="transform-matrix" class="member">
<div class="member-link">
<a name="transform-matrix" href="#transform-matrix"><tt><b>transform</b>(matrix)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Transform the gradient color by the specified matrix.</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>matrix:</tt>
<a href="../classes/Matrix.html"><tt>Matrix</tt></a>
&mdash;&nbsp;the matrix to transform the gradient color by
</li>
</ul>
</div>
</div>
</div>
<h3>Math Operator Functions</h3>
<div id="add-number" class="member">
<div class="member-link">
<a name="add-number" href="#add-number"><tt><b>add</b>(number)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the addition of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to add
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<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
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color + 1;
console.log(result); // { red: 1, blue: 1, green: 1 }</code></pre>
</div>
</div>
</div>
<div id="add-color" class="member">
<div class="member-link">
<a name="add-color" href="#add-color"><tt><b>add</b>(color)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the addition of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to add
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the addition of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(1, 0, 0);
var result = color1 + color2;
console.log(result); // { red: 1, blue: 1, green: 1 }</code></pre>
</div>
</div>
</div>
<div id="subtract-number" class="member">
<div class="member-link">
<a name="subtract-number" href="#subtract-number"><tt><b>subtract</b>(number)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the subtraction of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to subtract
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<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 color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color - 1;
console.log(result); // { red: 0, blue: 0, green: 0 }</code></pre>
</div>
</div>
</div>
<div id="subtract-color" class="member">
<div class="member-link">
<a name="subtract-color" href="#subtract-color"><tt><b>subtract</b>(color)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the subtraction of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to subtract
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the subtraction of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(1, 0, 0);
var result = color1 - color2;
console.log(result); // { red: 0, blue: 1, green: 1 }</code></pre>
</div>
</div>
</div>
<div id="multiply-number" class="member">
<div class="member-link">
<a name="multiply-number" href="#multiply-number"><tt><b>multiply</b>(number)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the multiplication of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to multiply
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the multiplication of the color and the value as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color * 0.5;
console.log(result); // { red: 0.25, blue: 0.5, green: 0.5 }</code></pre>
</div>
</div>
</div>
<div id="multiply-color" class="member">
<div class="member-link">
<a name="multiply-color" href="#multiply-color"><tt><b>multiply</b>(color)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the multiplication of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to multiply
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the multiplication of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(0.5, 0, 0.5);
var result = color1 * color2;
console.log(result); // { red: 0, blue: 0, green: 0.5 }</code></pre>
</div>
</div>
</div>
<div id="divide-number" class="member">
<div class="member-link">
<a name="divide-number" href="#divide-number"><tt><b>divide</b>(number)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the division of the supplied value to both coordinates of the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>number:</tt>
<tt>Number</tt>
&mdash;&nbsp;the number to divide
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<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 color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color = new Color(0.5, 1, 1);
var result = color / 2;
console.log(result); // { red: 0.25, blue: 0.5, green: 0.5 }</code></pre>
</div>
</div>
</div>
<div id="divide-color" class="member">
<div class="member-link">
<a name="divide-color" href="#divide-color"><tt><b>divide</b>(color)</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns the division of the supplied color to the color as a new color. The object itself is not modified!</p>
<ul class="member-list">
<h4>Parameters:</h4>
<li>
<tt>color:</tt>
<a href="../classes/Color.html"><tt>Color</tt></a>
&mdash;&nbsp;the color to divide
</li>
</ul>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the division of the two colors as a new color
</li>
</ul>
<h4>Example:</h4>
<pre><code>var color1 = new Color(0, 1, 1);
var color2 = new Color(0.5, 0, 0.5);
var result = color1 / color2;
console.log(result); // { red: 0, blue: 0, green: 1 }</code></pre>
</div>
</div>
</div>
</div>
<div class="reference-members">
<h2>Static Methods</h2>
<div id="random" class="member">
<div class="member-link">
<a name="random" href="#random"><tt><b>Color.random</b>()</tt></a>
</div>
<div class="member-description hidden">
<div class="member-text">
<p>Returns a color object with random <a href="../classes/Color.html#red"><tt>red</tt></a>, <a href="../classes/Color.html#green"><tt>green</tt></a> and <a href="../classes/Color.html#blue"><tt>blue</tt></a> values between <code>0</code> and <code>1</code>.</p>
<ul class="member-list">
<h4>Returns:</h4>
<li>
<tt><a href="../classes/Color.html"><tt>Color</tt></a></tt>&nbsp;&mdash;&nbsp;the newly created color object
</li>
</ul>
<h4>Example:</h4>
<div class="paperscript split">
<div class="buttons">
<div class="button run">Run</div>
</div>
<script type="text/paperscript" canvas="canvas-17">
var circle = new Path.Circle(view.center, 50);
// Set a random color as circle fill color.
circle.fillColor = Color.random();
</script>
<div class="canvas"><canvas width="516" height="100" id="canvas-17"></canvas></div>
</div>
</div>
</div>
</div>
</div>
<!-- =========================== copyright notice ========================== -->
<p class="footer">
Paper.js v0.12.7<br>
Copyright &#169; 2011—2024 <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>
<div class="content-end"></div>
</article>
</body>