mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Rewrote transparency block
Wrapping of the value is now handled by a new function, _wrapTransparency; _updatePenColor now handles the transparency value; DEFAULT_PEN_STATE now includes a transparency value (100).
This commit is contained in:
parent
f61366643d
commit
3185eb27e1
1 changed files with 17 additions and 6 deletions
|
@ -55,6 +55,7 @@ class Scratch3PenBlocks {
|
|||
penDown: false,
|
||||
hue: 120,
|
||||
shade: 50,
|
||||
transparency: 100,
|
||||
penAttributes: {
|
||||
color4f: [0, 0, 1, 1],
|
||||
diameter: 1
|
||||
|
@ -183,11 +184,11 @@ class Scratch3PenBlocks {
|
|||
penState.penAttributes.color4f[0] = rgb.r / 255.0;
|
||||
penState.penAttributes.color4f[1] = rgb.g / 255.0;
|
||||
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
||||
penState.penAttributes.color4f[3] = 1;
|
||||
penState.penAttributes.color4f[3] = penState.transparency / 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a pen hue or shade values to the range [0,200).
|
||||
* Wrap a pen hue or shade values to the range (0,200).
|
||||
* @param {number} value - the pen hue or shade value to the proper range.
|
||||
* @returns {number} the wrapped value.
|
||||
* @private
|
||||
|
@ -197,6 +198,18 @@ class Scratch3PenBlocks {
|
|||
if (value < 0) value += 200;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a pen transparency value to the range (0, 100).
|
||||
* @param {number} value - the pen transparency value to the proper range.
|
||||
* @returns {number} the wrapped value.
|
||||
* @private
|
||||
*/
|
||||
_wrapTransparency (value) {
|
||||
value = value % 100;
|
||||
if (value < 0) value += 100;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the block primitives implemented by this package.
|
||||
|
@ -382,8 +395,7 @@ class Scratch3PenBlocks {
|
|||
*/
|
||||
changePenTransparencyBy (args, util) {
|
||||
const penState = this._getPenState(util.target);
|
||||
const TRANSPARENCY = args.TRANSPARENCY / 100;
|
||||
penState.penAttributes.color4f[3] = penState.penAttributes.color4f[3] + TRANSPARENCY;
|
||||
penState.transparency = this._wrapTransparency(penState.transparency + Cast.toNumber(args.TRANSPARENCY));
|
||||
this._updatePenColor(penState);
|
||||
}
|
||||
|
||||
|
@ -395,8 +407,7 @@ class Scratch3PenBlocks {
|
|||
*/
|
||||
setPenTransparencyTo (args, util) {
|
||||
const penState = this._getPenState(util.target);
|
||||
const TRANSPARENCY = MathUtil.clamp(args.TRANSPARENCY, 0, 100) / 100;
|
||||
penState.penAttributes.color4f[3] = TRANSPARENCY;
|
||||
penState.transparency = this._wrapTransparency(Cast.toNumber(args.TRANSPARENCY));
|
||||
this._updatePenColor(penState);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue