'use strict';
const Rac = require('../Rac');
const utils = require('../util/utils');
/**
* Color with RBGA values, each on the `[0,1]` range.
*
* @alias Rac.Color
*/
class Color {
constructor(rac, r, g, b, alpha = 1) {
utils.assertExists(rac, r, g, b, alpha);
utils.assertNumber(r, g, b, alpha);
this.rac = rac;
this.r = r;
this.g = g;
this.b = b;
this.alpha = alpha;
}
/**
* Returns a string representation intended for human consumption.
*/
toString() {
return `Color(${this.r},${this.g},${this.b},${this.alpha})`;
}
static fromRgba(rac, r, g, b, a = 255) {
return new Color(rac, r/255, g/255, b/255, a/255);
}
fill() {
return new Rac.Fill(this.rac, this);
}
stroke(weight = 1) {
return new Rac.Stroke(this.rac, weight, this);
}
withAlpha(newAlpha) {
return new Color(this.rac, this.r, this.g, this.b, newAlpha);
}
withAlphaRatio(ratio) {
return new Color(this.rac, this.r, this.g, this.b, this.alpha * ratio);
}
} // class Color
module.exports = Color;