From e30e5809d17dc754e61dc0be00dcfb70f3376362 Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 25 Aug 2017 15:07:38 +0800 Subject: [PATCH] Add new blocks change pen transparency by (num) set pen transparency to (num) --- src/blocks/scratch3_pen.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/blocks/scratch3_pen.js b/src/blocks/scratch3_pen.js index 13c0ed42b..7389035dd 100644 --- a/src/blocks/scratch3_pen.js +++ b/src/blocks/scratch3_pen.js @@ -214,7 +214,9 @@ class Scratch3PenBlocks { pen_changepenshadeby: this.changePenShadeBy, pen_setpenshadeto: this.setPenShadeToNumber, pen_changepensizeby: this.changePenSizeBy, - pen_setpensizeto: this.setPenSizeTo + pen_setpensizeto: this.setPenSizeTo, + pen_changepentransparencyby: this.changePenTransparencyBy, + pen_setpentransparencyto: this.setPenTransparencyTo }; } @@ -371,6 +373,32 @@ class Scratch3PenBlocks { const penAttributes = this._getPenState(util.target).penAttributes; penAttributes.diameter = this._clampPenSize(Cast.toNumber(args.SIZE)); } + + /** + * The pen "change pen transparency by {number}" block changes the "transparency" of the pen, related to the RGB value. + * @param {object} args - the block arguments. + * @property {number} TRANSPARENCY - the amount of desired transparency change. + * @param {object} util - utility object provided by the runtime. + */ + changePenTransparencyBy (args, util) { + const penState = this._getPenState(util.target); + + penState.penAttributes.color4f[3] = penState.penAttributes.color4f[3] + (args.TRANSPARENCY / 255); + this._updatePenColor(penState); + } + + /** + * The pen "set pen transparency to {number}" block sets the "transparency" of the pen, related to the RGB value. + * @param {object} args - the block arguments. + * @property {number} TRANSPARENCY - the amount of desired transparency change. + * @param {object} util - utility object provided by the runtime. + */ + setPenTransparencyTo (args, util) { + const penState = this._getPenState(util.target); + + penState.penAttributes.color4f[3] = args.TRANSPARENCY / 255; + this._updatePenColor(penState); + } } module.exports = Scratch3PenBlocks;