Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2

Merged
merged 14 commits into from
May 6, 2021
Prev Previous commit
Next Next commit
can mix colors
  • Loading branch information
Firanel committed May 5, 2021
commit ef1dbae02cf184927b41fd27a474c4b9f1920388
78 changes: 77 additions & 1 deletion docs/classes/Color.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ <h2><a href="#Metamethods">Metamethods</a></h2>
<td class="name" nowrap><a href="#Color:__eq">Color:__eq (other)</a></td>
<td class="summary">Check if colors are equal.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Color:__add">Color:__add (a, b)</a></td>
<td class="summary">Mix two colors evenly.</td>
</tr>
</table>
<h2><a href="#Methods">Methods</a></h2>
<table class="function_list">
Expand Down Expand Up @@ -160,6 +164,10 @@ <h2><a href="#Methods">Methods</a></h2>
<td class="summary">Set to black or white depending on lightness.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Color:mix">Color:mix (other, strength)</a></td>
<td class="summary">Mix two colors together.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Color:complement">Color:complement ()</a></td>
<td class="summary">Generate complementary color.</td>
</tr>
Expand Down Expand Up @@ -406,6 +414,41 @@ <h3>Returns:</h3>



</dd>
<dt>
<a name = "Color:__add"></a>
<strong>Color:__add (a, b)</strong>
</dt>
<dd>
Mix two colors evenly.


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">a</span>
<span class="types"><a class="type" href="../classes/Color.html#">Color</a></span>
first color
</li>
<li><span class="parameter">b</span>
<span class="types"><a class="type" href="../classes/Color.html#">Color</a></span>
second color
</li>
</ul>

<h3>Returns:</h3>
<ol>

<span class="types"><a class="type" href="../classes/Color.html#">Color</a></span>
new color
</ol>


<h3>See also:</h3>
<ul>
<a href="../classes/Color.html#Color:mix">Color:mix</a>
</ul>


</dd>
</dl>
<h2 class="section-header "><a name="Methods"></a>Methods</h2>
Expand Down Expand Up @@ -781,6 +824,39 @@ <h3>Returns:</h3>



</dd>
<dt>
<a name = "Color:mix"></a>
<strong>Color:mix (other, strength)</strong>
</dt>
<dd>
Mix two colors together.


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">other</span>
<span class="types"><a class="type" href="../classes/Color.html#">Color</a></span>



</li>
<li><span class="parameter">strength</span>
<span class="types"><span class="type">number</span></span>
0 results in self, 1 results in other (Default: 0.5)
</li>
</ul>

<h3>Returns:</h3>
<ol>

<span class="types"><a class="type" href="../classes/Color.html#">Color</a></span>
self
</ol>




</dd>
<dt>
<a name = "Color:complement"></a>
Expand Down Expand Up @@ -1001,7 +1077,7 @@ <h3>Usage:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-05-05 16:08:30 </i>
<i style="float:right;">Last updated 2021-05-05 16:34:08 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h2>Topics</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-05-05 16:08:30 </i>
<i style="float:right;">Last updated 2021-05-05 16:34:08 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/lua-color.colors.X11.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h3>Usage:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-05-05 16:08:30 </i>
<i style="float:right;">Last updated 2021-05-05 16:34:08 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/lua-color.colors.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h3>Usage:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-05-05 16:08:30 </i>
<i style="float:right;">Last updated 2021-05-05 16:34:08 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/README.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ <h3>Other</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-05-05 16:08:30 </i>
<i style="float:right;">Last updated 2021-05-05 16:34:08 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
28 changes: 28 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,21 @@ function Color:blackOrWhite()
return self
end

--- Mix two colors together.
--
-- @tparam Color other
-- @tparam number strength 0 results in self, 1 results in other (Default: 0.5)
--
-- @treturn Color self
function Color:mix(other, strength)
if strength == nil then strength = 0.5 end
self.r = self.r * (1 - strength) + other.r * strength
self.g = self.g * (1 - strength) + other.g * strength
self.b = self.b * (1 - strength) + other.b * strength
self.a = self.a * (1 - strength) + other.a * strength
return self
end


--- Generate complementary color.
--
Expand Down Expand Up @@ -595,6 +610,19 @@ function Color:__eq(other)
and self.a == other.a
end

--- Mix two colors evenly.
--
-- @tparam Color a first color
-- @tparam Color b second color
--
-- @treturn Color new color
--
-- @see Color:mix
function Color.__add(a, b)
assert(Color.isColor(a) and Color.isColor(b), "Can only add two colors.")
return Color(a):mix(b)
end



--- Check whether `color` is a Color.
Expand Down