Implement graphic effects and size blocks

This commit is contained in:
Tim Mickel 2016-06-30 00:11:47 -04:00
parent 7db2981ddc
commit 1eaed6fff3
4 changed files with 90 additions and 2 deletions
playground
src

View file

@ -252,7 +252,7 @@
</value>
<value name="CHANGE">
<shadow type="math_number">
<field name="NUM">10</field>
<field name="NUM">25</field>
</shadow>
</value>
</block>
@ -262,7 +262,7 @@
</value>
<value name="VALUE">
<shadow type="math_number">
<field name="NUM">10</field>
<field name="NUM">0</field>
</shadow>
</value>
</block>

View file

@ -0,0 +1,54 @@
function Scratch3LooksBlocks(runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
*/
this.runtime = runtime;
}
/**
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3LooksBlocks.prototype.getPrimitives = function() {
return {
'looks_effectmenu': this.effectMenu,
'looks_changeeffectby': this.changeEffect,
'looks_seteffectto': this.setEffect,
'looks_cleargraphiceffects': this.clearEffects,
'looks_changesizeby': this.changeSize,
'looks_setsizeto': this.setSize,
'looks_size': this.getSize
};
};
Scratch3LooksBlocks.prototype.effectMenu = function (args) {
return args.EFFECT.toLowerCase();
};
Scratch3LooksBlocks.prototype.changeEffect = function (args, util) {
var newValue = args.CHANGE + util.target.effects[args.EFFECT];
util.target.setEffect(args.EFFECT, newValue);
};
Scratch3LooksBlocks.prototype.setEffect = function (args, util) {
util.target.setEffect(args.EFFECT, args.VALUE);
};
Scratch3LooksBlocks.prototype.clearEffects = function (args, util) {
util.target.clearEffects();
};
Scratch3LooksBlocks.prototype.changeSize = function (args, util) {
util.target.setSize(util.target.size + args.CHANGE);
};
Scratch3LooksBlocks.prototype.setSize = function (args, util) {
util.target.setSize(args.SIZE);
};
Scratch3LooksBlocks.prototype.getSize = function (args, util) {
return util.target.size;
};
module.exports = Scratch3LooksBlocks;

View file

@ -6,6 +6,7 @@ var util = require('util');
var defaultBlockPackages = {
'scratch3_control': require('../blocks/scratch3_control'),
'scratch3_event': require('../blocks/scratch3_event'),
'scratch3_looks': require('../blocks/scratch3_looks'),
'scratch3_motion': require('../blocks/scratch3_motion'),
'scratch3_operators': require('../blocks/scratch3_operators')
};

View file

@ -24,6 +24,18 @@ Clone.prototype.y = 0;
Clone.prototype.direction = 90;
Clone.prototype.size = 100;
Clone.prototype.effects = {
'color': 0,
'fisheye': 0,
'whirl': 0,
'pixelate': 0,
'mosaic': 0,
'brightness': 0,
'ghost': 0
};
Clone.prototype.setXY = function (x, y) {
this.x = x;
this.y = y;
@ -39,4 +51,25 @@ Clone.prototype.setDirection = function (direction) {
});
};
Clone.prototype.setSize = function (size) {
this.size = MathUtil.clamp(size, 5, 535);
self.renderer.updateDrawableProperties(this.drawableID, {
scale: this.size
});
};
Clone.prototype.setEffect = function (effectName, value) {
this.effects[effectName] = value;
var props = {};
props[effectName] = this.effects[effectName];
self.renderer.updateDrawableProperties(this.drawableID, props);
};
Clone.prototype.clearEffects = function () {
for (var effectName in this.effects) {
this.effects[effectName] = 0;
}
self.renderer.updateDrawableProperties(this.drawableID, this.effects);
};
module.exports = Clone;