【Scratch拡張機能をJavascriptで自作】SVG画像からスプライトをアニメーション的に動かす拡張機能の作成方法
※ 当ページには【広告/PR】を含む場合があります。
2021/02/17
clipPath
use
無償で試せる素材を提供されているサイト
ぴぽや倉庫
Superpowers Asset Packs
テクニックのキモ ~ SVG画像を分割する
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="300" version="1.1" viewBox="0 0 100 150">
<defs>
<g id="baseImage">
<image width="64" height="112" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABwCAYAAACuE3ZzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYw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ZwDVPxvihdrvPC7RL+XfyeQGuvMon3Hk4xX2ASFZpr/7BQ0vyA3Rx/TuYAshrfujPFqNzvJWJDknlU40wOmqGBzkgnDcIiy+u5kCPrWk71Gj7poFoRL7lzwvUFPydIba4HWvU9uoFDnIPaOaJDwAuf2sr8xK1jFKmWFDf8ipamWARN7xvfF4gSVHf2mqKLdIjuGFveW00P4HvP0nC+00ZgL97oO5xPQslOcJid0kUqMPcx4nC+63IEBGlcl4LRsIYJV0WabMvcEgS3m8qQ0SDCQJPoKvXwkpcBdIey+s7fkcHFBJ0md4bpg3vA5s+A4ieiU2Xb2C6DtCU8/J3hLeRwLZt3ywgUkQNjOqADGeU4uYnKHEL4fXJXZs+7SNtyRAGOZ8Bajv5o3va6cd/23paIy56xrORITIKb8eJ+xPfGDc/gRilTLEg/6Z3IqrGopT7+TqjJJdfnRP88Uuki8u+lyqqHaDGd4erwEKdW6cXoZmICQ0UFaYlUmIzkEbM8AIH4SVoyOU4uFTBxxpGSDMAgjNCrm6qR3H3dD8/i7nyFJdTnRKdEUh2YzaL+4/uyQGQ7xRUYv8qNxiHEZKErkLIWI7jcE5QeGtKF0+Xv7MNxrgETO8f0HmA1Pn18Wwg8MLfCWDgBsOUl4SIaWb+fwCcPl4MsJm3rQAAAABJRU5ErkJggg=="/>
</g>
<clipPath id="anim1">
<rect width="16" height="16"/>
</clipPath>
<clipPath id="anim2">
<rect y="17" width="16" height="16"/>
</clipPath>
<clipPath id="anim3">
<rect y="33" width="16" height="16"/>
</clipPath>
<clipPath id="anim4">
<rect y="49" width="16" height="16"/>
</clipPath>
</defs>
<use xlink:href="#baseImage" clip-path="url(#anim1)" x="0" y="0"></use>
<use xlink:href="#baseImage" clip-path="url(#anim2)" x="24" y="24"></use>
<use xlink:href="#baseImage" clip-path="url(#anim3)" x="48" y="48"></use>
<use xlink:href="#baseImage" clip-path="url(#anim4)" x="72" y="72"></use>
</svg>
clipPath
use
拡張機能の実装
index.js
const ArgumentType = require('../../extension-support/argument-type');
const BlockType = require('../../extension-support/block-type');
const Cast = require('../../util/cast');
const formatMessage = require('format-message');
const log = require('../../util/log');
const StageLayering = require('../../engine/stage-layering');
class Scratch3PartialImageWriter {
constructor (runtime) {
this._extVersion = '0.0.1';
this.runtime = runtime;
this._x = 0;
this._y = 0;
this._xOrigin = 24;
this._yOrigin = -48;
this._imageDrawableId = -1;
this._imageSkinId = -1;
this.emptyImg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0" viewBox="0 0 0 0"></svg>';
}
_spawnSprite(partId_) {
const xoffsets_ = [0, 0, 0, 0, -16, -16, -16, -16, -32, -32, -32, -32, -48, -48, -48, -48];
const yoffsets_ = [0, -17, -33, -49, 0, -17, -33, -49, 0, -17, -33, -49, 0, -17, -33, -49];
if (partId_ < 0 || partId_ > 16) { return this.emptyImg; }
const characterSeed = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="168" viewBox="0 0 64 112">
<defs>
<g id="baseImage">
<image width="64" height="112" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABwCAYAAACuE3ZzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpA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rect width="16" height="16"/></clipPath>
<clipPath id="anim2"><rect y="17" width="16" height="16"/></clipPath>
<clipPath id="anim3"><rect y="33" width="16" height="16"/></clipPath>
<clipPath id="anim4"><rect y="49" width="16" height="16"/></clipPath>
<clipPath id="anim5"><rect x="17" y="0" width="16" height="16"/></clipPath>
<clipPath id="anim6"><rect x="17" y="17" width="16" height="16"/></clipPath>
<clipPath id="anim7"><rect x="17" y="33" width="16" height="16"/></clipPath>
<clipPath id="anim8"><rect x="17" y="49" width="16" height="16"/></clipPath>
<clipPath id="anim9"><rect x="33" y="0" width="16" height="16"/></clipPath>
<clipPath id="anim10"><rect x="33" y="17" width="16" height="16"/></clipPath>
<clipPath id="anim11"><rect x="33" y="33" width="16" height="16"/></clipPath>
<clipPath id="anim12"><rect x="33" y="49" width="16" height="16"/></clipPath>
<clipPath id="anim13"><rect x="49" y="0" width="16" height="16"/></clipPath>
<clipPath id="anim14"><rect x="49" y="17" width="16" height="16"/></clipPath>
<clipPath id="anim15"><rect x="49" y="33" width="16" height="16"/></clipPath>
<clipPath id="anim16"><rect x="49" y="49" width="16" height="16"/></clipPath>
</defs>
<use xlink:href="#baseImage" clip-path="url(#anim${partId_})" x="${xoffsets_[partId_ - 1]}" y="${yoffsets_[partId_ - 1]}"></use>
</svg>`;
return characterSeed;
}
getInfo () {
return {
id: 'partialimagewriter',
name: formatMessage({
id: 'partialimagewriter.categoryName',
default: 'PartialImageWriter',
description: 'Label for the partialimagewriter extension category'
}),
blocks: [
{
opcode: 'initSprite',
blockType: BlockType.COMMAND
},
{
opcode: 'stamp',
blockType: BlockType.COMMAND,
text: formatMessage({
id: 'partialimagewriter.stamp',
default: 'stamp [PART_ID]',
description: 'Render a current skin onto a drawble'
}),
arguments: {
PART_ID: {
type: ArgumentType.NUMBER,
defaultValue: 1
}
}
},
{
opcode: 'moveTo',
blockType: BlockType.COMMAND,
text: formatMessage({
id: 'partialimagewriter.moveto',
default: 'move to ( [X_POS], [Y_POS] )',
description: 'move current sprite to'
}),
arguments: {
X_POS: {
type: ArgumentType.NUMBER,
defaultValue: 0
},
Y_POS: {
type: ArgumentType.NUMBER,
defaultValue: 0
}
}
},
{
opcode: 'setXYOffset',
blockType: BlockType.COMMAND,
text: formatMessage({
id: 'partialimagewriter.setxyoffset',
default: 'Origin set to ( [X_ORIGIN], [Y_ORIGIN] )',
description: 'set new origin'
}),
arguments: {
X_ORIGIN: {
type: ArgumentType.NUMBER,
defaultValue: 0
},
Y_ORIGIN: {
type: ArgumentType.NUMBER,
defaultValue: 0
}
}
},
{
opcode: 'clearImage',
blockType: BlockType.COMMAND
},
{
opcode: 'goImageToBack',
blockType: BlockType.COMMAND
},
{
opcode: 'goImageToFront',
blockType: BlockType.COMMAND
},
{
opcode: 'getVersion',
text: 'Version Info',
blockType: BlockType.REPORTER
}
],
menus: {}
};
}
stamp (args, util) {
if (this._imageSkinId >= 0) {
this._pi = Cast.toNumber(args.PART_ID);
const chara1 = this._spawnSprite(this._pi);
this.runtime.renderer.updateSVGSkin(this._imageSkinId, chara1);
}
}
moveTo (args, util) {
this._x = Cast.toNumber(args.X_POS);
this._y = Cast.toNumber(args.Y_POS);
if (this._imageDrawableId >= 0 && this._imageSkinId >= 0) {
this.runtime.renderer.updateDrawableProperties(this._imageDrawableId, {
skinId: this._imageSkinId,
position: [this._x + this._xOrigin, this._y + this._yOrigin],
scale: [100, 100],
direction: 90
});
this.runtime.requestRedraw();
}
}
setXYOffset(args, util) {
this._xOrigin = Cast.toNumber(args.X_ORIGIN);
this._yOrigin = Cast.toNumber(args.Y_ORIGIN);
}
initSprite() {
if (this._imageSkinId < 0 && this.runtime.renderer) {
const skinId = this.runtime.renderer.createSVGSkin(this.emptyImg);
this._imageSkinId = skinId;
this._imageDrawableId = this.runtime.renderer.createDrawable(StageLayering.SPRITE_LAYER);
this.runtime.renderer.updateDrawableProperties(this._imageDrawableId, {skinId: this._imageSkinId});
}
}
clearImage () {
if (this._imageSkinId >= 0) {
this.runtime.renderer.updateSVGSkin(this._imageSkinId, this.emptyImg);
}
}
goImageToBack() {
if (this._imageDrawableId >= 0 && this._imageSkinId >= 0) {
this.runtime.renderer.setDrawableOrder(this._imageDrawableId, 1, StageLayering.SPRITE_LAYER);
}
}
goImageToFront() {
if (this._imageDrawableId >= 0 && this._imageSkinId >= 0) {
this.runtime.renderer.setDrawableOrder(this._imageDrawableId, Infinity, StageLayering.SPRITE_LAYER);
}
}
getVersion(args) {
return this._extVersion;
}
}
module.exports = Scratch3PartialImageWriter;
まとめ
参考サイト
記事を書いた人
ナンデモ系エンジニア
これからの"地方格差"なきプログラミング教育とは何かを考えながら、 地方密着型プログラミング学習関連テーマの記事を不定期で独自にブログ発信しています。
カテゴリー