fponticelli / thx.color

General purpose color library for Haxe
http://thx-lib.org
MIT License
38 stars 4 forks source link

function for simulate alpha opacity #25

Closed francescoagati closed 9 years ago

francescoagati commented 9 years ago
class ColorTools {
  public inline static function withAlphaEmulated(color:thx.color.Rgbx,background:thx.color.Rgb,alpha:Float) {
    var red =  Std.int((1 - alpha) * background.red + alpha * color.red);
    var green =  Std.int((1 - alpha) * background.green + alpha * color.green);
    var blue = Std.int((1 - alpha) * background.blue + alpha * color.blue);
    trace(red,green,blue);
    return ('rgb($red,$green,$blue)':thx.color.Rgb);
  }
}

based on http://yolijn.com/convert-rgba-to-rgb

fponticelli commented 9 years ago

Interesting idea. Why not adding combineColors directly to Rgba and Rgbxa?

fponticelli commented 9 years ago

If we add combineColors your use case would become:

color.withAlpha(0.5).combineColor(otherColor); // changed `combineColors` to `combineColor`
francescoagati commented 9 years ago

and with combineColor i can after convert rgba to normal rgb?

2015-07-13 17:09 GMT+02:00 Franco Ponticelli notifications@github.com:

If we add combineColors your use case would become:

color.withAlpha(0.5).combineColor(otherColor); // changed combineColors to combineColor

— Reply to this email directly or view it on GitHub https://github.com/fponticelli/thx.color/issues/25#issuecomment-120961974 .

fponticelli commented 9 years ago

You can always do that (implicitly or through .toRgb) but since the alpha info is lost in combineColor I guess the output should be directly Rgb or Rgbx. I can add this later today or I will be glad to accept a PR.

francescoagati commented 9 years ago

ok i prepare a pull request

2015-07-13 17:15 GMT+02:00 Franco Ponticelli notifications@github.com:

You can always do that (implicitly or through .toRgb) but since the alpha info is lost in combineColor I guess the output should be directly Rgb or Rgbx. I can add this later today or I will be glad to accept a PR.

— Reply to this email directly or view it on GitHub https://github.com/fponticelli/thx.color/issues/25#issuecomment-120963265 .

fponticelli commented 9 years ago

;)

fponticelli commented 9 years ago

Implemented, thank you for the suggestion.

francescoagati commented 9 years ago

:+1: